Configuring Nagios3 push notifications

This is a quick howto that explains how to add NotifyMyAndroid push notifications to your Nagios3.

It is based on the original Prowl guide available here.

Before we start, you will need:

  • Notify My Android Account (So you can get an API Key). You can register here .
  • Generate your API key on your Account page.
  • Notify My Android installed on your Android device. You can get it on Google Play .
  • Download NMA Perl script and save it to /usr/local/bin/ Remember to add exec permission: sudo chmod +x /usr/local/bin/
  • You need Perl SSL encryption package to send notifications with HTTPS. The required lib names are: Crypt::SSLeay and LWP::UserAgent On Ubuntu: apt-get install libcrypt-ssleay-perl liblwp-useragent-determined-perl. On CentOS/Fedora: yum install openssl-perl.
  • To make sure it is working, try :

/usr/local/bin/ -apikey='yourAPIkeyHere' -application='' -event='test' -notification='mic check 1 2'

You should get a 'Notification successfully posted.' message (and a notification on your phone, of course!). If the script isn't working, you'll have to figure out the reason, because Nagios depends on it. Once you've ironed all that out, it's time to configure Nagios! First, you need to set up your contact information. Edit whichever file you keep your contacts in, and modify an existing record, or add a new one, similar to this:

define contact{
    contact_name                    paul_pager
    alias                           John Paul
    service_notification_period     24x7
    host_notification_period        24x7
    service_notification_options    w,u,c,r
    host_notification_options       d,u,r
    service_notification_commands   notify-service-by-nma
    host_notification_commands      notify-host-by-nma
    _nma_apikey                     yourAPIkeyGoesHere

It is very important that you leave the underscore in front of the _nma_apikey variable, as Nagios' custom variables depend on it. Next, you'll need to add the custom NotifyMyAndroid notification commands. Edit the appropriate file, and add these commands:

define command{
        command_name notify-host-by-nma
        command_line /usr/bin/perl -w /usr/local/bin/ -apikey="$_CONTACTNMA_APIKEY$" -priority=1 -application="Nagios" -event="Host" -notification="$HOSTNAME$ $HOSTDESC$ '$HOSTOUTPUT$'"
define command{
        command_name notify-service-by-nma
        command_line /usr/bin/perl -w /usr/local/bin/ -apikey="$_CONTACTNMA_APIKEY$" -priority=1 -application="Nagios" -event="Service" -notification="$HOSTNAME$ $SERVICEDESC$ '$SERVICEOUTPUT$'"

If your perl binary doesn't live in /usr/bin, be sure to give the correct path. (run 'which perl' to find this out if you don't know) If you try to run the script directly, (without using the system perl binary) nagios uses its own perl interpreter, and you'll get an error similar to this in the nagios logs:

*ePN failed to compile /usr/local/bin/ "Missing right curly or square bracket at (eval 1) line 95, at end of line syntax error at (eval 1) line 102, at EOF"

If you have any trouble, check the nagios debug logs, (you may need to turn up the nagios debug level) and try to run the command it's producing as the nagios user.