diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 64692cb5..c8cc710a 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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. diff --git a/src/lang/en_US.lang.php b/src/lang/en_US.lang.php index f9f76f83..dff43c83 100644 --- a/src/lang/en_US.lang.php +++ b/src/lang/en_US.lang.php @@ -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', diff --git a/src/psm/Module/Server/Controller/AbstractServerController.php b/src/psm/Module/Server/Controller/AbstractServerController.php index 0e6b8fe8..dab57c25 100644 --- a/src/psm/Module/Server/Controller/AbstractServerController.php +++ b/src/psm/Module/Server/Controller/AbstractServerController.php @@ -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( diff --git a/src/psm/Module/Server/Controller/ServerController.php b/src/psm/Module/Server/Controller/ServerController.php index 193ba20c..46d1f371 100644 --- a/src/psm/Module/Server/Controller/ServerController.php +++ b/src/psm/Module/Server/Controller/ServerController.php @@ -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; } } - diff --git a/src/psm/Util/Install/Installer.php b/src/psm/Util/Install/Installer.php index 5cfe126a..2ad74fe9 100644 --- a/src/psm/Util/Install/Installer.php +++ b/src/psm/Util/Install/Installer.php @@ -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); diff --git a/src/psm/Util/Server/Updater/StatusUpdater.php b/src/psm/Util/Server/Updater/StatusUpdater.php index 8f9dcbb8..a55a4978 100644 --- a/src/psm/Util/Server/Updater/StatusUpdater.php +++ b/src/psm/Util/Server/Updater/StatusUpdater.php @@ -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); diff --git a/src/templates/default/module/server/server/view.tpl.html b/src/templates/default/module/server/server/view.tpl.html index af5224ea..2aeee9b2 100644 --- a/src/templates/default/module/server/server/view.tpl.html +++ b/src/templates/default/module/server/server/view.tpl.html @@ -93,6 +93,22 @@ {% endif %} + + {{ label_advanced }}  +   + + + {{ label_last_error }}: + {{ last_error }} + + + {{ label_last_output }}: + {{ last_output }} + + + {{ label_last_error_output }}: + {{ last_error_output }} + {% if has_admin_actions %}   diff --git a/static/css/style.css b/static/css/style.css index ece2d6fb..89f618b6 100755 --- a/static/css/style.css +++ b/static/css/style.css @@ -676,3 +676,6 @@ legend{ .icon-telegram { background-position: -96px -168px; } +.icon-expand-arrow { + background-position: -312px -120px; +}