mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
validate.php proper exit code (#16274)
some fixes around database & poller checks
This commit is contained in:
@@ -28,6 +28,7 @@ namespace LibreNMS\Validations\Poller;
|
|||||||
use App\Models\Device;
|
use App\Models\Device;
|
||||||
use App\Models\Poller;
|
use App\Models\Poller;
|
||||||
use App\Models\PollerCluster;
|
use App\Models\PollerCluster;
|
||||||
|
use LibreNMS\DB\Eloquent;
|
||||||
use LibreNMS\ValidationResult;
|
use LibreNMS\ValidationResult;
|
||||||
|
|
||||||
class CheckActivePoller implements \LibreNMS\Interfaces\Validation
|
class CheckActivePoller implements \LibreNMS\Interfaces\Validation
|
||||||
@@ -40,7 +41,9 @@ class CheckActivePoller implements \LibreNMS\Interfaces\Validation
|
|||||||
$dispatcher_exists = PollerCluster::isActive()->exists();
|
$dispatcher_exists = PollerCluster::isActive()->exists();
|
||||||
$wrapper_exists = Poller::isActive()->exists();
|
$wrapper_exists = Poller::isActive()->exists();
|
||||||
if (! $dispatcher_exists && ! $wrapper_exists) {
|
if (! $dispatcher_exists && ! $wrapper_exists) {
|
||||||
return ValidationResult::fail(trans('validation.validations.poller.CheckActivePoller.fail'));
|
$interval = (int) \LibreNMS\Config::get('rrd.step');
|
||||||
|
|
||||||
|
return ValidationResult::fail(trans('validation.validations.poller.CheckActivePoller.fail', ['interval' => $interval]));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($dispatcher_exists && $wrapper_exists) {
|
if ($dispatcher_exists && $wrapper_exists) {
|
||||||
@@ -55,6 +58,6 @@ class CheckActivePoller implements \LibreNMS\Interfaces\Validation
|
|||||||
*/
|
*/
|
||||||
public function enabled(): bool
|
public function enabled(): bool
|
||||||
{
|
{
|
||||||
return Device::exists();
|
return Eloquent::isConnected() && Device::exists();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -28,6 +28,7 @@ namespace LibreNMS\Validations\Poller;
|
|||||||
use App\Models\Device;
|
use App\Models\Device;
|
||||||
use App\Models\Poller;
|
use App\Models\Poller;
|
||||||
use App\Models\PollerCluster;
|
use App\Models\PollerCluster;
|
||||||
|
use LibreNMS\DB\Eloquent;
|
||||||
use LibreNMS\ValidationResult;
|
use LibreNMS\ValidationResult;
|
||||||
|
|
||||||
class CheckDispatcherService implements \LibreNMS\Interfaces\Validation
|
class CheckDispatcherService implements \LibreNMS\Interfaces\Validation
|
||||||
@@ -49,7 +50,7 @@ class CheckDispatcherService implements \LibreNMS\Interfaces\Validation
|
|||||||
*/
|
*/
|
||||||
public function enabled(): bool
|
public function enabled(): bool
|
||||||
{
|
{
|
||||||
return Device::exists();
|
return Eloquent::isConnected() && Device::exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function checkDispatchService(): ValidationResult
|
private function checkDispatchService(): ValidationResult
|
||||||
|
@@ -28,6 +28,7 @@ namespace LibreNMS\Validations\Poller;
|
|||||||
use App\Models\Poller;
|
use App\Models\Poller;
|
||||||
use App\Models\PollerCluster;
|
use App\Models\PollerCluster;
|
||||||
use LibreNMS\Config;
|
use LibreNMS\Config;
|
||||||
|
use LibreNMS\DB\Eloquent;
|
||||||
use LibreNMS\ValidationResult;
|
use LibreNMS\ValidationResult;
|
||||||
|
|
||||||
class CheckPythonWrapper implements \LibreNMS\Interfaces\Validation
|
class CheckPythonWrapper implements \LibreNMS\Interfaces\Validation
|
||||||
@@ -70,7 +71,7 @@ class CheckPythonWrapper implements \LibreNMS\Interfaces\Validation
|
|||||||
*/
|
*/
|
||||||
public function enabled(): bool
|
public function enabled(): bool
|
||||||
{
|
{
|
||||||
return true;
|
return Eloquent::isConnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function checkPythonWrapper(): ValidationResult
|
private function checkPythonWrapper(): ValidationResult
|
||||||
|
@@ -117,6 +117,20 @@ class Validator
|
|||||||
}, ValidationResult::SUCCESS);
|
}, ValidationResult::SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get overall status
|
||||||
|
*/
|
||||||
|
public function getStatus(): int
|
||||||
|
{
|
||||||
|
return array_reduce($this->results, function ($compound, array $results) {
|
||||||
|
foreach ($results as $result) {
|
||||||
|
$compound = min($compound, $result->getStatus());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $compound;
|
||||||
|
}, ValidationResult::SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the ValidationResults for a specific validation group.
|
* Get the ValidationResults for a specific validation group.
|
||||||
*
|
*
|
||||||
|
@@ -100,7 +100,7 @@ if (! module_selected('nodb', $init_modules)) {
|
|||||||
echo "Check the install docs for more info: https://docs.librenms.org/Installation/\n";
|
echo "Check the install docs for more info: https://docs.librenms.org/Installation/\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
exit;
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
\LibreNMS\DB\Eloquent::setStrictMode(false); // disable strict mode for legacy code...
|
\LibreNMS\DB\Eloquent::setStrictMode(false); // disable strict mode for legacy code...
|
||||||
|
@@ -267,7 +267,7 @@ return [
|
|||||||
],
|
],
|
||||||
'poller' => [
|
'poller' => [
|
||||||
'CheckActivePoller' => [
|
'CheckActivePoller' => [
|
||||||
'fail' => 'No active polling method detected',
|
'fail' => 'Poller is not running. No poller has run within the last :interval seconds.',
|
||||||
'both_fail' => 'Both Dispatcher Service and Python Wrapper were active recently, this could cause double polling',
|
'both_fail' => 'Both Dispatcher Service and Python Wrapper were active recently, this could cause double polling',
|
||||||
'ok' => 'Active pollers found',
|
'ok' => 'Active pollers found',
|
||||||
],
|
],
|
||||||
|
@@ -268,7 +268,7 @@ return [
|
|||||||
],
|
],
|
||||||
'poller' => [
|
'poller' => [
|
||||||
'CheckActivePoller' => [
|
'CheckActivePoller' => [
|
||||||
'fail' => 'Nenhum método de polling ativo detectado',
|
'fail' => 'O Poller não está em execução. Nenhum poller foi executado nos últimos :interval segundos',
|
||||||
'both_fail' => 'Tanto o Dispatcher Service quanto o Python Wrapper estiveram ativos recentemente, isso pode causar duplo polling',
|
'both_fail' => 'Tanto o Dispatcher Service quanto o Python Wrapper estiveram ativos recentemente, isso pode causar duplo polling',
|
||||||
'ok' => 'Pollers ativos encontrados',
|
'ok' => 'Pollers ativos encontrados',
|
||||||
],
|
],
|
||||||
|
@@ -268,7 +268,7 @@ return [
|
|||||||
],
|
],
|
||||||
'poller' => [
|
'poller' => [
|
||||||
'CheckActivePoller' => [
|
'CheckActivePoller' => [
|
||||||
'fail' => '未检测到活动的轮询方法',
|
'fail' => '轮询器未运行。 过去 :interval 秒内没有运行任何轮询器。',
|
||||||
'both_fail' => '调度程序服务和Python包装器最近都处于活动状态,这可能导致双重轮询',
|
'both_fail' => '调度程序服务和Python包装器最近都处于活动状态,这可能导致双重轮询',
|
||||||
'ok' => '找到活动的轮询器',
|
'ok' => '找到活动的轮询器',
|
||||||
],
|
],
|
||||||
|
17
validate.php
17
validate.php
@@ -51,7 +51,7 @@ if (isset($options['h'])) {
|
|||||||
Example: ./validate.php -g mail.
|
Example: ./validate.php -g mail.
|
||||||
|
|
||||||
";
|
";
|
||||||
exit;
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (function_exists('posix_getuid') && posix_getuid() === 0) {
|
if (function_exists('posix_getuid') && posix_getuid() === 0) {
|
||||||
@@ -62,7 +62,7 @@ if (function_exists('posix_getuid') && posix_getuid() === 0) {
|
|||||||
// Check autoload
|
// Check autoload
|
||||||
if (! file_exists('vendor/autoload.php')) {
|
if (! file_exists('vendor/autoload.php')) {
|
||||||
print_fail('Composer has not been run, dependencies are missing', './scripts/composer_wrapper.php install --no-dev');
|
print_fail('Composer has not been run, dependencies are missing', './scripts/composer_wrapper.php install --no-dev');
|
||||||
exit;
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once 'vendor/autoload.php';
|
require_once 'vendor/autoload.php';
|
||||||
@@ -114,17 +114,17 @@ if ($validator->getGroupStatus('dependencies') == ValidationResult::FAILURE) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($pre_checks_failed) {
|
if ($pre_checks_failed) {
|
||||||
exit;
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
$init_modules = [];
|
$init_modules = ['nodb'];
|
||||||
require 'includes/init.php';
|
require 'includes/init.php';
|
||||||
|
|
||||||
// make sure install_dir is set correctly, or the next includes will fail
|
// make sure install_dir is set correctly, or the next includes will fail
|
||||||
if (! file_exists(Config::get('install_dir') . '/.env')) {
|
if (! file_exists(Config::get('install_dir') . '/.env')) {
|
||||||
$suggested = realpath(__DIR__);
|
$suggested = realpath(__DIR__);
|
||||||
print_fail('\'install_dir\' config setting is not set correctly.', "It should probably be set to: $suggested");
|
print_fail('\'install_dir\' config setting is not set correctly.', "It should probably be set to: $suggested");
|
||||||
exit;
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (\LibreNMS\DB\Eloquent::isConnected()) {
|
if (\LibreNMS\DB\Eloquent::isConnected()) {
|
||||||
@@ -144,9 +144,16 @@ if (isset($options['g'])) {
|
|||||||
$modules = []; // all modules
|
$modules = []; // all modules
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// the code below may not show the database check above, always print it
|
||||||
|
if (! in_array('database', $modules)) {
|
||||||
|
$validator->printResults('database');
|
||||||
|
}
|
||||||
|
|
||||||
// run checks
|
// run checks
|
||||||
$validator->validate($modules, isset($options['s']) || ! empty($modules));
|
$validator->validate($modules, isset($options['s']) || ! empty($modules));
|
||||||
|
|
||||||
|
exit($validator->getStatus() ? 0 : 1);
|
||||||
|
|
||||||
function print_header()
|
function print_header()
|
||||||
{
|
{
|
||||||
$output = ob_get_clean();
|
$output = ob_get_clean();
|
||||||
|
Reference in New Issue
Block a user