From 7a91b8a3f3143248c767d576505ad9239582b975 Mon Sep 17 00:00:00 2001 From: Perri Date: Wed, 26 Feb 2014 21:06:33 +0000 Subject: [PATCH 1/4] Add database functions and upgrade queries for uptime logging feature --- src/includes/functions.inc.php | 20 ++++++++++++++++++++ src/psm/Util/Install/Queries.class.php | 10 ++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/includes/functions.inc.php b/src/includes/functions.inc.php index 7bcc6724..053e946a 100755 --- a/src/includes/functions.inc.php +++ b/src/includes/functions.inc.php @@ -168,6 +168,26 @@ function psm_add_log($server_id, $type, $message, $user_id = null) { ); } +/** + * This function adds the result of a check to the uptime table for logging purposes. + * + * @param int $server_id + * @param string $message + */ +function psm_log_uptime($server_id, $status, $latency) { + global $db; + + $db->save( + PSM_DB_PREFIX.'uptime', + array( + 'server_id' => $server_id, + 'date' => date('Y-m-d H:i:s'), + 'status' => $status, + 'latency' => $latency, + ) + ); +} + /** * Parses a string from the language file with the correct variables replaced in the message * diff --git a/src/psm/Util/Install/Queries.class.php b/src/psm/Util/Install/Queries.class.php index ab9254ce..4c91c7d1 100644 --- a/src/psm/Util/Install/Queries.class.php +++ b/src/psm/Util/Install/Queries.class.php @@ -130,6 +130,16 @@ class Queries { } + if(version_compare($version_from, '2.1.0', '<=')) { + // 2.1 upgrade + $queries[] = "CREATE TABLE `" . PSM_DB_PREFIX . "uptime` ( + `server_id` INT( 11 ) NOT NULL , + `date` DATETIME NOT NULL , + `status` INT( 1 ) NOT NULL , + `latency` FLOAT( 9, 7 ) NULL + ) ENGINE = MYISAM ;" + } + } $queries[] = "UPDATE `" . PSM_DB_PREFIX . "config` SET `value` = '{$version}' WHERE `key` = 'version';"; } return $queries; From 71ab326ddb00f089f6e3b9fca0f65be2d5d8b2d2 Mon Sep 17 00:00:00 2001 From: Perri Date: Wed, 26 Feb 2014 21:54:11 +0000 Subject: [PATCH 2/4] Log uptime to database --- cron/status.cron.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cron/status.cron.php b/cron/status.cron.php index 6a76ed41..de588ff9 100755 --- a/cron/status.cron.php +++ b/cron/status.cron.php @@ -77,6 +77,12 @@ foreach ($servers as $server) { $save, array('server_id' => $server['server_id']) ); + + if(status_new == "on") { + psm_log_uptime($server['server_id'], 1, $updater->getRtime()); + } else { + psm_log_uptime($server['server_id'], 0, $updater->getRtime()); + } } psm_update_conf('cron_running', 0); From fafc0448bda74fa10ef8ffcedb8ee301e208602a Mon Sep 17 00:00:00 2001 From: Perri Date: Wed, 26 Feb 2014 22:01:47 +0000 Subject: [PATCH 3/4] Add a couple of comments to make it clearer --- cron/status.cron.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cron/status.cron.php b/cron/status.cron.php index de588ff9..b3a7553c 100755 --- a/cron/status.cron.php +++ b/cron/status.cron.php @@ -79,8 +79,10 @@ foreach ($servers as $server) { ); if(status_new == "on") { + // Status is 1 if online psm_log_uptime($server['server_id'], 1, $updater->getRtime()); } else { + // Status is 0 if offline psm_log_uptime($server['server_id'], 0, $updater->getRtime()); } } From 9100ae2412de82fac55a90102ca3d25c1be273b1 Mon Sep 17 00:00:00 2001 From: Perri Date: Thu, 27 Feb 2014 00:59:43 +0000 Subject: [PATCH 4/4] Correct comments --- src/includes/functions.inc.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/includes/functions.inc.php b/src/includes/functions.inc.php index 053e946a..4994ee7a 100755 --- a/src/includes/functions.inc.php +++ b/src/includes/functions.inc.php @@ -172,7 +172,8 @@ function psm_add_log($server_id, $type, $message, $user_id = null) { * This function adds the result of a check to the uptime table for logging purposes. * * @param int $server_id - * @param string $message + * @param int $status + * @param string $latency */ function psm_log_uptime($server_id, $status, $latency) { global $db;