Adding regex support to search for patterns in the website body, thanks

to Paul Feakins.
This commit is contained in:
Pepijn Over 2014-02-08 20:14:49 +01:00
parent 9894399c2a
commit 947923c5d6
13 changed files with 34 additions and 9 deletions

View File

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

View File

@ -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 <http://sourceforge.net/index.php>), it will use cURL to open the website and
check the HTTP status code (see <http://en.wikipedia.org/wiki/List_of_HTTP_status_codes> 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).

View File

@ -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();

View File

@ -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',

View File

@ -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',

View File

@ -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',

View File

@ -71,6 +71,7 @@ $sm_lang = array(
'domain' => 'Domaine/IP',
'port' => 'Port',
'type' => 'Type',
'pattern' => 'Search string/pattern',
'last_check' => 'Derni&egrave;re v&eacute;rification',
'last_online' => 'Derni&egrave;re fois OK',
'monitoring' => 'Supervision',

View File

@ -72,6 +72,7 @@ $sm_lang = array(
'domain' => 'Domain/IP',
'port' => 'Port',
'type' => 'Type',
'pattern' => 'Search string/regex',
'last_check' => '최근체크',
'last_online' => '최근접속',
'monitoring' => '확인중',

View File

@ -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',

View File

@ -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'),

View File

@ -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';";

View File

@ -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) {

View File

@ -91,6 +91,12 @@
</select>
</div>
</div>
<div class="control-group">
<label class="control-label" for="pattern">{label_pattern}</label>
<div class="controls">
<input type="text" name="pattern" value="{edit_value_pattern}" maxlength="255" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="active">{label_monitoring}</label>
<div class="controls">