As a developer or sysadmin, you often find yourself wanting to send notifications to yourself or others, when certain events occur. For example: if your web application encounters a critical error, or a server is not responding, you want to know about it as fast as possible. Of course you can use an SMS provider to send a message to your phone. But sending SMS messages is still not free, and most providers use API’s that are not very flexible. Enter Pushover: a web service combined with mobile app, to send free (not counting the one-time purchase of the app) push notifications to smartphones.
Pushover has two very appealing USP’s: it’s free, and it’s extremely easy to implement on any platform, in any situation. This is illustrated by the few simple steps you need to take to get up and running.
- Go to pushover.net and sign-up for a free account. It’s as simple as entering your e-mail address and choosing a password.
- Take your smartphone and download the Pushover app (available on iPhone/iPad App Store and Android Play Store). When starting the app for the first time, enter your e-mail address, password, and a name for your device. This allows you to recognize your device if you decide to add more devices to your account later, and allows you to send messages to a sub-set of those devices. For example, you cloud have two devices named “iPhone” and “iPad” and send high-priority notifications to both, and low priority ones only to the iPad.
- On your PC, log in to the Pushover website. You now enter your dashboard. This is where the magic happens 😉
From the dashboard, you can send a test notification to yourself, just to see if everything is correctly installed. That’s it, your ready for business! Read on to see how you can setup some real notifications.
You can integrate Pushover into almost any application, script, etc. by using either their REST API, or by sending e-mails to your personalized Pushover e-mail address (which looks something like “5Had0f311FwopfA@api.pushover.net”). Below are a couple of examples of sending a Pushover message through different programming languages. Pushover provides sample code for al lot of programming languages.
Before you fire up your IDE though, you first need to register a new application in your Pushover dashboard. Every app gets a unique API key, and is allowed to send 7,500 notifications a month, completely for free. You can create an unlimited number of applications in your account, so really: the sky is the limit here. After your done registering the application, copy your Application Key and your User Key, and put them in an empty textfile, or somewhere else you can find it for the next steps.
Example in PHP
All you need is a PHP enabled server, with the cURL module installed. Create a new file (or open an existing one), copy/paste the following code, and replace “APP_TOKEN” with your Application Key, and “USER_KEY” with your User Key. Execute the script, and voilà: you’ve just sent your very first push notification!
<?php curl_setopt_array($ch = curl_init(), array( CURLOPT_URL => "https://api.pushover.net/1/messages.json", CURLOPT_POSTFIELDS => array( "token" => "APP_TOKEN", "user" => "USER_KEY", "message" => "hello world", ))); curl_exec($ch); curl_close($ch); ?>
Example through the commandline
Of course, using cURL you can just as easily send notifications right from the commandline in Linux, Windows, or other operating systems:
curl -s \ --cacert ca-bundle.crt \ -F "token=APP_TOKEN" \ -F "user=USER_KEY" \ -F "message=hello world" \ https://api.pushover.net/1/messages.json
These are just very basic examples. If you really want to get creative, there’s more to know:
- A notification can have a maximum of 512 characters (counting both the title and the message body.
- You can also provide a supplementary URL. This allows a recipient to click through to a specified URL, for more information.
- A user can set “Quiet hours”, during which only high priority messages will be let through. All other messages are queued until the “quiet hours” end. When sending a message, use the priority field to indicate if a message has high priority or not.
- Using the timestamp field, you can have your message show a particular time, rather than the time it was sent.
- You can send a message to a certain device, identified by the device name. If you don’t specify a device name, the message gets sent to all active devices in your account.
For further reading, check out the API documentation. This also covers error handling, key validation, and more advanced topics.
Because of Pushover’s simple API it can be used for virtually anything. I personally have set it up to:
- Have my home-server send me a notification every night, with the results of my SyncBack backup (both success and failure messages).
- The server that hosts this very blog notifies me every night upon completion of both the MySQL and file backups.
- CopperEgg (a cloud server monitoring tool) send me notifications if the server is offline, slowing down, running out of memory, etcetera.
- By using IFTTT (which is an absolutely great service by the way!) I get notified when tomorrow’s weather forecast calls for snow (so I can anticipate the heavier traffic on my daily commute)
- Notify me when SickBeard downloads a new episode of one of my favorite TV shows (SickBeard has built-in Pushover support)
These are just a few examples of what’s possible. The only real limit on what’s possible is your own imagination! I hope this article helps get you started.