Tired of checking every day the dedicated server availability of So You Start? Yeah, I got tired too so I decided to create a custom script to help me on this.
I tried other services without luck so I decided to share this script hoping it will make your life easier and happier!
What you need:
- Linux Server with installed
- curl
- sed
- jsawk (it needs spidermonkey installed, so for Ubuntu users just install the packages libmozjs-24-bin, libmozjs-24-dev, libmozjs-24-0)
If jsawk returns “js command not found”, create a symbolic link with:
sudo ln -s /usr/bin/js24 /usr/bin/js
- Mailgun (I used mailgun to make my life easier, but you can choose other ways to send the e-mail notification)
Here below the bash code I wrote:
[code lang=”bash”]#!/bin/bash
server=”143sys4″
func () {
curl –silent https://ws.ovh.com/dedicated/r2/ws.dispatcher/getAvailability2?callback=Request.JSONP.request_map.request_0 | sed ‘s/Request.JSONP.request_map.request_0(//’ | sed ‘s/);//’ | jsawk ‘for(var availability=””,d=0;d<this.answer.availability.length;d++)if(“$server”===this.answer.availability[d].reference)for(var thisisyou=this.answer.availability[d],c=0;c<thisisyou.metaZones.length;c++)”unavailable”!==thisisyou.metaZones[c][/c].availability&&(availability+=”Zone “+c+”: “+thisisyou.metaZones[c][/c].zone+”\n”);return availability;’
}
var=$(func)
if [ “$var” != “” ]
then
curl -s –user ‘api:key-XXXXXXXXXXXXXXXXXXXXX’ https://api.mailgun.net/v3/domain.com/messages -F from=’Name Surname <[email protected]>’ -F [email protected] -F subject=’SOYOUSTART ALERT’ -F text=$var
fi
[/code]
Things to change in the code:
- Line 2 – “server” variable: this value needs to be changed depending on the server you’re interested to check.
How to retrieve this code? Directly from the HTML template of http://www.soyoustart.com/en/essential-servers/
The previous image is an example of how to retrieve the server code for the Server SYS-IP-1. - Line 9 – MailGun API key and URL: as I already said, I used mailgun to simplify the email submit, you can change it with the service/command you prefer.
A valid alternative could be using the ancient “mail” command (if not already installed sudo apt-get install mailutils)
Then change the Curl call with:
echo $var | mail -s “SOYOUSTART ALERT” [email protected]
Last steps:
- make the bash file executable (of course 🙂
- add it to the crontab
That’s it 🙂