Configuring Nagios3 push notifications

This is a quick howto that explains how to add NotifyMyAndroid push notifications on 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 My Account page. To get one, login with your account then go to "My Account". If you don't see an API key on the right side of the page, click on the "Generate New Key" Button and one should appear on your list.
  • Notify My Android installed on your Android device. You can get it on the Marketplace .
  • Download NMA Perl script and save it to /usr/local/bin/nma.pl. Remember to add exec permission: sudo chmod +x /usr/local/bin/nma.pl.
  • 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/nma.pl -apikey='yourAPIkeyHere' -application='/nma.html' -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/nma.pl -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/nma.pl -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 nma.pl 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/nma.pl: "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.