Created
December 21, 2016 16:29
-
-
Save colinwilson/3d4249eda398ed5ec0438197e80a1a84 to your computer and use it in GitHub Desktop.
OVH Server Availability Checker
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 | |
/* | |
* Script to check SoYouStart availability based on http://www.tienle.com/2014/09-03/script-check-soyoustart-availability.html | |
*/ | |
define('CHECK_URL', 'https://ws.ovh.com/dedicated/r2/ws.dispatcher/getAvailability2'); | |
define('NOTIFICATION_EMAILS', '[email protected]'); // Comma separated list of notifaction email address | |
define('SYSTEM_EMAIL', '0'); // 1 = enabled local smtp system | |
define('MAILGUN', '1'); // 1 = enable email through mailgun api, require an account on https://mailgun.org/ | |
define('MAILGUN_API', 'YOUR_MAILGUN_API_KEY'); // Enter your Mailgun App API Key here | |
define('MAILGUN_DOMAIN', 'YOUR_MAILGUN_DOMAIN'); // Enter your Mailgun App sending domain here | |
define('TEMP_PREVIOUS_MSG_FILE', dirname(__FILE__). '/sys-avail-cache.txt'); | |
$f = file_get_contents(CHECK_URL); | |
$a = json_decode($f); | |
$avail = $a->answer->availability; | |
$str_avai = ''; | |
$zone_to_check = array('143sys10','143sys11'); //Replace with your choice of servers to check on | |
foreach($avail as $s) { | |
if( in_array($s->reference, $zone_to_check)) { | |
$z = $s->zones; | |
foreach($z as $zone) { | |
// Please check your best zone here http://proof.ovh.net/ | |
if($zone->availability!=='unavailable' && $zone->availability!=='unknown' && strtolower($zone->zone) == 'bhs' || $zone->availability!=='unavailable' && $zone->availability!=='unknown' && strtolower($zone->zone) == 'gra' || $zone->availability!=='unavailable' && $zone->availability!=='unknown' && strtolower($zone->zone) == 'rbx' || $zone->availability!=='unavailable' && $zone->availability!=='unknown' && strtolower($zone->zone) == 'sbg' || $zone->availability!=='unavailable' && $zone->availability!=='unknown' && strtolower($zone->zone) == 'waw' || $zone->availability!=='unavailable' && $zone->availability!=='unknown' && strtolower($zone->zone) == 'rbx-hz' || $zone->availability!=='unavailable' && $zone->availability!=='unknown' && strtolower($zone->zone) == 'sgp' || $zone->availability!=='unavailable' && $zone->availability!=='unknown' && strtolower($zone->zone) == 'syd') | |
{ | |
$str_avai .= $s->reference . " is " . $zone->availability . " in " . $zone->zone . " - Purchase Link: https://eu.soyoustart.com/en/cgi-bin/newOrder/order.cgi?hard=" . $s->reference . "\n"; // Replace link with your country's soyoustart site link | |
} | |
} | |
} | |
} | |
//-- write to cache file to avoid repeated notifications | |
$previous_message = @file_get_contents(TEMP_PREVIOUS_MSG_FILE); | |
if ($str_avai != ''){ | |
if ($str_avai != $previous_message){ | |
if (defined('NOTIFICATION_EMAILS')){ | |
$emails = NOTIFICATION_EMAILS; | |
sendNotificationEmail($emails, $str_avai); | |
} | |
$ff = fopen(TEMP_PREVIOUS_MSG_FILE, "w"); | |
fwrite($ff, $str_avai); | |
fclose($ff); | |
} | |
} else { | |
$ff = fopen(TEMP_PREVIOUS_MSG_FILE, "w"); | |
fwrite($ff, '-'); | |
fclose($ff); | |
} | |
/** | |
* Send email via MAILGUN API | |
*/ | |
function sendNotificationEmail($to, $msg){ | |
if (defined('MAILGUN_API') && MAILGUN == 1) { | |
require dirname(__FILE__) . '/vendor/autoload.php'; | |
$mailgun = new Mailgun\Mailgun(MAILGUN_API); | |
$domain = MAILGUN_DOMAIN; | |
$date = new DateTime('now', new DateTimeZone('UTC')); // replace your timezone here | |
$message = array( | |
'text' => $msg, | |
'subject' => "SoYouStart Availability - " . $date->format('Y-m-d H:i:s'), | |
'from' => "[email protected]", | |
'to' => $to, | |
); | |
$results = $mailgun->sendMessage($domain, $message); | |
} | |
if ( SYSTEM_EMAIL == 1 ) { | |
$mail = mail($to, $message->subject, $msg); | |
} | |
return ; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment