Push Notifications With PRTG And Pushover

PushoverIntroduction

I was looking for a way for my PRTG installation to alert me whenever I was away from home.  I initially thought of using an “email to SMS message” service, and started looking into this option.  I was then pointed to an API push service called Pushover.

Setting this up to work with PRTG is amazingly simple.  The instructions and scripts I use are taken from this blog, just cleaned up a bit and with more screenshots.

 

Prerequisites

A Pushover account,

Install Python for Windows onto your PRTG server.  Choose Python 2, not 3.

An Android or Apple device with the Pushover app installed,

store-google   store-apple

 

Pushover Instructions

Once you have created your account and verified your email address, you need to create an application in-order to get an API key.

  1. pushover - 1From your main home page,
  2. Next to Your Applications, click Register An Application,
  3. Fill out the displayed form, my entries were…
    • PRTG
    • Application
    • (blank)
    • This image (click to enlarge) – PRTG-75x75
  4. Tick the Terms Of Service check box and click Create Application.

Once the application has been created, you will be presented with an API Key.  You will need this later, along with your User Key.

 

Device Setup

Depending on your device, download the appropriate app and install it.  Log in to the app, and check the settings to see if you need to change anything, specifically the Edit Quiet Hours.

 

Python Scripts

Log on yo your PRTG server, and install Python.  This is a very straight forward installation…

python install - 1   python install - 2   python install - 3   python install - 4   python install - 5

Once done, we need to create two plain text files into the following folder…

C:\Program Files (x86)\PRTG Network Monitor\Notifications\EXE

 

File 1 – pushover.bat

Create a file called pushover.bat and enter the following code…

C:\Python27\Python "C:\Program Files (x86)\PRTG Network Monitor\Notifications\EXE\pushover.py" %*

Change the listed paths if required.

 

File 2 – pushover.py

Create a file called pushover.py and enter the following code…

import httplib, urllib, sys
 
apiKey = sys.argv[1]
userKey = sys.argv[2]
priority = sys.argv[3]
title = sys.argv[4]
msg = ''
 
for count, arg in enumerate(sys.argv):
    if count > 4:
        msg += arg + '\n'
 
conn = httplib.HTTPSConnection("api.pushover.net:443")
conn.request("POST", "/1/messages.json",
    urllib.urlencode({
        "token": apiKey,
        "user": userKey,
        "message": msg,
        "title": title,
        "priority": priority,
        "retry":"30",
        "expire":"3600"
    }),
    { "Content-type": "application/x-www-form-urlencoded" })
response = conn.getresponse()

 

PRTG Setup

Part one

  1. From your PRTG console,
  2. Click Setup > Account Settings > Notifications,
  3. Click the ‘Add New Notification‘ button on the bottom left,
  4. Add a name for your notification – PRTG – ALERT,
  5. Scroll down and check the Execute Program box,
  6. Choose pushover.bat from the dropdown,
  7. Enter the parameters as follows:

[api-key] [user-key] [priority] “%device – %name : %status” “ALERT/ERROR” “Msg: %message”

Example:  abcd1234efgh5678 ab12cd34ef56gh78 0 “%device – %name : %status” “ALERT/ERROR” “Msg: %message”

(For a list of priority values, check out the Pushover FAQs)

  1. Click Save,
  2. Click Test, and you should receive an alert on your device almost immediately.

 pushover - alarmtest

I have three alerts set up..

  • ALERT/ERROR
  • WARNING
  • ALL OK

 

Part two

Now that we have an alert or three setup, we need to make sure your devices start using them.  For my small setup, I set my notifications at the top level, at the Local Probe…

  1. From the PRTG console, select the Local Probe device (or other device if you want more control),
  2. Select the Notifications tab along the top,
  3. Click Add State Trigger,
  4. From the new trigger then appears, choose the options that bests suits you and your environment.  The no notification drop down should list the alerts you setup above.

prtg notifications - 1

The values I have are shown below…

prtg notifications - 2

 

Errors / Issues / Troubleshooting

When I initially set this up the alerts were not coming though.  In order to troubleshoot this issue, I ran the pushover.py script manually.  Do do this…

  1. Open a command prompt on your PRTG server,
  2. Type the following command into the window…
C:\Python27\Python "C:\Program Files (x86)\PRTG Network Monitor\Notifications\EXE\pushover.py" [api-key] [user-key] 0 "Manual Test" "Ignore This Message"

…making sure to enter your API Key and User Key in the correct locations

  1. You should see no output if everything works OK.

In my case, I got SSL handshake errors.  To fix this, I just visited the Pushover API site (https://api.pushover.net) in order for my server to download the SSL certificate.

 

More Pushover Configuration

I have added another post about using Pushover notifications with my Synology DiskStation and VMware vCenter Alerts.  Read about it here.

6 thoughts on “Push Notifications With PRTG And Pushover

  1. Barry says:

    Just found this post after wanting to do the same. But, it’s even easier now.

    Click on ‘execute http action’.
    For URL, enter: https://api.pushover.net/1/messages.json
    For Postdata, enter:
    token=&user=&message=application=[%sitename],event=%status,description=%device %name %status %down (%message) —— Last Result: %lastvalue Date/Time: %datetime Timezone: %timezone

    NB: I’ve tweaked the info at http://kb.paessler.com/en/topic/1693-how-can-i-send-push-notifications-from-prtg-to-iphones to build up the data that is posted to Pushover.

  2. Andrew says:

    Can multiple user keys be entered so the notifications will go to several people at once?

  3. Hi,

    This is Kimberley from Paessler (the vendor behind PRTG). Thanks for such a cool post! Just wanted to let you know that PRTG now includes native push notifications to iOS and Android, so you might want to check them out as an alternate method for receiving push notifications:
    https://kb.paessler.com/en/topic/60892-how-can-i-use-push-notifications-with-prtg

    All the best,

    Kimberley

Leave a Reply

Your email address will not be published. Required fields are marked *