feature: validate.php: check poller and discovery status (#4663)

This commit is contained in:
Tony Murray
2016-10-03 11:48:19 -05:00
committed by Neil Lathwood
parent d712f4ca69
commit c5177c26af
2 changed files with 97 additions and 60 deletions

View File

@@ -1118,7 +1118,7 @@ function version_info($remote = true)
$output['php_ver'] = phpversion();
$output['mysql_ver'] = dbFetchCell('SELECT version()');
$output['rrdtool_ver'] = implode(' ', array_slice(explode(' ', shell_exec($config['rrdtool'].' --version |head -n1')), 1, 1));
$output['netsnmp_ver'] = shell_exec($config['snmpget'].' --version 2>&1');
$output['netsnmp_ver'] = str_replace('version: ', '', rtrim(shell_exec($config['snmpget'].' --version 2>&1')));
return $output;
}//end version_info()

View File

@@ -15,6 +15,9 @@
chdir(__DIR__); // cwd to the directory containing this script
require_once 'includes/defaults.inc.php';
require_once 'includes/common.php';
$options = getopt('m:h::');
if (isset($options['h'])) {
@@ -35,20 +38,62 @@ if (isset($options['h'])) {
exit;
}
if (strstr(`php -ln config.php`, 'No syntax errors detected')) {
$first_line = `head -n1 config.php`;
$last_lines = explode(PHP_EOL, `tail -n2 config.php`);
if (substr($first_line, 0, 5) !== '<?php') {
print_fail("config.php doesn't start with a <?php - please fix this ($first_line)");
} elseif ($last_lines[0] == '?>' && $last_lines[1] == '') {
print_fail('config.php contains a new line at the end, please remove any whitespace at the end of the file and also remove ?>');
} elseif ($last_lines[1] == '?>') {
print_warn("It looks like you have ?> at the end of config.php, it is suggested you remove this");
}
} else {
print_fail('Syntax error in config.php');
$console_color = new Console_Color2();
// critical config.php checks
if (!file_exists('config.php')) {
print_fail('config.php does not exist, please copy config.php.default to config.php');
exit;
}
$config_failed = false;
$syntax_check = `php -ln config.php`;
if (!str_contains($syntax_check, 'No syntax errors detected')) {
print_fail('Syntax error in config.php');
echo $syntax_check;
$config_failed = true;
}
$first_line = rtrim(`head -n1 config.php`);
if (!starts_with($first_line, '<?php')) {
print_fail("config.php doesn't start with a <?php - please fix this ($first_line)");
$config_failed = true;
}
if (str_contains(`tail config.php`, '?>')) {
print_fail("Remove the ?> at the end of config.php");
$config_failed = true;
}
if ($config_failed) {
exit;
}
// load config.php now
require_once 'config.php';
// make sure install_dir is set correctly, or the next includes will fail
if (!file_exists($config['install_dir'].'/config.php')) {
print_fail('$config[\'install_dir\'] is not set correctly. It should probably be set to: ' . getcwd());
exit;
}
// continue loading includes
require_once 'includes/definitions.inc.php';
require_once 'includes/functions.php';
require_once 'includes/alerts.inc.php';
$versions = version_info();
$cur_sha = $versions['local_sha'];
echo "==========================================================\n";
echo "LibreNMS Version: $cur_sha\n";
echo "DB Schema: ".$versions['db_schema']."\n";
echo "PHP: ".$versions['php_ver']."\n";
echo "MySQL: ".$versions['mysql_ver']."\n";
echo "RRDTool: ".$versions['rrdtool_ver']."\n";
echo "SNMP: ".$versions['netsnmp_ver']."\n";
echo "==========================================================\n\n";
// Check we are running this as the root user
if (function_exists('posix_getpwuid')) {
$userinfo = posix_getpwuid(posix_geteuid());
@@ -60,53 +105,10 @@ if ($username !== 'root') {
print_fail("You need to run this script as root");
}
// load config.php now
require_once 'includes/defaults.inc.php';
require_once 'config.php';
// make sure install_dir is set correctly, or the next includes will fail
if (!file_exists($config['install_dir'].'/config.php')) {
print_fail('$config[\'install_dir\'] is not set correctly. It should probably be set to: ' . getcwd());
exit;
}
// continue loading includes
require_once 'includes/definitions.inc.php';
require_once 'includes/functions.php';
require_once 'includes/common.php';
require_once $config['install_dir'].'/includes/alerts.inc.php';
$versions = version_info();
echo "====================================\n";
echo "Version info:\n";
$cur_sha = $versions['local_sha'];
if ($config['update_channel'] == 'master' && $cur_sha != $versions['github']['sha']) {
$commit_date = new DateTime('@'.$versions['local_date'], new DateTimeZone(date_default_timezone_get()));
print_warn("Your install is out of date: $cur_sha " . $commit_date->format('(r)'));
} else {
echo "Commit SHA: $cur_sha\n";
print_warn("Your install is out of date, last update: " . $commit_date->format('r'));
}
if ($versions['local_branch'] != 'master') {
print_warn("Your local git branch is not master, this will prevent automatic updates.");
}
// check for modified files
$modifiedcmd = 'git diff --name-only --exit-code';
if ($username === 'root') {
$modifiedcmd = 'su '.$config['user'].' -c "'.$modifiedcmd.'"';
}
exec($modifiedcmd, $cmdoutput, $code);
if ($code !== 0 && !empty($cmdoutput)) {
print_warn("Your local git contains modified files, this could prevent automatic updates.\nModified files:");
echo(' ' . implode("\n ", $cmdoutput) . "\n");
}
echo "DB Schema: ".$versions['db_schema']."\n";
echo "PHP: ".$versions['php_ver']."\n";
echo "MySQL: ".$versions['mysql_ver']."\n";
echo "RRDTool: ".$versions['rrdtool_ver']."\n";
echo "SNMP: ".$versions['netsnmp_ver']."\n";
echo "====================================\n";
// Check php modules we use to make sure they are loaded
$extensions = array('pcre','curl','session','snmp','mcrypt');
@@ -226,6 +228,41 @@ if (!function_exists('openssl_random_pseudo_bytes')) {
}
}
// check discovery last run
if (dbFetchCell('SELECT COUNT(`device_id`) FROM `devices` WHERE `last_discovered` IS NOT NULL') == 0) {
print_fail('Discovery has never run, check the cron job');
} elseif (dbFetchCell("SELECT COUNT(`device_id`) FROM `devices` WHERE `last_discovered` <= DATE_ADD(NOW(), INTERVAL - 24 hours) AND `ignore` = 0 AND `disabled` = 0 AND `status` = 1") > 0) {
print_fail("Discovery has not run in the last 24 hours, check the cron job");
}
// check poller
if (dbFetchCell('SELECT COUNT(`device_id`) FROM `devices` WHERE `last_polled` IS NOT NULL') == 0) {
print_fail('The poller has never run, check the cron job');
} elseif (dbFetchCell("SELECT COUNT(`device_id`) FROM `devices` WHERE `last_polled` <= DATE_ADD(NOW(), INTERVAL - 5 minute) AND `ignore` = 0 AND `disabled` = 0 AND `status` = 1") > 0) {
print_fail("The poller has not run in the last 5 minutes, check the cron job");
} elseif (dbFetchCell("SELECT COUNT(`device_id`) FROM `devices` WHERE (`last_polled` <= DATE_ADD(NOW(), INTERVAL - 5 minute) OR `last_polled` IS NULL) AND `ignore` = 0 AND `disabled` = 0 AND `status` = 1") > 0) {
print_warn("Some devices have not been polled in the last 5 minutes, check your poll log");
}
if (dbFetchCell('SELECT COUNT(`device_id`) FROM `devices` WHERE last_polled_timetaken > 300 AND `ignore` = 0 AND `disabled` = 0 AND `status` = 1') > 0) {
print_fail("Some devices have not completed their polling run in 5 minutes, this will create gaps in data.\n Check your poll log and refer to http://docs.librenms.org/Support/Performance/");
}
if ($versions['local_branch'] != 'master') {
print_warn("Your local git branch is not master, this will prevent automatic updates.");
}
// check for modified files
$modifiedcmd = 'git diff --name-only --exit-code';
if ($username === 'root') {
$modifiedcmd = 'su '.$config['user'].' -c "'.$modifiedcmd.'"';
}
exec($modifiedcmd, $cmdoutput, $code);
if ($code !== 0 && !empty($cmdoutput)) {
print_warn("Your local git contains modified files, this could prevent automatic updates.\nModified files:");
echo(' ' . implode("\n ", $cmdoutput) . "\n");
}
// Modules test
$modules = explode(',', $options['m']);
foreach ($modules as $module) {
@@ -339,19 +376,19 @@ foreach ($modules as $module) {
function print_ok($msg)
{
echo "[OK] $msg\n";
c_echo("[%gOK%n] $msg\n");
}//end print_ok()
function print_fail($msg)
{
echo "[FAIL] $msg\n";
c_echo("[%RFAIL%n] $msg\n");
}//end print_fail()
function print_warn($msg)
{
echo "[WARN] $msg\n";
c_echo("[%YWARN%n] $msg\n");
}//end print_warn()
function check_rrdcached()