This commit is contained in:
Germs2004 2022-01-12 17:03:16 +02:00 committed by GitHub
commit 675f8a6797
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 93 additions and 59 deletions

View File

@ -258,6 +258,8 @@ $sm_lang = array(
'hour' => 'Hour',
'warning_threshold' => 'Warning threshold',
'warning_threshold_description' => 'Number of failed checks required before it is marked offline.',
'connectivity_sanity_test' => 'phpservermon Connectivity Sanity Test',
'connectivity_sanity_test_description' => 'Optional. The IP address entered here should be one that is trusted to be always online. It will be pinged before and after this server gets checked. If either sanity (ping) test fails, then it is assumed that phpservermon has a connectivity problem and the results will not be saved. If both sanity tests pass, the server results will be logged like normal. To disable this sanity test, leave this box blank.',
'ssl_cert_expiry_days' => 'SSL Certificate Validity',
'ssl_cert_expiry_days_description' => 'The minimum remaining days the SSL certificate is still valid. Use 0 to disable check.',
'ssl_cert_expired' => 'SSL certificate expired since',

View File

@ -611,6 +611,8 @@ class ServerController extends AbstractServerController
'label_users' => psm_get_lang('servers', 'users'),
'label_warning_threshold' => psm_get_lang('servers', 'warning_threshold'),
'label_warning_threshold_description' => psm_get_lang('servers', 'warning_threshold_description'),
'label_connectivity_sanity_test' => psm_get_lang('servers', 'connectivity_sanity_test'),
'label_connectivity_sanity_test_description' => psm_get_lang('servers', 'connectivity_sanity_test_description'),
'label_ssl_cert_expiry_days' => psm_get_lang('servers', 'ssl_cert_expiry_days'),
'label_ssl_cert_expiry_days_description' => psm_get_lang('servers', 'ssl_cert_expiry_days_description'),
'label_action' => psm_get_lang('system', 'action'),

View File

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

View File

@ -45,6 +45,8 @@
</optgroup>
</select>
</div>
<!-- Connectivity Sanity Test -->
{{ macro.input_field("text", "connectivity_sanity_test", null, "connectivity_sanity_test", label_connectivity_sanity_test, edit_value_connectivity_sanity_test, null, null, null, label_connectivity_sanity_test_description, null, null, null) }}
<!-- Custom port -->
{{ macro.input_field("number", "port", "port types typeService", "port", label_custom_port, edit_value_port, null, "5") }}
<!-- SSL Cert check -->