Skip to content

Instantly share code, notes, and snippets.

@sajanp
Created June 29, 2013 19:16
Show Gist options
  • Save sajanp/5892310 to your computer and use it in GitHub Desktop.
Save sajanp/5892310 to your computer and use it in GitHub Desktop.
A basic status page for Nodeping. You create check groups by putting (Group Name) in the check name at nodeping.
<?php
$apiToken = ''; // Your API Key from NodePing.
// Ask NodePing if any checks are down.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.nodeping.com/api/1/checks?current=1&token=" . $apiToken);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$checks = json_decode(curl_exec($ch));
// Group Everything.
foreach ($checks as $check) {
preg_match_all("/\((.*?)\)/", $check->label, $result_array);
$group = $result_array[1][0];
$groups[$group][] = $check;
if (property_exists($check, 'current')) {
$groups[$group]['overall'] = true;
}
}
?>
<html>
<head>
<title>Noppix LLC Status</title>
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet">
<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
<link href='http://fonts.googleapis.com/css?family=Droid+Sans' rel='stylesheet' type='text/css'>
<style>
body, html {
background: #efefef;
margin: 15px 0;
font-family: 'Droid Sans', sans-serif;
}
.container {
width: 500px;
}
#intro, #logo, h2 {
margin: 10px auto;
text-align: center;
display: block;
font-size: 1.3em;
}
h2 {
font-size: 1.7em;
}
p {
margin: 5px;
text-align: center;
}
</style>
</head>
<body>
<div class="container">
<img src="logo.png" alt="Noppix LLC Logo" id="logo">
<h2>Service Status</h2>
<p id="intro">If you have any questions, please feel free to email [email protected] or call (888) 736-0443.</p>
<table class="table table-hover table-condensed">
<?php
foreach ($groups as $group => $checks) {
if (strlen($group) < 2) {
continue;
}
$percentDown = (count(array_keys($checks, 'current')) / count($checks)) * 100;
if ($percentDown > 49) {
echo '<tr class="error">';
echo '<td>' . $group . '</td>';
echo '<td><span class="label label-important">Down</span></td>';
echo '<tr>';
} elseif ($percentDown > 1 and $percentDown < 49) {
echo '<tr class="warning">';
echo '<td>' . $group . '</td>';
echo '<td><span class="label label-warning">Disruption</span></td>';
echo '<tr>';
} else {
echo '<tr class="success">';
echo '<td>' . $group . '</td>';
echo '<td><span class="label label-success">Running</span></td>';
echo '<tr>';
}
}
?>
</table>
<p>If you see <span class="label label-warning">Disruption</span> above it means either only a small portion of clients are affected, or something is down but redundant affecting no clients.</p>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment