From d83b6750901f6e675e63501409f48c4aaf8d7e2b Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Tue, 21 Aug 2018 16:21:55 -0500 Subject: [PATCH] Check for incorrect heartbeats in rrdtstep.php script (#9041) Also, fix some incorrect config names (rrd_step -> rrd.step) DO NOT DELETE THIS TEXT #### Please note > Please read this information carefully. You can run `./scripts/pre-commit.php` to check your code before submitting. - [x] Have you followed our [code guidelines?](http://docs.librenms.org/Developing/Code-Guidelines/) #### Testers If you would like to test this pull request then please run: `./scripts/github-apply `, i.e `./scripts/github-apply 5926` --- LibreNMS/Validations/Poller.php | 4 ++-- app/Jobs/PingCheck.php | 2 +- html/includes/table/poll-log.inc.php | 2 +- scripts/rrdstep.php | 22 +++++++++++++++++----- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/LibreNMS/Validations/Poller.php b/LibreNMS/Validations/Poller.php index d5dbcd4fc6..0e61a6b66e 100644 --- a/LibreNMS/Validations/Poller.php +++ b/LibreNMS/Validations/Poller.php @@ -107,7 +107,7 @@ class Poller extends BaseValidation private function checkDeviceLastPolled(Validator $validator) { - $overdue = (int)(Config::get('rrd_step', 300) * 1.2); + $overdue = (int)(Config::get('rrd.step', 300) * 1.2); if (count($devices = dbFetchColumn("SELECT `hostname` FROM `devices` WHERE (`last_polled` < DATE_ADD(NOW(), INTERVAL - $overdue SECOND) 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.") ->setList('Devices', $devices); @@ -126,7 +126,7 @@ class Poller extends BaseValidation private function checkDevicePollDuration(Validator $validator) { - $period = (int)Config::get('rrd_step', 300); + $period = (int)Config::get('rrd.step', 300); if (count($devices = dbFetchColumn("SELECT `hostname` FROM `devices` WHERE last_polled_timetaken > $period 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.") ->setList('Devices', $devices); diff --git a/app/Jobs/PingCheck.php b/app/Jobs/PingCheck.php index 616c1d3861..4ed81ba47d 100644 --- a/app/Jobs/PingCheck.php +++ b/app/Jobs/PingCheck.php @@ -81,7 +81,7 @@ class PingCheck implements ShouldQueue $cmd = ['fping', '-f', '-', '-e', '-t', $timeout, '-r', $retries]; - $wait = Config::get('rrd_step', 300) * 2; + $wait = Config::get('rrd.step', 300) * 2; $this->process = new Process($cmd, null, null, null, $wait); } diff --git a/html/includes/table/poll-log.inc.php b/html/includes/table/poll-log.inc.php index 14a8e907b1..784f5838d4 100644 --- a/html/includes/table/poll-log.inc.php +++ b/html/includes/table/poll-log.inc.php @@ -22,7 +22,7 @@ if (isset($searchPhrase) && !empty($searchPhrase)) { } if ($vars['type'] == "unpolled") { - $overdue = (int)(Config::get('rrd_step', 300) * 1.2); + $overdue = (int)(Config::get('rrd.step', 300) * 1.2); $sql .= " AND `last_polled` <= DATE_ADD(NOW(), INTERVAL - $overdue SECOND)"; } diff --git a/scripts/rrdstep.php b/scripts/rrdstep.php index 6459ca179c..1700f7fd28 100755 --- a/scripts/rrdstep.php +++ b/scripts/rrdstep.php @@ -79,12 +79,24 @@ foreach ($files as $file) { } $rrd_info = shell_exec("$rrdtool info $file"); - preg_match('/step = (\d+)/', $rrd_info, $matches); + preg_match('/step = (\d+)/', $rrd_info, $step_matches); - if ($matches[1] == $step) { - d_echo("Skipping $file, step is already $step.\n"); - $skipped++; - continue; + if ($step_matches[1] == $step) { + preg_match_all('/minimal_heartbeat = (\d+)/', $rrd_info, $heartbeat_matches); + try { + foreach ($heartbeat_matches[1] as $ds_heartbeat) { + if ($ds_heartbeat != $heartbeat) { + throw new Exception("Mismatched heartbeat. {$ds_heartbeat} != $heartbeat"); + } + } + // all heartbeats ok + + d_echo("Skipping $file, step is already $step.\n"); + $skipped++; + continue; + } catch (Exception $e) { + echo $e->getMessage() . PHP_EOL; + } } echo "Converting $file: ";