-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckResponse.php
61 lines (39 loc) · 1.48 KB
/
checkResponse.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
require 'sites.php';
$DOWN=0;
$OUT = array ();
function curlRequest ($s) {
$respHTTP = @explode(" ",exec("curl -sI http://$s|head -1"))[1];
$respHTTPs = @explode(" ",exec("curl -sI https://$s|head -1"))[1];
if ($respHTTP == '200' || $respHTTPs == '200') return "OK";
elseif ($respHTTP == FALSE && $respHTTPs == FALSE) return "has a null HTTP(s) responses, could not to resolve.\n";
else return "has a bad HTTP: (".$respHTTP.")/HTTPS: (".$respHTTPs.") responses\n";
}
if ($interface == 'cli') {
foreach ($SITES as $site) {
$check = curlRequest($site);
if ($check != 'OK') {
$logfile = fopen("response-error.log", 'a');
$report = "WARNING: ".@date(DATE_COOKIE)." ".strtoupper($site)." - ".$check;
#echo $report;
fwrite($logfile, $report);
fclose($logfile);
++$DOWN;
}
}
/*
Purge log file if all responses is passed successfully
*/
if ($DOWN === 0) exec('cat /dev/null > response-error.log');
/*
Output to Solar Wind
*/
echo $DOWN > 0 ? "Statistic.SitesIsDown:$DOWN" : "Statistic.SitesIsDown:0";
}
else {
header("cache-control: no-cache, must-revalidate, max-age=0");
echo "<b>$script</b> - provide checks of all http(s) responses of monitored domains.<br>\n
In any warning alerts see the <a href=\"/sw/response-error.log\">LOG FILE</a>, which will be empty if all responses is OK.<br>\n";
require 'footer.php';
}
?>