fix: Improve poller validation (#7586)

* fix: improve poller validation
remove failures when there are duplicate poller entries
add warning that there are duplicate poller entries
link to the poller log in the webui
small fix to getBaseURL() to avoid exception when run from cli.

* Re-run poller cleanup to try to reduce the users with duplicates.
This commit is contained in:
Tony Murray
2017-10-31 15:32:56 -05:00
committed by Neil Lathwood
parent a71c33fb63
commit d809bddb4e
3 changed files with 58 additions and 11 deletions

View File

@@ -53,35 +53,81 @@ class Poller implements ValidationGroup
return; // can't check poller/discovery if there are no devices.
}
// FIXME pollers table is only updated by poller-wrapper.py
// check poller
$this->checkDuplicatePollerEntries($validator);
$this->checkLastPolled($validator);
$this->checkDeviceLastPolled($validator);
$this->checkDevicePollDuration($validator);
$this->checkLastDiscovered($validator);
}
private function checkDuplicatePollerEntries(Validator $validator)
{
$sql = "SELECT TRIM(TRAILING '\n' FROM `poller_name`) as `name`, COUNT(*) as `count` FROM `pollers` GROUP BY `name`;";
foreach (dbFetchRows($sql) as $poller) {
if ($poller['count'] > 1) {
$validator->warn(
'Duplicate poller entries',
"Remove duplicates manually or with: DELETE FROM `pollers` WHERE `poller_name` LIKE '%\\n'"
);
}
}
}
private function checkLastPolled(Validator $validator)
{
// pollers table is only updated by poller-wrapper.py
if (dbFetchCell('SELECT COUNT(*) FROM `pollers`')) {
$pollers = dbFetchColumn('SELECT `poller_name` FROM `pollers` WHERE `last_polled` <= DATE_ADD(NOW(), INTERVAL - 5 MINUTE)');
$dedupe_sql = "SELECT TRIM(TRAILING '\\n' FROM `poller_name`) AS `name`, MAX(`last_polled`) AS `polled` FROM `pollers` GROUP BY `name`";
$sql = "SELECT `name` FROM ($dedupe_sql) AS pt WHERE `polled` <= DATE_ADD(NOW(), INTERVAL - 5 MINUTE)";
$pollers = dbFetchColumn($sql);
if (count($pollers) > 0) {
foreach ($pollers as $poller) {
$validator->fail("The poller ($poller) has not complete within the last 5 minutes, check the cron job");
$validator->fail("The poller ($poller) has not completed within the last 5 minutes, check the cron job");
}
}
} else {
$validator->fail('The poller has never run, check the cron job');
$validator->fail('The poller has never run or you are not using poller-wrapper.py, check the cron job');
}
}
// check devices polling
private function checkDeviceLastPolled(Validator $validator)
{
if (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) {
$result = ValidationResult::warn("Some devices have not been polled in the last 5 minutes. You may have performance issues.")
->setFix('Check your poll log and see: http://docs.librenms.org/Support/Performance/')
->setList('Devices', $devices);
if (isCli()) {
$result->setFix('Check your poll log and see: http://docs.librenms.org/Support/Performance/');
} else {
$base_url = $validator->getBaseURL();
$result->setFix("Check $base_url/poll-log/ and see: http://docs.librenms.org/Support/Performance/");
}
$validator->result($result);
}
}
private function checkDevicePollDuration(Validator $validator)
{
if (count($devices = dbFetchColumn('SELECT `hostname` FROM `devices` WHERE last_polled_timetaken > 300 AND `ignore` = 0 AND `disabled` = 0 AND `status` = 1')) > 0) {
$result = ValidationResult::fail("Some devices have not completed their polling run in 5 minutes, this will create gaps in data.")
->setFix("Check your poll log and refer to http://docs.librenms.org/Support/Performance/")
->setList('Devices', $devices);
if (isCli()) {
$result->setFix('Check your poll log and see: http://docs.librenms.org/Support/Performance/');
} else {
$base_url = $validator->getBaseURL();
$result->setFix("Check $base_url/poll-log/ and see: http://docs.librenms.org/Support/Performance/");
}
$validator->result($result);
}
}
// check discovery last run
private function checkLastDiscovered(Validator $validator)
{
if (dbFetchCell('SELECT COUNT(*) FROM `devices` WHERE `last_discovered` IS NOT NULL') == 0) {
$validator->fail('Discovery has never run.", "Check the cron job');
} elseif (dbFetchCell("SELECT COUNT(*) FROM `devices` WHERE `last_discovered` <= DATE_ADD(NOW(), INTERVAL - 24 HOUR) AND `ignore` = 0 AND `disabled` = 0 AND `status` = 1") > 0) {

View File

@@ -267,7 +267,7 @@ class Validator
*/
public function getBaseURL()
{
$url = Config::get('base_url', get_url());
return rtrim(str_replace('validate', '', $url), '/');
$url = function_exists('get_url') ? get_url() : Config::get('base_url');
return rtrim(str_replace('validate', '', $url), '/'); // get base_url from current url
}
}

1
sql-schema/214.sql Normal file
View File

@@ -0,0 +1 @@
DELETE FROM `pollers` WHERE `poller_name` LIKE '%\n';