mirror of
https://github.com/librenms/librenms.git
synced 2024-09-21 02:18:39 +00:00
validate.php proper exit code (#16274)
some fixes around database & poller checks
This commit is contained in:
parent
b62a4bacd4
commit
f296464dae
@ -28,6 +28,7 @@ namespace LibreNMS\Validations\Poller;
|
||||
use App\Models\Device;
|
||||
use App\Models\Poller;
|
||||
use App\Models\PollerCluster;
|
||||
use LibreNMS\DB\Eloquent;
|
||||
use LibreNMS\ValidationResult;
|
||||
|
||||
class CheckActivePoller implements \LibreNMS\Interfaces\Validation
|
||||
@ -40,7 +41,9 @@ class CheckActivePoller implements \LibreNMS\Interfaces\Validation
|
||||
$dispatcher_exists = PollerCluster::isActive()->exists();
|
||||
$wrapper_exists = Poller::isActive()->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) {
|
||||
@ -55,6 +58,6 @@ class CheckActivePoller implements \LibreNMS\Interfaces\Validation
|
||||
*/
|
||||
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\Poller;
|
||||
use App\Models\PollerCluster;
|
||||
use LibreNMS\DB\Eloquent;
|
||||
use LibreNMS\ValidationResult;
|
||||
|
||||
class CheckDispatcherService implements \LibreNMS\Interfaces\Validation
|
||||
@ -49,7 +50,7 @@ class CheckDispatcherService implements \LibreNMS\Interfaces\Validation
|
||||
*/
|
||||
public function enabled(): bool
|
||||
{
|
||||
return Device::exists();
|
||||
return Eloquent::isConnected() && Device::exists();
|
||||
}
|
||||
|
||||
private function checkDispatchService(): ValidationResult
|
||||
|
@ -28,6 +28,7 @@ namespace LibreNMS\Validations\Poller;
|
||||
use App\Models\Poller;
|
||||
use App\Models\PollerCluster;
|
||||
use LibreNMS\Config;
|
||||
use LibreNMS\DB\Eloquent;
|
||||
use LibreNMS\ValidationResult;
|
||||
|
||||
class CheckPythonWrapper implements \LibreNMS\Interfaces\Validation
|
||||
@ -70,7 +71,7 @@ class CheckPythonWrapper implements \LibreNMS\Interfaces\Validation
|
||||
*/
|
||||
public function enabled(): bool
|
||||
{
|
||||
return true;
|
||||
return Eloquent::isConnected();
|
||||
}
|
||||
|
||||
private function checkPythonWrapper(): ValidationResult
|
||||
|
@ -117,6 +117,20 @@ class Validator
|
||||
}, 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.
|
||||
*
|
||||
|
@ -100,7 +100,7 @@ if (! module_selected('nodb', $init_modules)) {
|
||||
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...
|
||||
|
@ -267,7 +267,7 @@ return [
|
||||
],
|
||||
'poller' => [
|
||||
'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',
|
||||
'ok' => 'Active pollers found',
|
||||
],
|
||||
|
@ -268,7 +268,7 @@ return [
|
||||
],
|
||||
'poller' => [
|
||||
'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',
|
||||
'ok' => 'Pollers ativos encontrados',
|
||||
],
|
||||
|
@ -268,7 +268,7 @@ return [
|
||||
],
|
||||
'poller' => [
|
||||
'CheckActivePoller' => [
|
||||
'fail' => '未检测到活动的轮询方法',
|
||||
'fail' => '轮询器未运行。 过去 :interval 秒内没有运行任何轮询器。',
|
||||
'both_fail' => '调度程序服务和Python包装器最近都处于活动状态,这可能导致双重轮询',
|
||||
'ok' => '找到活动的轮询器',
|
||||
],
|
||||
|
17
validate.php
17
validate.php
@ -51,7 +51,7 @@ if (isset($options['h'])) {
|
||||
Example: ./validate.php -g mail.
|
||||
|
||||
";
|
||||
exit;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (function_exists('posix_getuid') && posix_getuid() === 0) {
|
||||
@ -62,7 +62,7 @@ if (function_exists('posix_getuid') && posix_getuid() === 0) {
|
||||
// Check autoload
|
||||
if (! file_exists('vendor/autoload.php')) {
|
||||
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';
|
||||
@ -114,17 +114,17 @@ if ($validator->getGroupStatus('dependencies') == ValidationResult::FAILURE) {
|
||||
}
|
||||
|
||||
if ($pre_checks_failed) {
|
||||
exit;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$init_modules = [];
|
||||
$init_modules = ['nodb'];
|
||||
require 'includes/init.php';
|
||||
|
||||
// make sure install_dir is set correctly, or the next includes will fail
|
||||
if (! file_exists(Config::get('install_dir') . '/.env')) {
|
||||
$suggested = realpath(__DIR__);
|
||||
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()) {
|
||||
@ -144,9 +144,16 @@ if (isset($options['g'])) {
|
||||
$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
|
||||
$validator->validate($modules, isset($options['s']) || ! empty($modules));
|
||||
|
||||
exit($validator->getStatus() ? 0 : 1);
|
||||
|
||||
function print_header()
|
||||
{
|
||||
$output = ob_get_clean();
|
||||
|
Loading…
Reference in New Issue
Block a user