-
-
Save radermacher/12c41878bec60cf07ad132272bf13723 to your computer and use it in GitHub Desktop.
Kimsufi notifier
This file contains hidden or 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 | |
$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