Merge pull request #19 from VeoPVM/develop

Add uptime checking
This commit is contained in:
Pep 2014-02-27 17:18:36 +01:00
commit 4f5e4d1ce2
3 changed files with 39 additions and 0 deletions

View File

@ -77,6 +77,14 @@ foreach ($servers as $server) {
$save,
array('server_id' => $server['server_id'])
);
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());
}
}
psm_update_conf('cron_running', 0);

View File

@ -168,6 +168,27 @@ 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 int $status
* @param string $latency
*/
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
*

View File

@ -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;