added support for connectivity_sanity_test
If the user has entered an IP address for the connectivity_sanity_test field on the server edit page, that IP address will be pinged before and after that server gets checked. If either of those pings fails, the server uptime results will not be logged because it is assumed that the phpservermon system is experiencing a connectivity problem. If both sanity test pings succeed, the server uptime results will be logged as normal.
This commit is contained in:
parent
550b7ad4fc
commit
cb75c86574
|
@ -95,20 +95,34 @@ class StatusUpdater
|
|||
$this->server = $this->db->selectRow(PSM_DB_PREFIX . 'servers', array(
|
||||
'server_id' => $server_id,
|
||||
), array(
|
||||
'server_id', 'ip', 'port', 'request_method', 'label',
|
||||
'server_id', 'connectivity_sanity_test',
|
||||
'ip', 'port', 'request_method', 'label',
|
||||
'type', 'pattern', 'pattern_online', 'post_field',
|
||||
'allow_http_status', 'redirect_check', 'header_name',
|
||||
'header_value', 'status', 'active', 'warning_threshold',
|
||||
'warning_threshold_counter', 'ssl_cert_expiry_days', 'ssl_cert_expired_time', 'timeout', 'website_username',
|
||||
'warning_threshold_counter', 'ssl_cert_expiry_days',
|
||||
'ssl_cert_expired_time', 'timeout', 'website_username',
|
||||
'website_password', 'last_offline'
|
||||
));
|
||||
if (empty($this->server)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// do Sanity Test before checking the actual server
|
||||
$sanity_result_before = true;
|
||||
$sanity_result_after = true;
|
||||
$connectivity_sanity_test_ip = escapeshellcmd($this->server['connectivity_sanity_test']);
|
||||
if (!empty($connectivity_sanity_test_ip))
|
||||
{
|
||||
$sanity_result_before = $this->updatePing($connectivity_sanity_test_ip, 1);
|
||||
}
|
||||
|
||||
if ($sanity_result_before) {
|
||||
// check the actual server
|
||||
switch ($this->server['type']) {
|
||||
case 'ping':
|
||||
$this->status_new = $this->updatePing($max_runs);
|
||||
$ip_to_ping = escapeshellcmd($this->server['ip']);
|
||||
$this->status_new = $this->updatePing($ip_to_ping, $max_runs);
|
||||
break;
|
||||
case 'service':
|
||||
$this->status_new = $this->updateService($max_runs);
|
||||
|
@ -118,6 +132,16 @@ class StatusUpdater
|
|||
break;
|
||||
}
|
||||
|
||||
// do Sanity Test again after checking the server
|
||||
if (!empty($connectivity_sanity_test_ip))
|
||||
{
|
||||
$sanity_result_after = $this->updatePing($connectivity_sanity_test_ip, 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Only log the results if both sanity tests pass (or if they were not requested)
|
||||
if ($sanity_result_before && $sanity_result_after) {
|
||||
|
||||
// update server status
|
||||
$save = array(
|
||||
'last_check' => date('Y-m-d H:i:s'),
|
||||
|
@ -165,28 +189,32 @@ class StatusUpdater
|
|||
$this->db->save(PSM_DB_PREFIX . 'servers', $save, array('server_id' => $this->server_id));
|
||||
|
||||
return $this->status_new;
|
||||
} else {
|
||||
// if either Sanity Test failed, do not log the results from the server check
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the current servers ping status
|
||||
* @param string $ip_to_ping
|
||||
* @param int $max_runs
|
||||
* @param int $run
|
||||
* @return boolean
|
||||
*/
|
||||
protected function updatePing($max_runs, $run = 1)
|
||||
protected function updatePing($ip_to_ping, $max_runs, $run = 1)
|
||||
{
|
||||
// Settings
|
||||
$max_runs = ($max_runs == null || $max_runs > 1) ? 1 : $max_runs;
|
||||
$server_ip = escapeshellcmd($this->server['ip']);
|
||||
$os_is_windows = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
|
||||
|
||||
$status = $os_is_windows ?
|
||||
$this->pingFromWindowsMachine($server_ip, $max_runs) :
|
||||
$this->pingFromNonWindowsMachine($server_ip, $max_runs);
|
||||
$this->pingFromWindowsMachine($ip_to_ping, $max_runs) :
|
||||
$this->pingFromNonWindowsMachine($ip_to_ping, $max_runs);
|
||||
|
||||
// check if server is available and rerun if asked.
|
||||
if (!$status && $run < $max_runs) {
|
||||
return $this->updatePing($max_runs, $run + 1);
|
||||
return $this->updatePing($ip_to_ping, $max_runs, $run + 1);
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue