From 586f7e90c5884332d9c93b0d5013e614f76b4b1a Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Mon, 9 Jan 2017 14:17:16 -0600 Subject: [PATCH] fix: validate mysql queries (#5365) --- validate.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/validate.php b/validate.php index 8bcff39f5aa5..1bf8b5dccc34 100755 --- a/validate.php +++ b/validate.php @@ -229,24 +229,26 @@ } // check discovery last run -if (dbFetchCell('SELECT COUNT(`device_id`) FROM `devices` WHERE `last_discovered` IS NOT NULL') == 0) { +if (dbFetchCell('SELECT COUNT(*) 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"); +} 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) { + print_fail("Discovery has not completed 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) { +if (dbFetchCell('SELECT COUNT(*) 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) { +} elseif (dbFetchCell("SELECT COUNT(*) 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 (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_warn("Some devices have not been polled in the last 5 minutes. + You may have performance issues. Check your poll log and see: http://docs.librenms.org/Support/Performance/"); print_list($devices, "\t %s\n"); } 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_fail("Some devices have not completed their polling run in 5 minutes, this will create gaps in data. + Check your poll log and refer to http://docs.librenms.org/Support/Performance/"); print_list($devices, "\t %s\n"); }