Last active
August 29, 2015 14:04
-
-
Save ThomasLeister/0d6c52f58f6df580558a to your computer and use it in GitHub Desktop.
Catches the current Uptimerobot status and displays it on a webpage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/**************************************************************** | |
* Copyright 2014 Thomas Leister | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
* | |
* | |
* | |
* This frontend uses mb20's Uptime Robot php class | |
* https://github.com/CodingOurWeb/PHP-wrapper-for-UptimeRobot-API/blob/master/uptimerobot.class.php | |
* | |
*****************************************************************/ | |
require_once("uptimerobot.class.php"); | |
$globalAPIKey = "[PLEASE ENTER GLOBAL API KEY HERE]"; | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Service status</title> | |
<style> | |
body{ | |
font-family:Monospace; | |
} | |
span.online{ | |
color:green; | |
} | |
span.offline{ | |
color:red; | |
} | |
span.paused{ | |
color:blue; | |
} | |
</style> | |
</head> | |
<body> | |
<?php | |
$ur = new UptimeRobot($globalAPIKey); // instantiates new UptimeRobot object | |
$ur->setFormat('json'); // sets output format | |
/*** get monitors ***/ | |
$result = $ur->getMonitors(null); | |
$monitordata = json_decode($result); | |
$monitors = $monitordata->monitors; | |
$monitor = $monitors->monitor; | |
?> | |
<h2>Service status</h2> | |
<table> | |
<tr style="font-weight:bold;"><td>Host</td> <td>Uptime (%)</td> <td>Status</td></tr> | |
<?php | |
foreach($monitor as $domain){ | |
if($domain->status == 2){ | |
$status = "<span class=\"online\">ONLINE</span>"; | |
} | |
else if($domain->status == 0){ | |
$status = "<span class=\"paused\">PAUSED / WORK IN PROGRESS</span>"; | |
} | |
else{ | |
$status = "<span class=\"offline\">OFFLINE</span>"; | |
} | |
$uptime = $domain->alltimeuptimeratio; | |
$name = $domain->friendlyname; | |
?> | |
<tr><td><?php echo $name;?></td> <td><?php echo $uptime; ?></td> <td><?php echo $status; ?></td> </tr> | |
<?php | |
} | |
?> | |
</table> | |
<p style="font-size:10px; margin-top:50px;"> | |
Data provided by <a href="http://uptimerobot.com">Uptime Robot</a>.<br> | |
<a href="https://gist.github.com/ThomasLeister/0d6c52f58f6df580558a">Frontend script</a> by <a href="https://thomas-leister.de">Thomas Leister</a> | |
</p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment