Request: '. $this->request . ''; + error_log("Request: $this->request\r\nResponse: $cResponse", E_USER_NOTICE); + echo $debug; + } + + return $this->result; + } +} diff --git a/src/psm/Util/Install/Installer.php b/src/psm/Util/Install/Installer.php index 1d592b50..c01e208e 100644 --- a/src/psm/Util/Install/Installer.php +++ b/src/psm/Util/Install/Installer.php @@ -235,16 +235,18 @@ class Installer { `error` varchar(255) NULL, `rtime` FLOAT(9, 7) NULL, `last_online` datetime NULL, + `last_offline` datetime NULL, + `last_offline_duration` varchar(255) NULL, `last_check` datetime NULL, `active` enum('yes','no') NOT NULL default 'yes', `email` enum('yes','no') NOT NULL default 'yes', `sms` enum('yes','no') NOT NULL default 'no', `pushover` enum('yes','no') NOT NULL default 'yes', - `telegram` enum('yes','no') NOT NULL default 'yes', - `warning_threshold` mediumint(1) unsigned NOT NULL DEFAULT '1', - `warning_threshold_counter` mediumint(1) unsigned NOT NULL DEFAULT '0', - `timeout` smallint(1) unsigned NULL DEFAULT NULL, - `website_username` varchar(255) DEFAULT NULL, + `telegram` enum('yes','no') NOT NULL default 'yes', + `warning_threshold` mediumint(1) unsigned NOT NULL DEFAULT '1', + `warning_threshold_counter` mediumint(1) unsigned NOT NULL DEFAULT '0', + `timeout` smallint(1) unsigned NULL DEFAULT NULL, + `website_username` varchar(255) DEFAULT NULL, `website_password` varchar(255) DEFAULT NULL, PRIMARY KEY (`server_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;", @@ -330,6 +332,8 @@ class Installer { $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` CHANGE `last_online` `last_online` DATETIME NULL;"; $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` CHANGE `last_check` `last_check` DATETIME NULL;"; $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` ADD `pattern` VARCHAR( 255 ) NOT NULL AFTER `type`;"; + $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` ADD `last_offline` DATETIME NULL;"; + $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` ADD `last_offline_duration` varchar(255) NULL;"; $this->execSQL($queries); } @@ -361,6 +365,8 @@ class Installer { $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` CHANGE `server_id` `server_id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT;"; $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` ADD `warning_threshold` MEDIUMINT( 1 ) UNSIGNED NOT NULL DEFAULT '1';"; $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` ADD `warning_threshold_counter` MEDIUMINT( 1 ) UNSIGNED NOT NULL DEFAULT '0';"; + $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` ADD `last_offline` DATETIME NULL;"; + $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` ADD `last_offline_duration` varchar(255) NULL;"; $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "users` CHANGE `user_id` `user_id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT;"; $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "users` @@ -443,6 +449,8 @@ class Installer { $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "log` CHANGE `type` `type` ENUM( 'status', 'email', 'sms', 'pushover' ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;"; $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` ADD `timeout` smallint(1) unsigned NULL DEFAULT NULL;"; + $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` ADD `last_offline` DATETIME NULL;"; + $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` ADD `last_offline_duration` varchar(255) NULL;"; $queries[] = "CREATE TABLE IF NOT EXISTS `" . PSM_DB_PREFIX . "users_preferences` ( `user_id` int(11) unsigned NOT NULL, @@ -525,6 +533,7 @@ class Installer { */ protected function upgrade330() { $queries = array(); + $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` ADD COLUMN `last_offline` DATETIME NULL AFTER `last_online`, ADD COLUMN `last_offline_duration` varchar(255) NULL AFTER `last_offline`;"; $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` ADD `pattern_online` TINYINT( 1 ) unsigned NOT NULL AFTER `pattern`;"; $this->execSQL($queries); } diff --git a/src/psm/Util/Server/Updater/StatusNotifier.php b/src/psm/Util/Server/Updater/StatusNotifier.php index aa5adf3d..33fe8129 100644 --- a/src/psm/Util/Server/Updater/StatusNotifier.php +++ b/src/psm/Util/Server/Updater/StatusNotifier.php @@ -128,7 +128,7 @@ class StatusNotifier { $this->server = $this->db->selectRow(PSM_DB_PREFIX . 'servers', array( 'server_id' => $server_id, ), array( - 'server_id', 'ip', 'port', 'label', 'type', 'pattern', 'status', 'header_name', 'header_value', 'error', 'active', 'email', 'sms', 'pushover', 'telegram', + 'server_id', 'ip', 'port', 'label', 'type', 'pattern', 'status', 'header_name', 'header_value', 'error', 'active', 'email', 'sms', 'pushover', 'telegram', 'last_online', 'last_offline', 'last_offline_duration', )); if(empty($this->server)) { return false; diff --git a/src/psm/Util/Server/Updater/StatusUpdater.php b/src/psm/Util/Server/Updater/StatusUpdater.php index 74ea9af7..48a162a1 100644 --- a/src/psm/Util/Server/Updater/StatusUpdater.php +++ b/src/psm/Util/Server/Updater/StatusUpdater.php @@ -83,7 +83,7 @@ class StatusUpdater { 'server_id' => $server_id, ), array( 'server_id', 'ip', 'port', 'label', 'type', 'pattern', 'pattern_online', 'header_name', 'header_value', 'status', 'active', 'warning_threshold', - 'warning_threshold_counter', 'timeout', 'website_username', 'website_password' + 'warning_threshold_counter', 'timeout', 'website_username', 'website_password', 'last_offline' )); if(empty($this->server)) { return false; @@ -117,6 +117,12 @@ class StatusUpdater { $save['status'] = 'on'; $save['last_online'] = date('Y-m-d H:i:s'); $save['warning_threshold_counter'] = 0; + if ($this->server['status'] == 'off') { + $online_date = new \DateTime($save['last_online']); + $offline_date = new \DateTime($this->server['last_offline']); + $difference = $online_date->diff($offline_date); + $save['last_offline_duration'] = trim(psm_format_interval($difference)); + } } else { // server is offline, increase the error counter $save['warning_threshold_counter'] = $this->server['warning_threshold_counter'] + 1; @@ -128,6 +134,9 @@ class StatusUpdater { $this->status_new = true; } else { $save['status'] = 'off'; + if ($this->server['status'] == 'on') { + $save['last_offline'] = $save['last_check']; + } } } @@ -150,16 +159,19 @@ class StatusUpdater { // set ping payload $package = "\x08\x00\x7d\x4b\x00\x00\x00\x00PingHost"; - $fp = @fsockopen ($this->server['ip'], $this->server['port'], $errno, $this->error, 10); $socket = socket_create(AF_INET, SOCK_RAW, 1); socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => 10, 'usec' => 0)); socket_connect($socket, $this->server['ip'], null); - + socket_send($socket, $package, strLen($package), 0); if (socket_read($socket, 255)) { $status = true; } else { $status = false; + + // set error message + $errorcode = socket_last_error(); + $this->error = "Couldn't create socket [".$errorcode."]: ".socket_strerror($errorcode); } $this->rtime = microtime(true) - $starttime; socket_close($socket); @@ -245,7 +257,7 @@ class StatusUpdater { $result = false; } else { $result = true; - + //Okay, the HTTP status is good : 2xx or 3xx. Now we have to test the pattern if it's set up if($this->server['pattern'] != '') { // Check to see if the body should not contain specified pattern diff --git a/src/templates/default/module/install/config_upgrade.tpl.html b/src/templates/default/module/install/config_upgrade.tpl.html index 29803658..f67382d1 100644 --- a/src/templates/default/module/install/config_upgrade.tpl.html +++ b/src/templates/default/module/install/config_upgrade.tpl.html @@ -3,7 +3,6 @@ {% block install %}
Response: ' . $cResponse.'
We have discovered a previous version.
In the next step we will upgrade your database to the latest version.
-{{ block('results') }}-{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/src/templates/default/module/server/server/list.tpl.html b/src/templates/default/module/server/server/list.tpl.html index ed5d7ae3..9ab2ec66 100644 --- a/src/templates/default/module/server/server/list.tpl.html +++ b/src/templates/default/module/server/server/list.tpl.html @@ -8,6 +8,7 @@
{{ label_last_online }}: {{ server.last_online_nice }}
+{{ label_last_offline }}: {{ server.last_offline_nice }} {{ server.last_offline_duration_nice }}
{{ label_rtime }}: {{ server.rtime }}s