Mark specific HTTP status codes as online (#628)

Add option to specify which HTTP status codes are considered as "online".
Closing #175.
This commit is contained in:
Tim 2018-09-05 22:34:19 +02:00 committed by GitHub
parent 132a730d71
commit 7aa7ec363b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 34 additions and 4 deletions

View File

@ -5,6 +5,7 @@ Changelog
Not yet released
----------------
* #628: Added the option to mark specific HTTP status codes as online.
* #640: Removed () after last offline value when the last offline duration is unknown.
* #637: Added php extensions to composer required list, spelling fixes in changelog and composer update.
* #635: Changed server order on ?&mod=user&action=edit&id=x.

View File

@ -29,7 +29,7 @@
/**
* Current PSM version
*/
define('PSM_VERSION', '3.3.1');
define('PSM_VERSION', '3.4.0');
/**
* URL to check for updates. Will not be checked if turned off on config page.

View File

@ -169,6 +169,8 @@ $sm_lang = array(
'pattern_description' => 'If this pattern is not found on the website, the server will be marked online/offline. Regular expressions are allowed.',
'pattern_online' => 'Pattern indicates website is',
'pattern_online_description' => 'Online: If this pattern is not found on the website, the server will be marked online. Offline: If this pattern is not found on the website, the server will be marked offline.',
'allow_http_status' => 'Allow HTTP status code',
'allow_http_status_description' => 'Mark website as online. HTTP Status codes lower then 400 are marked as online by default. Seperate with |. Example: 401|403.',
'header' => 'Header',
'header_name_description' => 'Header name (case-sensitive)',
'header_value_description' => 'Header value. Regular expressions are allowed.',

View File

@ -142,6 +142,8 @@ $sm_lang = array(
'type_service' => 'Service',
'pattern' => 'Zoek voor tekst/regex',
'pattern_description' => 'Als dit patroon niet gevonden wordt op de website, zal de server als offline gemarkeerd worden. Regular expressions zijn toegestaan.',
'allow_http_status' => 'Sta HTTP status code toe',
'allow_http_status_description' => 'Markeer website als online. HTTP status code lager dan 400 worden standaard als online gemarkeerd. Scheiden met |. Bijvoorbeeld: 401|403.',
'last_check' => 'Laatst gecontroleerd',
'last_online' => 'Laatst online',
'last_offline' => 'Laatst offline',

View File

@ -65,6 +65,7 @@ abstract class AbstractServerController extends AbstractController {
`s`.`label`,
`s`.`pattern`,
`s`.`pattern_online`,
`s`.`allow_http_status`,
`s`.`header_name`,
`s`.`header_value`,
`s`.`status`,

View File

@ -200,6 +200,7 @@ class ServerController extends AbstractServerController {
'default_value_timeout' => PSM_CURL_TIMEOUT,
'edit_value_pattern' => $edit_server['pattern'],
'edit_pattern_selected_'.$edit_server['pattern_online'] => 'selected="selected"',
'edit_value_allow_http_status' => $edit_server['allow_http_status'],
'edit_value_header_name' => $edit_server['header_name'],
'edit_value_header_value' => $edit_server['header_value'],
'edit_value_warning_threshold' => $edit_server['warning_threshold'],
@ -267,6 +268,7 @@ class ServerController extends AbstractServerController {
'type' => psm_POST('type', ''),
'pattern' => psm_POST('pattern', ''),
'pattern_online' => in_array($_POST['pattern_online'], array('yes', 'no')) ? $_POST['pattern_online'] : 'yes',
'allow_http_status' => psm_POST('allow_http_status', ''),
'header_name' => psm_POST('header_name', ''),
'header_value' => psm_POST('header_value', ''),
'rtime' => psm_POST('rtime', '0.0000000'),
@ -473,6 +475,8 @@ class ServerController extends AbstractServerController {
'label_pattern_description' => psm_get_lang('servers', 'pattern_description'),
'label_pattern_online' => psm_get_lang('servers', 'pattern_online'),
'label_pattern_online_description' => psm_get_lang('servers', 'pattern_online_description'),
'label_allow_http_status' => psm_get_lang('servers', 'allow_http_status'),
'label_allow_http_status_description' => psm_get_lang('servers', 'allow_http_status_description'),
'label_header' => psm_get_lang('servers', 'header'),
'label_header_name_description' => psm_get_lang('servers', 'header_name_description'),
'label_header_value_description' => psm_get_lang('servers', 'header_value_description'),

View File

@ -227,8 +227,9 @@ class Installer {
`port` int(5) unsigned NOT NULL,
`label` varchar(255) NOT NULL,
`type` enum('ping','service','website') NOT NULL default 'service',
`pattern` varchar(255) NOT NULL,
`pattern` varchar(255) NOT NULL default '',
`pattern_online` enum('yes','no') NOT NULL default 'yes',
`allow_http_status` varchar(255) NOT NULL default '',
`header_name` varchar(255) NOT NULL default '',
`header_value` varchar(255) NOT NULL default '',
`status` enum('on','off') NOT NULL default 'on',
@ -313,6 +314,9 @@ class Installer {
if (version_compare($version_from, '3.3.0', '<')) {
$this->upgrade330();
}
if (version_compare($version_from, '3.4.0', '<')) {
$this->upgrade340();
}
psm_update_conf('version', $version_to);
}
@ -539,6 +543,15 @@ class Installer {
if (psm_get_conf('sms_gateway') == 'mollie') {
psm_update_conf('sms_gateway', 'messagebird');
}
}
/**
* Upgrade for v3.4.0 release
*/
protected function upgrade340() {
$queries = array();
$queries[] = "ALTER TABLE `".PSM_DB_PREFIX."servers` ADD `allow_http_status` VARCHAR(255) NOT NULL DEFAULT '' AFTER j`pattern_online`;";
$this->execSQL($queries);
}
}

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', 'pattern_online', 'header_name', 'header_value', 'status', 'active', 'warning_threshold',
'server_id', 'ip', 'port', 'label', 'type', 'pattern', 'pattern_online', 'allow_http_status', 'header_name', 'header_value', 'status', 'active', 'warning_threshold',
'warning_threshold_counter', 'timeout', 'website_username', 'website_password', 'last_offline'
));
if (empty($this->server)) {
@ -250,8 +250,9 @@ class StatusUpdater {
$code = $code_matches[1][0];
$msg = $code_matches[2][0];
$allow_http_status = explode("|", $this->server['allow_http_status']);
// All status codes starting with a 4 or higher mean trouble!
if (substr($code, 0, 1) >= '4') {
if (substr($code, 0, 1) >= '4' && !in_array($code ,$allow_http_status)) {
$this->error = "HTTP STATUS ERROR: ".$code.' '.$msg;
$result = false;
} else {

View File

@ -74,6 +74,12 @@
</select>
</div>
</div>
<div class="control-group types typeWebsite">
<label class="control-label" for="allow_http_status">{{ label_allow_http_status }}</label>
<div class="controls">
<input type="text" id="allow_http_status" name="allow_http_status" value="{{ edit_value_allow_http_status }}" maxlength="255" data-toggle="tooltip" title="{{ label_allow_http_status_description }}" />
</div>
</div>
<div class="control-group types typeWebsite">
<label class="control-label" for="header_name">{{ label_header }}</label>
<div class="controls">