Skip to content

Instantly share code, notes, and snippets.

@maop
Created December 10, 2015 02:11
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maop/30b15c1f44267d91c4c4 to your computer and use it in GitHub Desktop.
Save maop/30b15c1f44267d91c4c4 to your computer and use it in GitHub Desktop.
Python Script for watching SoYouStart.com server availability, it can watch many servers at many datacenters and notify by email
#!/usr/bin/env python
# I was in a hurry for a SYS server so i make this quick script,
# notice that you have to use codes from the "us" version, since server's id
# are different in the Europe versions of ovh sites
# You'll receive notification mails like this:
#
# 141cabk1 | BK-8T: Intel i3 2130 2c/4t 3.4 GHz+ 8 GB 2x4 TB SATA
# AVAILABLE (1H-low) in gra
# AVAILABLE (1H-low) in sbg
# AVAILABLE (1H-low) in bhs
#
# 143casys2 | E3-SAT-3: Intel Xeon E3 1245v2 4c/8t 3.4 GHz+ 32 GB 2x2 TB SATA
# AVAILABLE (1H-low) in sbg
#
# And yes this script will send a mail for every time you run it, as i said i was in a hurry,
# maybe later i'll add a flag system that only sends mails on server status changes ;)
import json
import urllib
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
# CHANGE THIS DATA:
# Server IDS to monitor (you have to obtain the IDs from the source code of https://www.soyoustart.com/us/essential-servers/ )
server_ids = [ '143casys2' , '143casys11' ]
# Prefered datacenters: bhs, sbg, gra, rbx, etc...
dc_zones = ['bhs']
# mail settings
mail_server = "mail.server.tld"
mail_user = "user@mail.tld"
mail_pass = "h4x0rP4ss"
mail_to = "receiver@mail.tld" # this is the mail where notifications will be send to
#If you want description of the servers
desc = {
'143casys2': 'E3-SAT-3: Intel Xeon E3 1245v2 4c/8t 3.4 GHz+ 32 GB 2x2 TB SATA | $56.00',
'143casys11': 'E3-SSD-3: Intel Xeon E3 1245v2 4c/8t 3.4 GHz+ 32 GB 3x120 GB SSD | $56.00',
'141cabk1': 'BK-8T: Intel i3 2130 2c/4t 3.4 GHz+ 8 GB 2x4 TB SATA | $69.00'
}
# Start Main Script
soyoustart_json = urllib.urlopen("http://ws.ovh.ca/dedicated/r2/ws.dispatcher/getAvailability2")
parsed_json = json.loads(soyoustart_json.read())
available_servers = []
for i in parsed_json["answer"]["availability"]:
if i["reference"] in server_ids: #["reference"] has the server id
s = "\n{0} | {1}".format(i["reference"], desc[i["reference"]])
sz = ""
for j in i["zones"]:
if j["zone"] in dc_zones: #["zone"] has the datacenter code
if j["availability"] != "unknown" and j["availability"] != "unavailable":
sz = sz + "\nAVAILABLE ({0}) in {1}".format(j["availability"], j["zone"])
if sz:
available_servers.append(s+sz)
if available_servers:
msg = MIMEMultipart()
msg["From"] = mail_user
msg["To"] = mail_to
msg["Subject"] = "SoYouStart Servers Available!"
body = "\n".join(available_servers)
msg.attach(MIMEText(body, 'plain'))
smtp_server = smtplib.SMTP(mail_server, 587)
smtp_server.starttls()
smtp_server.login(mail_user, mail_pass)
smtp_server.sendmail(mail_user, mail_to, msg.as_string())
smtp_server.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment