Sending push notifications to my phone

I had an XMPP server which I used to send Nagios notifications to my phone using XMPP messages. I also hoped to use it for chatting with people, but since everyone uses locked in systems like Facebook and Skype that don't support federation I decided to stop using XMPP.

I decided to use the service Pushover.net instead which is has a mobile app for receiving push notifications.

It works great, you register you app on the website and your device from your mobile. After that it's just a simple HTTP POST request away from sending push messages.

I created a small python script which I use in my Nagios system that sends the alert through Pushover. It's in my github script repo.

Send-Pushover (Check the repo for the latest version)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/env python3

import argparse
import requests
import sys

def push_message(message, app, user):
        data = { "token": app, "user": user, "message": message }
        r = requests.post("https://api.pushover.net/1/messages.json", params=data)

def main(argv):
    parser = argparse.ArgumentParser(description="Push message with Pushover.net")
    parser.add_argument('-a', dest='app_id', required=True, help="Application ID")
    parser.add_argument('-u', dest='user_id', required=True, help="User ID")
    parser.add_argument('-m', dest='message', required=False, default='', help="Message to send, can also be read from stdin")
    args = parser.parse_args(argv)

    if (args.message == '') and not sys.stdin.isatty():
        for line in sys.stdin:
            args.message = args.message + line

    push_message(args.message, args.app_id, args.user_id)

if __name__ == "__main__":
    main(sys.argv[1:])