diff --git a/src/includes/functions.inc.php b/src/includes/functions.inc.php
index 9d267637..b810dd9e 100644
--- a/src/includes/functions.inc.php
+++ b/src/includes/functions.inc.php
@@ -236,6 +236,25 @@ function psm_log_uptime($server_id, $status, $latency) {
);
}
+/**
+ * Converts an interval into a string
+ *
+ * @param DateInterval $interval
+ * @return string
+ */
+ function psm_format_interval(DateInterval $interval) {
+ $result = "";
+
+ if ($interval->y) { $result .= $interval->format("%y ") . ( ($interval->y == 1) ? psm_get_lang('system', 'year') : psm_get_lang('system', 'years') ) . " "; }
+ if ($interval->m) { $result .= $interval->format("%m ") . ( ($interval->m == 1) ? psm_get_lang('system', 'month') : psm_get_lang('system', 'months') ) . " "; }
+ if ($interval->d) { $result .= $interval->format("%d ") . ( ($interval->d == 1) ? psm_get_lang('system', 'day') : psm_get_lang('system', 'days') ) . " "; }
+ if ($interval->h) { $result .= $interval->format("%h ") . ( ($interval->h == 1) ? psm_get_lang('system', 'hour') : psm_get_lang('system', 'hours') ) . " "; }
+ if ($interval->i) { $result .= $interval->format("%i ") . ( ($interval->i == 1) ? psm_get_lang('system', 'minute') : psm_get_lang('system', 'minutes') ) . " "; }
+ if ($interval->s) { $result .= $interval->format("%s ") . ( ($interval->s == 1) ? psm_get_lang('system', 'second') : psm_get_lang('system', 'seconds') ) . " "; }
+
+ return $result;
+}
+
/**
* Parses a string from the language file with the correct variables replaced in the message
*
@@ -254,6 +273,11 @@ function psm_parse_msg($status, $type, $vars) {
}
$vars['date'] = date('Y-m-d H:i:s');
+ $online_date = new DateTime($vars['last_online']);
+ $offline_date = new DateTime($vars['last_offline']);
+ $difference = $online_date->diff($offline_date);
+ $vars['downtime'] = psm_format_interval($difference);
+
foreach($vars as $k => $v) {
$message = str_replace('%' . strtoupper($k) . '%', $v, $message);
}
diff --git a/src/lang/bg_BG.lang.php b/src/lang/bg_BG.lang.php
index e9a2469f..27477d2b 100644
--- a/src/lang/bg_BG.lang.php
+++ b/src/lang/bg_BG.lang.php
@@ -58,6 +58,18 @@ $sm_lang = array(
'a_minute_ago' => 'преди минута',
'seconds_ago' => 'преди %d секунди',
'a_second_ago' => 'преди секунда',
+ 'year' => 'year',
+ 'years' => 'years',
+ 'month' => 'month',
+ 'months' => 'months',
+ 'day' => 'day',
+ 'days' => 'days',
+ 'hour' => 'hour',
+ 'hours' => 'hours',
+ 'minute' => 'minute',
+ 'minutes' => 'minutes',
+ 'second' => 'second',
+ 'seconds' => 'seconds',
),
'menu' => array(
'config' => 'Настройки',
diff --git a/src/lang/cs_CZ.lang.php b/src/lang/cs_CZ.lang.php
index 8222f150..6d3cae5c 100644
--- a/src/lang/cs_CZ.lang.php
+++ b/src/lang/cs_CZ.lang.php
@@ -58,6 +58,18 @@ $sm_lang = array(
'a_minute_ago' => 'cca před minutou',
'seconds_ago' => 'před %d vteřinami',
'a_second_ago' => 'před chvílí',
+ 'year' => 'year',
+ 'years' => 'years',
+ 'month' => 'month',
+ 'months' => 'months',
+ 'day' => 'day',
+ 'days' => 'days',
+ 'hour' => 'hour',
+ 'hours' => 'hours',
+ 'minute' => 'minute',
+ 'minutes' => 'minutes',
+ 'second' => 'second',
+ 'seconds' => 'seconds',
),
'menu' => array(
'config' => 'Konfigurace',
diff --git a/src/lang/da_DK.lang.php b/src/lang/da_DK.lang.php
index 5dd633b7..084cc573 100644
--- a/src/lang/da_DK.lang.php
+++ b/src/lang/da_DK.lang.php
@@ -58,6 +58,18 @@ $sm_lang = array(
'a_minute_ago' => 'omkring et minut siden',
'seconds_ago' => '%d sekunder siden',
'a_second_ago' => 'et sekund siden',
+ 'year' => 'year',
+ 'years' => 'years',
+ 'month' => 'month',
+ 'months' => 'months',
+ 'day' => 'day',
+ 'days' => 'days',
+ 'hour' => 'hour',
+ 'hours' => 'hours',
+ 'minute' => 'minute',
+ 'minutes' => 'minutes',
+ 'second' => 'second',
+ 'seconds' => 'seconds',
),
'menu' => array(
'config' => 'Indstillinger',
diff --git a/src/lang/de_DE.lang.php b/src/lang/de_DE.lang.php
index 0d5ba6b3..09c698d9 100644
--- a/src/lang/de_DE.lang.php
+++ b/src/lang/de_DE.lang.php
@@ -58,6 +58,18 @@ $sm_lang = array(
'a_minute_ago' => 'vor über einer Minute',
'seconds_ago' => 'vor %d Sekunden',
'a_second_ago' => 'vor über einer Sekunde',
+ 'year' => 'year',
+ 'years' => 'years',
+ 'month' => 'month',
+ 'months' => 'months',
+ 'day' => 'day',
+ 'days' => 'days',
+ 'hour' => 'hour',
+ 'hours' => 'hours',
+ 'minute' => 'minute',
+ 'minutes' => 'minutes',
+ 'second' => 'second',
+ 'seconds' => 'seconds',
),
'menu' => array(
'config' => 'Einstellungen',
diff --git a/src/lang/en_US.lang.php b/src/lang/en_US.lang.php
index 9c47eca6..ee9b2eb5 100644
--- a/src/lang/en_US.lang.php
+++ b/src/lang/en_US.lang.php
@@ -58,6 +58,18 @@ $sm_lang = array(
'a_minute_ago' => 'about a minute ago',
'seconds_ago' => '%d seconds ago',
'a_second_ago' => 'a second ago',
+ 'year' => 'year',
+ 'years' => 'years',
+ 'month' => 'month',
+ 'months' => 'months',
+ 'day' => 'day',
+ 'days' => 'days',
+ 'hour' => 'hour',
+ 'hours' => 'hours',
+ 'minute' => 'minute',
+ 'minutes' => 'minutes',
+ 'second' => 'second',
+ 'seconds' => 'seconds',
),
'menu' => array(
'config' => 'Config',
@@ -263,9 +275,9 @@ $sm_lang = array(
'off_pushover_message' => "Failed to connect to the following server:
Server: %LABEL%
IP: %IP%
Port: %PORT%
Error: %ERROR%
Date: %DATE%",
'on_sms' => 'Server \'%LABEL%\' is RUNNING: ip=%IP%, port=%PORT%',
'on_email_subject' => 'IMPORTANT: Server \'%LABEL%\' is RUNNING',
- 'on_email_body' => "Server '%LABEL%' is running again:
Server: %LABEL%
IP: %IP%
Port: %PORT%
Date: %DATE%",
+ 'on_email_body' => "Server '%LABEL%' is running again, it was down for %DOWNTIME%:
Server: %LABEL%
IP: %IP%
Port: %PORT%
Date: %DATE%",
'on_pushover_title' => 'Server \'%LABEL%\' is RUNNING',
- 'on_pushover_message' => 'Server \'%LABEL%\' is running again:
Server: %LABEL%
IP: %IP%
Port: %PORT%
Date: %DATE%',
+ 'on_pushover_message' => 'Server \'%LABEL%\' is running again, it was down for %DOWNTIME%:
Server: %LABEL%
IP: %IP%
Port: %PORT%
Date: %DATE%',
),
'login' => array(
'welcome_usermenu' => 'Welcome, %user_name%',
diff --git a/src/lang/es_ES.lang.php b/src/lang/es_ES.lang.php
index a2691d0b..f215f808 100644
--- a/src/lang/es_ES.lang.php
+++ b/src/lang/es_ES.lang.php
@@ -59,6 +59,18 @@ $sm_lang = array(
'a_minute_ago' => 'Hace aproximadamente un minuto',
'seconds_ago' => 'Hace %d segundos',
'a_second_ago' => 'Hace aproximadamente un segundo',
+ 'year' => 'year',
+ 'years' => 'years',
+ 'month' => 'month',
+ 'months' => 'months',
+ 'day' => 'day',
+ 'days' => 'days',
+ 'hour' => 'hour',
+ 'hours' => 'hours',
+ 'minute' => 'minute',
+ 'minutes' => 'minutes',
+ 'second' => 'second',
+ 'seconds' => 'seconds',
),
'menu' => array(
'config' => 'Configurar',
diff --git a/src/lang/fr_FR.lang.php b/src/lang/fr_FR.lang.php
index dbe24135..5aa0d917 100644
--- a/src/lang/fr_FR.lang.php
+++ b/src/lang/fr_FR.lang.php
@@ -59,6 +59,18 @@ $sm_lang = array(
'a_minute_ago' => 'Il y a une minute',
'seconds_ago' => 'Il y a %d secondes',
'a_second_ago' => 'Il y a une seconde',
+ 'year' => 'year',
+ 'years' => 'years',
+ 'month' => 'month',
+ 'months' => 'months',
+ 'day' => 'day',
+ 'days' => 'days',
+ 'hour' => 'hour',
+ 'hours' => 'hours',
+ 'minute' => 'minute',
+ 'minutes' => 'minutes',
+ 'second' => 'second',
+ 'seconds' => 'seconds',
),
'menu' => array(
'config' => 'Configuration',
diff --git a/src/lang/it_IT.lang.php b/src/lang/it_IT.lang.php
index 86da1063..8da1717d 100644
--- a/src/lang/it_IT.lang.php
+++ b/src/lang/it_IT.lang.php
@@ -58,6 +58,18 @@ $sm_lang = array(
'a_minute_ago' => 'about a minute ago',
'seconds_ago' => '%d seconds ago',
'a_second_ago' => 'a second ago',
+ 'year' => 'year',
+ 'years' => 'years',
+ 'month' => 'month',
+ 'months' => 'months',
+ 'day' => 'day',
+ 'days' => 'days',
+ 'hour' => 'hour',
+ 'hours' => 'hours',
+ 'minute' => 'minute',
+ 'minutes' => 'minutes',
+ 'second' => 'second',
+ 'seconds' => 'seconds',
),
'menu' => array(
'config' => 'Configurazione',
diff --git a/src/lang/ko_KR.lang.php b/src/lang/ko_KR.lang.php
index cda96b74..bce462e1 100644
--- a/src/lang/ko_KR.lang.php
+++ b/src/lang/ko_KR.lang.php
@@ -58,6 +58,18 @@ $sm_lang = array(
'a_minute_ago' => 'about a minute ago',
'seconds_ago' => '%d seconds ago',
'a_second_ago' => 'a second ago',
+ 'year' => 'year',
+ 'years' => 'years',
+ 'month' => 'month',
+ 'months' => 'months',
+ 'day' => 'day',
+ 'days' => 'days',
+ 'hour' => 'hour',
+ 'hours' => 'hours',
+ 'minute' => 'minute',
+ 'minutes' => 'minutes',
+ 'second' => 'second',
+ 'seconds' => 'seconds',
),
'menu' => array(
'config' => '설정',
diff --git a/src/lang/nl_NL.lang.php b/src/lang/nl_NL.lang.php
index 8a273710..eb60b708 100644
--- a/src/lang/nl_NL.lang.php
+++ b/src/lang/nl_NL.lang.php
@@ -58,6 +58,18 @@ $sm_lang = array(
'a_minute_ago' => 'een minuut geleden',
'seconds_ago' => '%d seconden geleden',
'a_second_ago' => 'een seconde geleden',
+ 'year' => 'year',
+ 'years' => 'years',
+ 'month' => 'month',
+ 'months' => 'months',
+ 'day' => 'day',
+ 'days' => 'days',
+ 'hour' => 'hour',
+ 'hours' => 'hours',
+ 'minute' => 'minute',
+ 'minutes' => 'minutes',
+ 'second' => 'second',
+ 'seconds' => 'seconds',
),
'menu' => array(
'config' => 'Configuratie',
diff --git a/src/lang/pl_PL.lang.php b/src/lang/pl_PL.lang.php
index 0e2cf5f1..d0e047b6 100644
--- a/src/lang/pl_PL.lang.php
+++ b/src/lang/pl_PL.lang.php
@@ -58,6 +58,18 @@ $sm_lang = array(
'a_minute_ago' => 'minutę temu',
'seconds_ago' => '%d sekund temu',
'a_second_ago' => 'sekundę temu',
+ 'year' => 'year',
+ 'years' => 'years',
+ 'month' => 'month',
+ 'months' => 'months',
+ 'day' => 'day',
+ 'days' => 'days',
+ 'hour' => 'hour',
+ 'hours' => 'hours',
+ 'minute' => 'minute',
+ 'minutes' => 'minutes',
+ 'second' => 'second',
+ 'seconds' => 'seconds',
),
'menu' => array(
'config' => 'Konfiguracja',
diff --git a/src/lang/pt_BR.lang.php b/src/lang/pt_BR.lang.php
index bc80a053..cf0fae6e 100644
--- a/src/lang/pt_BR.lang.php
+++ b/src/lang/pt_BR.lang.php
@@ -58,6 +58,18 @@ $sm_lang = array(
'a_minute_ago' => 'cerca de um minuto atrás',
'seconds_ago' => '%d segundos atrás',
'a_second_ago' => 'um segundo atrás',
+ 'year' => 'year',
+ 'years' => 'years',
+ 'month' => 'month',
+ 'months' => 'months',
+ 'day' => 'day',
+ 'days' => 'days',
+ 'hour' => 'hour',
+ 'hours' => 'hours',
+ 'minute' => 'minute',
+ 'minutes' => 'minutes',
+ 'second' => 'second',
+ 'seconds' => 'seconds',
),
'menu' => array(
'config' => 'Configuração',
diff --git a/src/lang/ru_RU.lang.php b/src/lang/ru_RU.lang.php
index d9d1603f..dc5aa7d1 100644
--- a/src/lang/ru_RU.lang.php
+++ b/src/lang/ru_RU.lang.php
@@ -58,6 +58,18 @@ $sm_lang = array(
'a_minute_ago' => 'минуту назад',
'seconds_ago' => '%d секунд назад',
'a_second_ago' => 'секунду назад',
+ 'year' => 'year',
+ 'years' => 'years',
+ 'month' => 'month',
+ 'months' => 'months',
+ 'day' => 'day',
+ 'days' => 'days',
+ 'hour' => 'hour',
+ 'hours' => 'hours',
+ 'minute' => 'minute',
+ 'minutes' => 'minutes',
+ 'second' => 'second',
+ 'seconds' => 'seconds',
),
'menu' => array(
'config' => 'Параметры',
diff --git a/src/lang/tr_TR.lang.php b/src/lang/tr_TR.lang.php
index c16a78e7..75ed4a70 100644
--- a/src/lang/tr_TR.lang.php
+++ b/src/lang/tr_TR.lang.php
@@ -58,6 +58,18 @@ $sm_lang = array(
'a_minute_ago' => 'yaklaşık bir dakika önce',
'seconds_ago' => '%d saniye önce',
'a_second_ago' => 'bir saniye önce',
+ 'year' => 'year',
+ 'years' => 'years',
+ 'month' => 'month',
+ 'months' => 'months',
+ 'day' => 'day',
+ 'days' => 'days',
+ 'hour' => 'hour',
+ 'hours' => 'hours',
+ 'minute' => 'minute',
+ 'minutes' => 'minutes',
+ 'second' => 'second',
+ 'seconds' => 'seconds',
),
'menu' => array(
'config' => 'Ayarlar',
diff --git a/src/lang/zh_CN.lang.php b/src/lang/zh_CN.lang.php
index 81703b3a..ad85261d 100644
--- a/src/lang/zh_CN.lang.php
+++ b/src/lang/zh_CN.lang.php
@@ -58,6 +58,18 @@ $sm_lang = array(
'a_minute_ago' => '1分钟前',
'seconds_ago' => '%d 秒前',
'a_second_ago' => '刚刚',
+ 'year' => 'year',
+ 'years' => 'years',
+ 'month' => 'month',
+ 'months' => 'months',
+ 'day' => 'day',
+ 'days' => 'days',
+ 'hour' => 'hour',
+ 'hours' => 'hours',
+ 'minute' => 'minute',
+ 'minutes' => 'minutes',
+ 'second' => 'second',
+ 'seconds' => 'seconds',
),
'menu' => array(
'config' => '设置',
diff --git a/src/psm/Util/Install/Installer.class.php b/src/psm/Util/Install/Installer.class.php
index 30e3ad25..8760a819 100644
--- a/src/psm/Util/Install/Installer.class.php
+++ b/src/psm/Util/Install/Installer.class.php
@@ -126,7 +126,7 @@ class Installer {
$this->log('Populating database...');
$queries = array();
- $queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "servers` (`ip`, `port`, `label`, `type`, `pattern`, `status`, `error`, `rtime`, `last_online`, `last_check`, `active`, `email`, `sms`, `pushover`) VALUES ('http://sourceforge.net/index.php', 80, 'SourceForge', 'website', '', 'on', '', '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', 'yes', 'yes', 'yes', 'yes'), ('smtp.gmail.com', 465, 'Gmail SMTP', 'service', '', 'on', '', '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', 'yes', 'yes', 'yes', 'yes')";
+ $queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "servers` (`ip`, `port`, `label`, `type`, `pattern`, `status`, `error`, `rtime`, `last_online`, `last_check`, `active`, `email`, `sms`, `pushover`, `last_offline`) VALUES ('http://sourceforge.net/index.php', 80, 'SourceForge', 'website', '', 'on', '', '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', 'yes', 'yes', 'yes', 'yes', '0000-00-00 00:00:00'), ('smtp.gmail.com', 465, 'Gmail SMTP', 'service', '', 'on', '', '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', 'yes', 'yes', 'yes', 'yes', '0000-00-00 00:00:00')";
$queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "users_servers` (`user_id`,`server_id`) VALUES (1, 1), (1, 2);";
$queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "config` (`key`, `value`) VALUE
('language', 'en_US'),
@@ -226,6 +226,7 @@ class Installer {
`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,
+ `last_offline` datetime 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` (
@@ -301,6 +302,7 @@ 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 AFTER `timeout`;";
$this->execSQL($queries);
}
@@ -332,6 +334,7 @@ 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 AFTER `timeout`;";
$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`
@@ -411,6 +414,7 @@ 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 AFTER `timeout`;";
$queries[] = "CREATE TABLE IF NOT EXISTS `" . PSM_DB_PREFIX . "users_preferences` (
`user_id` int(11) unsigned NOT NULL,
diff --git a/src/psm/Util/Server/Updater/StatusNotifier.class.php b/src/psm/Util/Server/Updater/StatusNotifier.class.php
index 154b4c3e..5b699e42 100644
--- a/src/psm/Util/Server/Updater/StatusNotifier.class.php
+++ b/src/psm/Util/Server/Updater/StatusNotifier.class.php
@@ -121,7 +121,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', 'error', 'active', 'email', 'sms', 'pushover',
+ 'server_id', 'ip', 'port', 'label', 'type', 'pattern', 'status', 'error', 'active', 'email', 'sms', 'pushover', 'last_online', 'last_offline',
));
if(empty($this->server)) {
return false;
@@ -315,4 +315,4 @@ class StatusNotifier {
");
return $users;
}
-}
\ No newline at end of file
+}
diff --git a/src/psm/Util/Server/Updater/StatusUpdater.class.php b/src/psm/Util/Server/Updater/StatusUpdater.class.php
index acd7bd9e..46c1ba89 100644
--- a/src/psm/Util/Server/Updater/StatusUpdater.class.php
+++ b/src/psm/Util/Server/Updater/StatusUpdater.class.php
@@ -82,7 +82,7 @@ class StatusUpdater {
$this->server = $this->db->selectRow(PSM_DB_PREFIX . 'servers', array(
'server_id' => $server_id,
), array(
- 'server_id', 'ip', 'port', 'label', 'type', 'pattern', 'status', 'active', 'warning_threshold', 'warning_threshold_counter', 'timeout',
+ 'server_id', 'ip', 'port', 'label', 'type', 'pattern', 'status', 'active', 'warning_threshold', 'warning_threshold_counter', 'timeout', 'last_online',
));
if(empty($this->server)) {
return false;
@@ -113,6 +113,9 @@ 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') {
+ $save['last_offline'] = $this->server['last_online'];
+ }
} else {
// server is offline, increase the error counter
$save['warning_threshold_counter'] = $this->server['warning_threshold_counter'] + 1;