Skip to content

Instantly share code, notes, and snippets.

@Bojak4616
Created February 13, 2018 05:02
Show Gist options
  • Save Bojak4616/e2ef00c537eed95f262409ac2cd5853e to your computer and use it in GitHub Desktop.
Save Bojak4616/e2ef00c537eed95f262409ac2cd5853e to your computer and use it in GitHub Desktop.
Ping host to see if it's up. If it's not, use Pushbullet to send you a notification.
#!/usr/bin/python
import subprocess
# Follow https://docs.pushbullet.com/#api-quick-start to get free token
TOKEN = ""
HOST_ADDRESS = ""
BASE_URL = "https://api.pushbullet.com/v2/"
data = '{"type":"note","title":"Sia","body":"Sia Host is Down!!"}'
try:
subprocess.check_call(["ping", "-c", "1", HOST_ADDRESS])
except subprocess.CalledProcessError:
r = subprocess.check_output(["curl", "--header", 'Access-Token: {}'.format(TOKEN), "--header", "Content-Type: application/json",
"--data-binary", data, "--request", "POST", '{}pushes'.format(BASE_URL)])
print r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment