Skip to content

Commit

Permalink
feature: validate list devices that have not been polled in the last …
Browse files Browse the repository at this point in the history
…5 minutes or took more than 5 minutes to poll (#5037)
  • Loading branch information
murrant authored and laf committed Nov 23, 2016
1 parent db240cb commit 6890a71
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
20 changes: 20 additions & 0 deletions includes/common.php
Expand Up @@ -1487,6 +1487,26 @@ function get_auth_ad_group_filter($groupname)
return $group_filter;
}

/**
* Print a list of items up to a max amount
* If over that number, a line will print the total items
*
* @param array $list
* @param string $format format as consumed by printf()
* @param int $max the max amount of items to print, default 10
*/
function print_list($list, $format, $max = 10)
{
foreach (array_slice($list, 0, $max) as $item) {
printf($format, $item);
}

$extra = count($list) - $max;
if ($extra > 0) {
printf($format, " and $extra more...");
}
}

/**
* @param $value
* @return string
Expand Down
13 changes: 6 additions & 7 deletions validate.php
Expand Up @@ -139,10 +139,7 @@
$files = explode(PHP_EOL, $find_result);
if (is_array($files)) {
print_fail("We have found some files that are owned by a different user than $tmp_user, this will stop you updating automatically and / or rrd files being updated causing graphs to fail:\nIf you don't run a bespoke install then you can fix this by running `chown -R $tmp_user:$tmp_user ".$config['install_dir']."`");
foreach ($files as $file) {
echo "$file\n";
}
echo "\n";
print_list($files, "\t %s\n");
}
}
} else {
Expand Down Expand Up @@ -243,12 +240,14 @@
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) {
} elseif (count($devices = dbFetchColumn("SELECT `hostname` 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");
print_list($devices, "\t %s\n");
}

if (dbFetchCell('SELECT COUNT(`device_id`) FROM `devices` WHERE last_polled_timetaken > 300 AND `ignore` = 0 AND `disabled` = 0 AND `status` = 1') > 0) {
if (count($devices = dbFetchColumn('SELECT `hostname` 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/");
print_list($devices, "\t %s\n");
}

if ($versions['local_branch'] != 'master') {
Expand All @@ -263,7 +262,7 @@
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");
print_list($cmdoutput, "\t %s\n");
}

// Modules test
Expand Down

0 comments on commit 6890a71

Please sign in to comment.