Added option to view latest (failing) server response and error (#627)

Shows:
- latest error.
- latest positive response.
- latest failure response.
This commit is contained in:
Tim 2018-09-05 22:52:23 +02:00 committed by GitHub
parent 72b262c706
commit b26f85d975
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 57 additions and 4 deletions

View File

@ -5,6 +5,7 @@ Changelog
Not yet released
----------------
* #627: Latest server output, error and output during a failure will be saved and are shown on the server page.
* #631: Added option to specify the request method.
* #628: Added the option to mark specific HTTP status codes as online.
* #640: Removed () after last offline value when the last offline duration is unknown.

View File

@ -50,6 +50,7 @@ $sm_lang = array(
'cancel' => 'Cancel',
'none' => 'None',
'activate' => 'Activate',
'advanced' => 'Advanced',
// date/time format according the strftime php function format parameter http://php.net/manual/function.strftime.php
'short_day_format' => '%B %e',
'long_day_format' => '%B %e, %Y',
@ -181,6 +182,9 @@ $sm_lang = array(
'last_check' => 'Last check',
'last_online' => 'Last online',
'last_offline' => 'Last offline',
'last_output' => 'Last positive output',
'last_error' => 'Last error',
'last_error_output' => 'Last error output',
'monitoring' => 'Monitoring',
'no_monitoring' => 'No monitoring',
'email' => 'Email',

View File

@ -85,7 +85,10 @@ abstract class AbstractServerController extends AbstractController {
`s`.`warning_threshold_counter`,
`s`.`timeout`,
`s`.`website_username`,
`s`.`website_password`
`s`.`website_password`,
`s`.`last_error`,
`s`.`last_error_output`,
`s`.`last_output`
FROM `".PSM_DB_PREFIX."servers` AS `s`
{$sql_join}
{$sql_where}
@ -127,6 +130,10 @@ abstract class AbstractServerController extends AbstractController {
$server['type'] = psm_get_lang('servers', 'type_'.$server['type']);
$server['timeout'] = ($server['timeout'] > 0) ? $server['timeout'] : PSM_CURL_TIMEOUT;
$server['last_error'] = htmlentities($server['last_error']);
$server['last_error_output'] = htmlentities($server['last_error_output']);
$server['last_output'] = htmlentities($server['last_output']);
$url_actions = array('delete', 'edit', 'view');
foreach ($url_actions as $action) {
$server['url_'.$action] = psm_build_url(array(

View File

@ -490,6 +490,9 @@ class ServerController extends AbstractServerController {
'label_rtime' => psm_get_lang('servers', 'latency'),
'label_last_online' => psm_get_lang('servers', 'last_online'),
'label_last_offline' => psm_get_lang('servers', 'last_offline'),
'label_last_output' => psm_get_lang('servers', 'last_output'),
'label_last_error' => psm_get_lang('servers', 'last_error'),
'label_last_error_output' => psm_get_lang('servers', 'last_error_output'),
'label_monitoring' => psm_get_lang('servers', 'monitoring'),
'label_email' => psm_get_lang('servers', 'email'),
'label_send_email' => psm_get_lang('servers', 'send_email'),
@ -508,6 +511,7 @@ class ServerController extends AbstractServerController {
'label_yes' => psm_get_lang('system', 'yes'),
'label_no' => psm_get_lang('system', 'no'),
'label_add_new' => psm_get_lang('system', 'add_new'),
'label_advanced' => psm_get_lang('system', 'advanced'),
'label_online' => psm_get_lang('system', 'online'),
'label_offline' => psm_get_lang('system', 'offline'),
);
@ -531,4 +535,3 @@ class ServerController extends AbstractServerController {
return $result;
}
}

View File

@ -250,6 +250,9 @@ class Installer {
`timeout` smallint(1) unsigned NULL DEFAULT NULL,
`website_username` varchar(255) DEFAULT NULL,
`website_password` varchar(255) DEFAULT NULL,
`last_error` varchar(255) DEFAULT NULL,
`last_error_output` varchar(255) DEFAULT NULL,
`last_output` varchar(255) DEFAULT NULL,
PRIMARY KEY (`server_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;",
PSM_DB_PREFIX.'servers_uptime' => "CREATE TABLE IF NOT EXISTS `".PSM_DB_PREFIX."servers_uptime` (
@ -551,6 +554,9 @@ class Installer {
*/
protected function upgrade340() {
$queries = array();
$queries[] = "ALTER TABLE `".PSM_DB_PREFIX."servers` ADD COLUMN `last_error` VARCHAR(255) NULL AFTER `website_password`;";
$queries[] = "ALTER TABLE `".PSM_DB_PREFIX."servers` ADD COLUMN `last_error_output` TEXT NULL AFTER `last_error`;";
$queries[] = "ALTER TABLE `".PSM_DB_PREFIX."servers` ADD COLUMN `last_output` TEXT NULL AFTER `last_error_output`;";
$queries[] = "ALTER TABLE `".PSM_DB_PREFIX."servers` ADD COLUMN `request_method` varchar(50) NULL AFTER `port`;";
$queries[] = "ALTER TABLE `".PSM_DB_PREFIX."servers` ADD COLUMN `allow_http_status` VARCHAR(255) NOT NULL DEFAULT '' AFTER `pattern_online`;";
$this->execSQL($queries);

View File

@ -37,6 +37,8 @@ use psm\Service\Database;
class StatusUpdater {
public $error = '';
public $header = '';
public $rtime = 0;
public $status_new = false;
@ -69,6 +71,9 @@ class StatusUpdater {
*
* Please note: if the server is down but has not met the warning threshold, this will return true
* to avoid any "we are down" events.
*
* @todo Get last_output when there is a HPPT 50x error.
*
* @param int $server_id
* @param int $max_runs how many times should the script recheck the server if unavailable. default is 2
* @return boolean TRUE if server is up, FALSE otherwise
@ -76,6 +81,7 @@ class StatusUpdater {
public function update($server_id, $max_runs = 2) {
$this->server_id = $server_id;
$this->error = '';
$this->header = '';
$this->rtime = '';
// get server info from db
@ -105,8 +111,11 @@ class StatusUpdater {
$save = array(
'last_check' => date('Y-m-d H:i:s'),
'error' => $this->error,
'rtime' => $this->rtime,
'rtime' => $this->rtime
);
if(!empty($this->error)){
$save['last_error'] = $this->error;
}
// log the uptime before checking the warning threshold,
// so that the warnings can still be reviewed in the server history.
@ -116,6 +125,7 @@ class StatusUpdater {
// if the server is on, add the last_online value and reset the error threshold counter
$save['status'] = 'on';
$save['last_online'] = date('Y-m-d H:i:s');
$save['last_output'] = $this->header;
$save['warning_threshold_counter'] = 0;
if ($this->server['status'] == 'off') {
$online_date = new \DateTime($save['last_online']);
@ -124,8 +134,10 @@ class StatusUpdater {
$save['last_offline_duration'] = trim(psm_format_interval($difference));
}
} else {
// server is offline, increase the error counter
// server is offline, increase the error counter and set last offline
$save['warning_threshold_counter'] = $this->server['warning_threshold_counter'] + 1;
$save['last_offline'] = date('Y-m-d H:i:s');
$save['last_error_output'] = empty($this->header) ? "Could not get headers. probably HTTP 50x error." : $this->header;
if ($save['warning_threshold_counter'] < $this->server['warning_threshold']) {
// the server is offline but the error threshold has not been met yet.
@ -232,6 +244,7 @@ class StatusUpdater {
psm_password_decrypt($this->server['server_id'].psm_get_conf('password_encrypt_key'), $this->server['website_password']),
$this->server['request_method']
);
$this->header = $curl_result;
$this->rtime = (microtime(true) - $starttime);

View File

@ -93,6 +93,22 @@
{% endif %}
</td>
</tr>
<tr>
<td id="advanced">{{ label_advanced }}&nbsp;<i class="icon-expand-arrow"></i></td>
<td>&nbsp;</td>
</tr>
<tr class="advanced">
<td>{{ label_last_error }}:</td>
<td>{{ last_error }}</td>
</tr>
<tr class="advanced">
<td>{{ label_last_output }}:</td>
<td>{{ last_output }}</td>
</tr>
<tr class="advanced">
<td>{{ label_last_error_output }}:</td>
<td>{{ last_error_output }}</td>
</tr>
{% if has_admin_actions %}
<tr>
<td class="hidden-small">&nbsp;</td>

View File

@ -676,3 +676,6 @@ legend{
.icon-telegram {
background-position: -96px -168px;
}
.icon-expand-arrow {
background-position: -312px -120px;
}