-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.php
40 lines (25 loc) · 787 Bytes
/
test.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
<?php
#example: php test.php -w 300 -c 400 -v price -u ontariobeerapi.ca/products/2139068/
#requires utils.php from http://doug.warner.fm/nagios-utilsphp-script-for-php-plugins.html
$options = getopt("w:c:v:u:");
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $options["u"]);
$chData=curl_exec($ch);
$chDataArray=json_decode($chData,true);
curl_close($ch);
include 'utils.php';
#echo $chDataArray[$options["v"]];
$warning = new Nagios_Plugin_Range($options["w"]);
$critical = new Nagios_Plugin_Range($options["c"]);
if($critical->check_range($chDataArray[$options["v"]])){
echo "CRITICAL!\n";
return 2;
}
if($warning->check_range($chDataArray[$options["v"]])){
echo "WARNING!\n";
return 1;
}
echo "OK!\n";
return 0;
?>