Add support for site online when pattern not found

patterns prefixed with "!" will count as mark site offline when this string is found
pull/579/head
Danial Nickford 2018-04-23 16:26:50 +12:00
parent fc4ffd6b2f
commit 5bc7c1e4ea
1 changed files with 5 additions and 3 deletions

View File

@ -248,9 +248,11 @@ class StatusUpdater {
//Okay, the HTTP status is good : 2xx or 3xx. Now we have to test the pattern if it's set up //Okay, the HTTP status is good : 2xx or 3xx. Now we have to test the pattern if it's set up
if($this->server['pattern'] != '') { if($this->server['pattern'] != '') {
// Check to see if the pattern was found. // Check to see if the body should not contain specified pattern
if(!preg_match("/{$this->server['pattern']}/i", $curl_result)) { $negative_search = substr($this->server['pattern'], 0, 1) === '!';
$this->error = 'TEXT ERROR : Pattern not found.'; // Check to see if the pattern was [not] found.
if($negative_search ? preg_match("/" . substr($this->server['pattern'],1) . "/i", $curl_result) : !preg_match("/{$this->server['pattern']}/i", $curl_result)) {
$this->error = 'TEXT ERROR : Pattern ' . ($negative_search ? 'was' : 'not') . ' found.';
$result = false; $result = false;
} }
} }