diff --git a/CHANGELOG b/CHANGELOG index 54fa6ddb..f51b4c51 100755 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,6 +6,7 @@ - Merged PHP Server Monitor Plus project by Luiz Alberto S. Ribeiro (https://github.com/madeinnordeste/PHP-Server-Monitor-Plus). -- New layout (thanks to twitter bootstrap) - New install module. +- Regex search on website has been added by Paul Feakins. - Support for mosms provider by Andreas Ek. - Support for Textmarketer provider by Perri Vardy-Mason. - Language files are now automatically detected, instead of a hardcoded list. diff --git a/README.md b/README.md index e3767f76..057fb35c 100755 --- a/README.md +++ b/README.md @@ -17,14 +17,11 @@ whether it is a "service" or a "website": * Website - The previous version only tried to establish a connection to the server on port 80. If you are running multiple - websites on 1 machine, there was no proper way to check each website for possible errors. Also it was impossible to make - sure your site was really up and running, all you knew was that the server was still online. - This function takes care of that. You can enter a link to a website (for example ), it will use cURL to open the website and check the HTTP status code (see for details). If the HTTP status code is in the 4xx range, it means an error occurred and the website is not accessible to the public. - In that case the script will return a "status offline", and will start sending out notifications. + You can also set a regular expression to match certain content on the page itself. If the regular expression returns no matches, the website is considered down. + In both cases the script will return a "status offline", and will start sending out notifications. Each server has it's own settings regarding notification. You can choose for email notification or text message (SMS). diff --git a/cron/status.cron.php b/cron/status.cron.php index d388db2c..9bd43e3a 100755 --- a/cron/status.cron.php +++ b/cron/status.cron.php @@ -32,7 +32,7 @@ require_once dirname(__FILE__) . '/../src/bootstrap.php'; $servers = $db->select( PSM_DB_PREFIX.'servers', array('active' => 'yes'), - array('server_id', 'ip', 'port', 'label', 'type', 'status', 'active', 'email', 'sms') + array('server_id', 'ip', 'port', 'label', 'type', 'pattern', 'status', 'active', 'email', 'sms') ); $updater = new \psm\Util\Updater\Status(); diff --git a/src/lang/br.lang.php b/src/lang/br.lang.php index 8885ef36..9a440a48 100755 --- a/src/lang/br.lang.php +++ b/src/lang/br.lang.php @@ -71,6 +71,7 @@ $sm_lang = array( 'domain' => 'Domínio/IP', 'port' => 'Porta', 'type' => 'Tipo', + 'pattern' => 'Search string/pattern', 'last_check' => 'Última verificação', 'last_online' => 'Última vez online', 'monitoring' => 'Monitoramento', diff --git a/src/lang/de.lang.php b/src/lang/de.lang.php index b8cb1f74..1b610e9d 100755 --- a/src/lang/de.lang.php +++ b/src/lang/de.lang.php @@ -71,6 +71,7 @@ $sm_lang = array( 'domain' => 'Domain/IP', 'port' => 'Port', 'type' => 'Type', + 'pattern' => 'Search string/pattern', 'last_check' => 'Letzter Check', 'last_online' => 'Letztes mal Online', 'monitoring' => 'Monitoring', diff --git a/src/lang/en.lang.php b/src/lang/en.lang.php index c1ea45be..b2c3cb07 100755 --- a/src/lang/en.lang.php +++ b/src/lang/en.lang.php @@ -71,6 +71,7 @@ $sm_lang = array( 'domain' => 'Domain/IP', 'port' => 'Port', 'type' => 'Type', + 'pattern' => 'Search string/pattern', 'last_check' => 'Last check', 'last_online' => 'Last online', 'monitoring' => 'Monitoring', diff --git a/src/lang/fr.lang.php b/src/lang/fr.lang.php index 02999319..767e25a7 100755 --- a/src/lang/fr.lang.php +++ b/src/lang/fr.lang.php @@ -71,6 +71,7 @@ $sm_lang = array( 'domain' => 'Domaine/IP', 'port' => 'Port', 'type' => 'Type', + 'pattern' => 'Search string/pattern', 'last_check' => 'Dernière vérification', 'last_online' => 'Dernière fois OK', 'monitoring' => 'Supervision', diff --git a/src/lang/kr.lang.php b/src/lang/kr.lang.php index 9d652df1..2c931de7 100755 --- a/src/lang/kr.lang.php +++ b/src/lang/kr.lang.php @@ -72,6 +72,7 @@ $sm_lang = array( 'domain' => 'Domain/IP', 'port' => 'Port', 'type' => 'Type', + 'pattern' => 'Search string/regex', 'last_check' => '최근체크', 'last_online' => '최근접속', 'monitoring' => '확인중', diff --git a/src/lang/nl.lang.php b/src/lang/nl.lang.php index 463ff6aa..dc227a65 100755 --- a/src/lang/nl.lang.php +++ b/src/lang/nl.lang.php @@ -71,6 +71,7 @@ $sm_lang = array( 'domain' => 'Domein/IP', 'port' => 'Poort', 'type' => 'Type', + 'pattern' => 'Zoek voor tekst/regex', 'last_check' => 'Laatst gecontroleerd', 'last_online' => 'Laatst online', 'monitoring' => 'Monitoring', diff --git a/src/psm/Module/Servers.class.php b/src/psm/Module/Servers.class.php index b12fc519..d19038f5 100755 --- a/src/psm/Module/Servers.class.php +++ b/src/psm/Module/Servers.class.php @@ -56,6 +56,7 @@ class Servers extends AbstractModule { '`port`, '. '`type`, '. '`label`, '. + '`pattern`, '. '`status`, '. '`error`, '. '`rtime`, '. @@ -134,6 +135,7 @@ class Servers extends AbstractModule { 'edit_value_label' => $edit_server['label'], 'edit_value_ip' => $edit_server['ip'], 'edit_value_port' => $edit_server['port'], + 'edit_value_pattern' => $edit_server['pattern'], 'edit_type_selected_' . $edit_server['type'] => 'selected="selected"', 'edit_active_selected_' . $edit_server['active'] => 'selected="selected"', 'edit_email_selected_' . $edit_server['email'] => 'selected="selected"', @@ -163,6 +165,7 @@ class Servers extends AbstractModule { 'port' => strip_tags($_POST['port']), // @todo validate the following values 'type' => $_POST['type'], + 'pattern' => $_POST['pattern'], 'active' => $_POST['active'], 'email' => $_POST['email'], 'sms' => $_POST['sms'], @@ -214,6 +217,7 @@ class Servers extends AbstractModule { 'label_domain' => psm_get_lang('servers', 'domain'), 'label_port' => psm_get_lang('servers', 'port'), 'label_type' => psm_get_lang('servers', 'type'), + 'label_pattern' => psm_get_lang('servers', 'pattern'), 'label_last_check' => psm_get_lang('servers', 'last_check'), 'label_rtime' => psm_get_lang('servers', 'rtime'), 'label_last_online' => psm_get_lang('servers', 'last_online'), diff --git a/src/psm/Util/Install/Queries.class.php b/src/psm/Util/Install/Queries.class.php index 4ce77c93..4c231881 100644 --- a/src/psm/Util/Install/Queries.class.php +++ b/src/psm/Util/Install/Queries.class.php @@ -61,6 +61,7 @@ class Queries { `port` int(5) NOT NULL, `label` varchar(255) NOT NULL, `type` enum('service','website') NOT NULL default 'service', + `pattern` varchar(255) NOT NULL, `status` enum('on','off') NOT NULL default 'on', `error` varchar(255) NULL, `rtime` FLOAT(9, 7) NULL, @@ -121,6 +122,8 @@ class Queries { $queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` CHANGE `rtime` `rtime` FLOAT( 9, 7 ) NULL;"; $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[] = "UPDATE `" . PSM_DB_PREFIX . "config` SET `value` = '{$version}' WHERE `key` = 'version';"; diff --git a/src/psm/Util/Updater/Status.class.php b/src/psm/Util/Updater/Status.class.php index 4d6357bb..38cc671a 100755 --- a/src/psm/Util/Updater/Status.class.php +++ b/src/psm/Util/Updater/Status.class.php @@ -130,10 +130,11 @@ class Status { curl_setopt ($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11'); // We're only interested in the header, because that should tell us plenty! + // unless we have a pattern to search for! curl_setopt($ch, CURLOPT_HEADER, true); - curl_setopt($ch, CURLOPT_NOBODY, true); + curl_setopt($ch, CURLOPT_NOBODY, ($this->server['pattern'] != '' ? false : true)); - $headers = curl_exec ($ch); + $curl_result = curl_exec ($ch); curl_close ($ch); $time = explode(" ", microtime()); @@ -141,7 +142,7 @@ class Status { $this->rtime = ($endtime - $starttime); // the first line would be the status code.. - $status_code = strtok($headers, "\r\n"); + $status_code = strtok($curl_result, "\r\n"); // keep it general // $code[1][0] = status code // $code[2][0] = name of status code @@ -163,6 +164,13 @@ class Status { $this->status_new = 'on'; } } + if($this->server['pattern'] != '') { + // Check to see if the pattern was found. + if(!preg_match("/{$this->server['pattern']}/i", $curl_result)) { + $this->server['error'] = $this->error = 'Pattern not found.'; + $this->status_new = 'off'; + } + } // check if server is available and rerun if asked. if($this->status_new == 'off' && $run < $max_runs) { diff --git a/src/templates/servers.tpl.html b/src/templates/servers.tpl.html index 0cf7c77b..49db8980 100755 --- a/src/templates/servers.tpl.html +++ b/src/templates/servers.tpl.html @@ -91,6 +91,12 @@ +
+ +
+ +
+