forked from ckdarby/PHP-UptimeRobot
-
Notifications
You must be signed in to change notification settings - Fork 3
/
uptimeRobot.php
44 lines (36 loc) · 1.08 KB
/
uptimeRobot.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
<?php
//Requires composer install to work
require_once(__DIR__.'/vendor/autoload.php');
use UptimeRobot\API;
//Set configuration settings
$config = [
'apiKey' => '',
'url' => 'https://api.uptimerobot.com'
];
try {
//Initalizes API with config options
$api = new API($config);
//Define parameters for our getMethod request
$args = [
'showTimezone' => 3
];
//Makes request to the getMonitor Method
$results = $api->request('/getMonitors', $args);
// Make sure there is a parameter to check the single monitor.
if ($argc > 1):
foreach ($results['monitors']['monitor'] as $monitor) {
if ($monitor['friendlyname'] === $argv[1]) echo $monitor['status'];
}
// List all monitors
else:
$data = "";
foreach ($results['monitors']['monitor'] as $monitor) {
$data .= "{\"{#MONITOR}\":\"".$monitor['friendlyname']."\"},";
}
echo "{\"data\":[".rtrim($data,',')."]}";
endif;
} catch (Exception $e) {
echo $e->getMessage();
//Output various debug information
var_dump($api->debug);
}