Skip to content

Instantly share code, notes, and snippets.

@julienbourdeau
Created August 13, 2017 05:34
Show Gist options
  • Save julienbourdeau/9fa76b84a3c382cbf5eaa013613bdda2 to your computer and use it in GitHub Desktop.
Save julienbourdeau/9fa76b84a3c382cbf5eaa013613bdda2 to your computer and use it in GitHub Desktop.
Kimsufi notifier
<?php
$url = "https://ws.ovh.com/dedicated/r2/ws.dispatcher/getAvailability2?callback=Request.JSONP.request_map.request_0";
$content = file_get_contents($url);
$content = substr($content, strlen("Request.JSONP.request_map.request_0("));
$content = substr($content, 0, strlen($content) - 2);
$content = json_decode($content);
$content = $content->answer->availability;
$servers = [];
foreach ($content as $type) {
$reference = $type->reference;
foreach ($type->zones as $zone) {
$availability = $zone->availability;
if ($availability != 'unknown' && $availability != "unavailable") {
if ($zone->zone == "gra" || $zone->zone == "rbx-hz" || $zone->zone == "sbg" || $zone->zone == "rbx") {
if (! isset($servers[$reference])) {
$servers[$reference] = [];
}
$servers[$reference][] = [$zone->zone => $availability];
}
}
}
}
$checking_list = ['160sk1' => 'KS-1'];
foreach ($checking_list as $ref => $refName) {
if (isset($servers[$ref])) {
notify("server ".$refName." available: ".json_encode($servers[$ref]));
}
}
function notify($message = 'Server available!') {
curl_setopt_array($ch = curl_init(), array(
CURLOPT_URL => "https://api.pushover.net/1/messages.json",
CURLOPT_POSTFIELDS => array(
"token" => "YOUR_TOKEN",
"user" => "YOUR_USER_KEY",
"message" => $message,
),
CURLOPT_SAFE_UPLOAD => true,
CURLOPT_RETURNTRANSFER => true,
));
curl_exec($ch);
curl_close($ch);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment