Created
February 13, 2018 05:02
-
-
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.
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
#!/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