Fix for Textmarketer and adds a new entry in the servers db table for the last time it was offline (last_offline) to allow the duration of the outage to be included in the notification, also exposed last_online and last_offline so that they can also be used in the notifications should the user wish.

pull/182/head
Matthew Pattman 2015-02-27 13:44:13 +00:00
parent 9370397555
commit 62633f6937
27 changed files with 281 additions and 65 deletions

View File

@ -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
*

View File

@ -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' => 'Настройки',
@ -127,6 +139,7 @@ $sm_lang = array(
'pattern_description' => 'Ако този текст не е намерен в интернет страницата (когато имате добавен сайт), той ще бъде маркиран като Офлайн. Регулярните изрази са разрешени.',
'last_check' => 'Последна проверка',
'last_online' => 'Последно на линия',
'last_offline' => 'Last offline',
'monitoring' => 'Мониторинг',
'no_monitoring' => 'Не се наблюдава',
'email' => 'Имейл',

View File

@ -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',
@ -127,6 +139,7 @@ $sm_lang = array(
'pattern_description' => 'Pokud vzorek nebude na webu nalezen, bude server označen jako offline. Regulární výrazy jsou povoleny.',
'last_check' => 'Poslední kontrola',
'last_online' => 'Naposledy online',
'last_offline' => 'Naposledy offline',
'monitoring' => 'Monitoring',
'no_monitoring' => 'Žádné monitorované služby',
'email' => 'Email',

View File

@ -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',
@ -127,6 +139,7 @@ $sm_lang = array(
'pattern_description' => 'Hvis dette mønster ikke findes på hjemmesiden, vil serveren blive markeret offline. Regulære udtryk er tilladt.',
'last_check' => 'Sidst kontrolleret',
'last_online' => 'Sidst online',
'last_offline' => 'Sidst offline',
'monitoring' => 'Overvågning',
'no_monitoring' => 'Ingen overvågning',
'email' => 'Email',

View File

@ -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',
@ -127,6 +139,7 @@ $sm_lang = array(
'pattern_description' => 'Wenn das gesuchte Muster nicht in der Webseite ist, wird die Seite als offline markiert. Reguläre Ausdrücke sind erlaubt.',
'last_check' => 'Letzter Check',
'last_online' => 'Zuletzt online',
'last_offline' => 'Zuletzt offline',
'monitoring' => 'Monitoring',
'no_monitoring' => 'Monitoring inaktiv',
'email' => 'E-Mail',

View File

@ -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',
@ -127,6 +139,7 @@ $sm_lang = array(
'pattern_description' => 'If this pattern is not found on the website, the server will be marked offline. Regular expressions are allowed.',
'last_check' => 'Last check',
'last_online' => 'Last online',
'last_offline' => 'Last offline',
'monitoring' => 'Monitoring',
'no_monitoring' => 'No monitoring',
'email' => 'Email',
@ -264,11 +277,11 @@ $sm_lang = array(
'off_email_body' => "Failed to connect to the following server:<br/><br/>Server: %LABEL%<br/>IP: %IP%<br/>Port: %PORT%<br/>Error: %ERROR%<br/>Date: %DATE%",
'off_pushover_title' => 'Server \'%LABEL%\' is DOWN',
'off_pushover_message' => "Failed to connect to the following server:<br/><br/>Server: %LABEL%<br/>IP: %IP%<br/>Port: %PORT%<br/>Error: %ERROR%<br/>Date: %DATE%",
'on_sms' => 'Server \'%LABEL%\' is RUNNING: ip=%IP%, port=%PORT%',
'on_sms' => 'Server \'%LABEL%\' is RUNNING: ip=%IP%, port=%PORT%, it was down for %LAST_OFFLINE_DURATION%',
'on_email_subject' => 'IMPORTANT: Server \'%LABEL%\' is RUNNING',
'on_email_body' => "Server '%LABEL%' is running again:<br/><br/>Server: %LABEL%<br/>IP: %IP%<br/>Port: %PORT%<br/>Date: %DATE%",
'on_email_body' => "Server '%LABEL%' is running again, it was down for %LAST_OFFLINE_DURATION%:<br/><br/>Server: %LABEL%<br/>IP: %IP%<br/>Port: %PORT%<br/>Date: %DATE%",
'on_pushover_title' => 'Server \'%LABEL%\' is RUNNING',
'on_pushover_message' => 'Server \'%LABEL%\' is running again:<br/><br/>Server: %LABEL%<br/>IP: %IP%<br/>Port: %PORT%<br/>Date: %DATE%',
'on_pushover_message' => 'Server \'%LABEL%\' is running again, it was down for %LAST_OFFLINE_DURATION%:<br/><br/>Server: %LABEL%<br/>IP: %IP%<br/>Port: %PORT%<br/>Date: %DATE%',
),
'login' => array(
'welcome_usermenu' => 'Welcome, %user_name%',

View File

@ -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',
@ -128,6 +140,7 @@ $sm_lang = array(
'pattern_description' => 'Si este patrón no se encuentra en el sitio web, el servidor estará marcada sin conexión. Se permiten expresiones regulares.',
'last_check' => 'Ultima verificación',
'last_online' => 'Última vez en línea',
'last_offline' => 'Last offline',
'monitoring' => 'Monitoreo',
'no_monitoring' => 'Sin monitoreo',
'email' => 'Email',

View File

@ -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',
@ -128,6 +140,7 @@ $sm_lang = array(
'pattern_description' => 'Si ce texte n\'est par retrouvé sur le site web, le serveur est marqué hors-service. Les expressions réguliaires sont autorisées.',
'last_check' => 'Dernière vérification',
'last_online' => 'Dernière fois OK',
'last_offline' => 'Last offline',
'monitoring' => 'Surveillé',
'no_monitoring' => 'Non surveillé',
'email' => 'Email',

View File

@ -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',
@ -127,6 +139,7 @@ $sm_lang = array(
'pattern_description' => 'If this pattern is not found on the website, the server will be marked offline. Regular expressions are allowed.',
'last_check' => 'Ultimo Controllo',
'last_online' => 'Ultima volta Online',
'last_offline' => 'Ultima volta offline',
'monitoring' => 'Sotto Controllo',
'no_monitoring' => 'No monitoring',
'email' => 'Email',

View File

@ -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' => '설정',
@ -127,6 +139,7 @@ $sm_lang = array(
'pattern_description' => 'If this pattern is not found on the website, the server will be marked offline. Regular expressions are allowed.',
'last_check' => '최근체크',
'last_online' => '최근접속',
'last_offline' => 'Last offline',
'monitoring' => '확인중',
'no_monitoring' => 'No monitoring',
'email' => '메일 전송',

View File

@ -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',
@ -127,6 +139,7 @@ $sm_lang = array(
'pattern_description' => 'Als dit patroon niet gevonden wordt op de website, zal de server als offline gemarkeerd worden. Regular expressions zijn toegestaan.',
'last_check' => 'Laatst gecontroleerd',
'last_online' => 'Laatst online',
'last_offline' => 'Laatst offline',
'monitoring' => 'Monitoring',
'no_monitoring' => 'No monitoring',
'email' => 'Email',

View File

@ -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',
@ -127,6 +139,7 @@ $sm_lang = array(
'pattern_description' => 'Jeśli wzorzec nie zostanie odnaleziony, status zostanie ustawiony na offline. Wyrażenia regularne są dozwolone.',
'last_check' => 'Ostatnie sprawdzenie',
'last_online' => 'Ostatnio online',
'last_offline' => 'Ostatnio offline',
'monitoring' => 'Monitorowany',
'no_monitoring' => 'Brak monitoringu',
'email' => 'Email',

View File

@ -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',
@ -127,6 +139,7 @@ $sm_lang = array(
'pattern_description' => 'Se esse padrão não for encontrado no site, o servidor será marcado offline. As expressões regulares são permitidas.',
'last_check' => 'Última verificação',
'last_online' => 'Última vez online',
'last_offline' => 'Última vez offline',
'monitoring' => 'Monitoramento',
'no_monitoring' => 'Sem monitoring',
'email' => 'Email',

View File

@ -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' => 'Параметры',
@ -127,6 +139,7 @@ $sm_lang = array(
'pattern_description' => 'Если текст по шаблону не найден на сайте, сервер будет помечен как Оффлайн. Регулярные выражения допустимы.',
'last_check' => 'Последняя проверка',
'last_online' => 'Был онлайн',
'last_offline' => 'Last offline',
'monitoring' => 'Мониторинг',
'no_monitoring' => 'Нет мониторинга',
'email' => 'E-mail',

View File

@ -58,6 +58,18 @@ $sm_lang = array(
'a_minute_ago' => 'ungefär en minut sen',
'seconds_ago' => '%d sekunder sedan',
'a_second_ago' => 'en sekund sedan',
'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' => 'Inställningar',
@ -127,6 +139,7 @@ $sm_lang = array(
'pattern_description' => 'Om detta mönster inte hittas i svaret kommer servern att markeras offline. "Regular expressions" är tillåtna.',
'last_check' => 'Senaste kontroll',
'last_online' => 'Senast online',
'last_offline' => 'Senast offline',
'monitoring' => 'Övervakas',
'no_monitoring' => 'Övervakas inte',
'email' => 'Email',

View File

@ -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',
@ -127,6 +139,7 @@ $sm_lang = array(
'pattern_description' => 'Bu pattern web sitenizde bulunamaz ise, sunucu offline olarak işaretlenecek. Regular expression\'a izin verilmiştir.',
'last_check' => 'Son kontrol',
'last_online' => 'Son çevrimiçi zamanı',
'last_offline' => 'Last offline',
'monitoring' => 'Monitoring',
'no_monitoring' => 'No monitoring',
'email' => 'E-posta',

View File

@ -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' => '设置',
@ -127,6 +139,7 @@ $sm_lang = array(
'pattern_description' => '如果在网站上未找到对应匹配内容, 则标记该网站为离线. 支持正则表达式.',
'last_check' => '最后检查',
'last_online' => '最后在线',
'last_offline' => 'Last offline',
'monitoring' => '监控中',
'no_monitoring' => 'No monitoring',
'email' => '邮件',

View File

@ -75,7 +75,9 @@ abstract class AbstractServerController extends AbstractController {
`s`.`pushover`,
`s`.`warning_threshold`,
`s`.`warning_threshold_counter`,
`s`.`timeout`
`s`.`timeout`,
`s`.`last_offline`,
`s`.`last_offline_duration`
FROM `".PSM_DB_PREFIX."servers` AS `s`
{$sql_join}
{$sql_where}
@ -97,6 +99,13 @@ abstract class AbstractServerController extends AbstractController {
protected function formatServer($server) {
$server['rtime'] = round((float) $server['rtime'], 4);
$server['last_online'] = psm_timespan($server['last_online']);
$server['last_offline'] = psm_timespan($server['last_offline']);
if ($server['last_offline'] != psm_get_lang('system', 'never')) {
$server['last_offline_duration'] = "(".$server['last_offline_duration'].")";
}
else {
$server['last_offline_duration'] = "";
}
$server['last_check'] = psm_timespan($server['last_check']);
$server['active'] = psm_get_lang('system', $server['active']);
$server['email'] = psm_get_lang('system', $server['email']);

View File

@ -399,6 +399,7 @@ class ServerController extends AbstractServerController {
'label_last_check' => psm_get_lang('servers', 'last_check'),
'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_monitoring' => psm_get_lang('servers', 'monitoring'),
'label_email' => psm_get_lang('servers', 'email'),
'label_send_email' => psm_get_lang('servers', 'send_email'),

View File

@ -54,6 +54,7 @@ class StatusController extends AbstractServerController {
$layout_data = array(
'label_last_check' => psm_get_lang('servers', 'last_check'),
'label_last_online' => psm_get_lang('servers', 'last_online'),
'label_last_offline' => psm_get_lang('servers', 'last_offline'),
'label_rtime' => psm_get_lang('servers', 'latency'),
'block_layout_active' => ($layout == 0) ? 'active' : '',
'list_layout_active' => ($layout != 0) ? 'active' : '',
@ -74,6 +75,11 @@ class StatusController extends AbstractServerController {
}
$server['last_checked_nice'] = psm_timespan($server['last_check']);
$server['last_online_nice'] = psm_timespan($server['last_online']);
$server['last_offline_nice'] = psm_timespan($server['last_offline']);
$server['last_offline_duration_nice'] = "";
if ($server['last_offline_nice'] != psm_get_lang('system', 'never')) {
$server['last_offline_duration_nice'] = "(".$server['last_offline_duration'].")";
}
$server['url_view'] = psm_build_url(array('mod' => 'server', 'action' => 'view', 'id' => $server['server_id'], 'back_to' => 'server_status'));
if ($server['status'] == "off") {

View File

@ -1,59 +0,0 @@
<?php
/**
* PHP Server Monitor
* Monitor your servers and websites.
*
* This file is part of PHP Server Monitor.
* PHP Server Monitor is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PHP Server Monitor is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PHP Server Monitor. If not, see <http://www.gnu.org/licenses/>.
*
* @package phpservermon
* @author Perri Vardy-Mason
* @copyright Copyright (c) 2008-2015 Pepijn Over <pep@peplab.net>
* @license http://www.gnu.org/licenses/gpl.txt GNU GPL v3
* @version Release: @package_version@
* @link http://www.phpservermonitor.org/
* @since phpservermon 2.1
**/
namespace psm\Txtmsg;
class Textmarketer extends Core {
// =========================================================================
// [ Fields ]
// =========================================================================
public $gateway = 1;
public $resultcode = null;
public $resultmessage = null;
public $success = false;
public $successcount = 0;
public function sendSMS($message) {
$textmarketer_url = "https://api.textmarketer.co.uk/gateway/";
$textmarketer_data = urlencode( $message );
$textmarketer_origin = urlencode( 'SERVERALERT' );
foreach( $this->recipients as $phone ){
$URL = $textmarketer_url."?username=" . $this->username . "&password=" . $this->password . "&to=" . $phone . "&message=" . $textmarketer_data . "&orig=" . $textmarketer_origin;
$result = file_get_contents( $URL );
}
return $result;
}
}

View File

@ -227,6 +227,8 @@ 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,
`last_offline_duration` varchar(255) 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` (
@ -302,6 +304,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);
}
@ -333,6 +337,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`
@ -412,6 +418,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,
@ -428,6 +436,9 @@ class Installer {
$queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` CHANGE `ip` `ip` VARCHAR(500) NOT 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;";
$this->execSQL($queries);
}
}

View File

@ -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', 'last_offline_duration',
));
if(empty($this->server)) {
return false;

View File

@ -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_offline',
));
if(empty($this->server)) {
return false;
@ -113,6 +113,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;
@ -124,6 +130,9 @@ class StatusUpdater {
$this->status_new = true;
} else {
$save['status'] = 'off';
if ($this->server['status'] == 'on') {
$save['last_offline'] = $save['last_check'];
}
}
}

View File

@ -8,6 +8,7 @@
<th class="visible-desktop">{{ label_type }}</th>
<th class="hidden-phone">{{ label_rtime }}</th>
<th class="hidden-phone">{{ label_last_online }}</th>
<th class="hidden-phone">{{ label_last_offline }}</th>
<th class="hidden-phone">{{ label_monitoring }}</th>
<th class="hidden-phone">{{ label_action }}</th>
</tr>
@ -23,6 +24,7 @@
<td class="nowrap visible-desktop"><div class="table-cell-title">{{ server.type }}</div></td>
<td class="nowrap hidden-phone"><div class="table-cell-title">{{ server.rtime }} s</div></td>
<td class="nowrap hidden-phone"><div class="table-cell-title">{{ server.last_online }}</div></td>
<td class="nowrap hidden-phone"><div class="table-cell-title">{{ server.last_offline }} {{ server.last_offline_duration }}</div></td>
<td class="tight hidden-phone"><div class="table-cell-title"><i class="{{ server.active_icon }}" title="{{ server.active_title }}"></i> <i class="{{ server.email_icon }}" title="{{ label_email }}"></i> <i class="{{ server.sms_icon }}" title="{{ label_sms }}"></i> <i class="{{ server.pushover_icon }}" title="Pushover"></i></div></td>
<td class="tight hidden-phone">
<div class="table-cell-title">
@ -58,6 +60,7 @@
<div class="table-body">
<div class="table-row"><div class="table-cell-details tight">{{ label_rtime }}: &nbsp;</div><div class="table-cell-details">{{ server.rtime }} s</div></div>
<div class="table-row"><div class="table-cell-details tight">{{ label_last_online }}: &nbsp;</div><div class="table-cell-details">{{ server.last_online }}</div></div>
<div class="table-row"><div class="table-cell-details tight">{{ label_last_offline }}: &nbsp;</div><div class="table-cell-details">{{ server.last_offline }} {{ server.last_offline_duration }}</div></div>
</div>
</td>
</tr>

View File

@ -49,6 +49,10 @@
<td>{{ label_last_online }}:</td>
<td>{{ last_online }}</td>
</tr>
<tr>
<td>{{ label_last_offline }}:</td>
<td>{{ last_offline }} {{ last_offline_duration }}</td>
</tr>
<tr>
<td>{{ label_rtime }}:</td>
<td>{{ rtime }} s</td>

View File

@ -15,6 +15,7 @@
<div class="entity" onclick="window.location.href='{{ server.url_view|raw }}'">
<h2>{{ server.label }}</h2>
<p>{{ label_last_online }}: {{ server.last_online_nice }}</p>
<p>{{ label_last_offline }}: {{ server.last_offline_nice }} {{ server.last_offline_duration_nice }}</p>
<p>{{ label_rtime }}: {{ server.rtime }}s</p>
</div>
</div>
@ -32,11 +33,13 @@
<div class="table-body">
<div class="table-row"><div class="table-cell-details tight">{{ label_last_online }}: &nbsp;</div><div class="table-cell-details">{{ server.last_online_nice }}</div></div>
<div class="table-row"><div class="table-cell-details tight">{{ label_last_check }}: &nbsp;</div><div class="table-cell-details">{{ server.last_checked_nice }}</div></div>
<div class="table-row"><div class="table-cell-details tight">&nbsp;</div><div class="table-cell-details">&nbsp;</div></div>
</div>
</div>
</td>
<td class="{{ server.class_warning }} hidden-phone">{{ label_last_online }}: {{ server.last_online_nice }}</td>
<td class="{{ server.class_warning }} hidden-phone">{{ label_last_check }}: {{ server.last_checked_nice }}</td>
<td class="{{ server.class_warning }} hidden-phone"></td>
</tr>
{% endfor %}
{% for server in servers_online %}
@ -45,11 +48,13 @@
<div class="visible-phone">
<div class="table-body">
<div class="table-row"><div class="table-cell-details tight">{{ label_last_online }}: &nbsp;</div><div class="table-cell-details">{{ server.last_online_nice }}</div></div>
<div class="table-row"><div class="table-cell-details tight">{{ label_last_offline }}: &nbsp;</div><div class="table-cell-details">{{ server.last_offline_nice }} {{ server.last_offline_duration_nice }}</div></div>
<div class="table-row"><div class="table-cell-details tight">{{ label_rtime }}: &nbsp;</div><div class="table-cell-details">{{ server.rtime }}</div></div>
</div>
</div>
</td>
<td class="hidden-phone">{{ label_last_online }}: {{ server.last_online_nice }}</td>
<td class="hidden-phone">{{ label_last_offline }}: {{ server.last_offline_nice }} {{ server.last_offline_duration_nice }}</td>
<td class="hidden-phone">{{ label_rtime }}: {{ server.rtime }}s</td>
</tr>
{% endfor %}