# Setting up nagios3 to send prowl notifications

Updated 27.i.2010 to reflect mig5’s corrections

I spent a few minutes today setting up our nagios install at work to page me via prowl, instead of an email->sms gateway. Why? Because I’m cheap, that’s why - don’t like paying for any more texts than I must. I ran into a few gotchas, so I thought I would briefly document the process.

sudo mkdir -p /usr/local/bin
sudo wget -O /usr/local/bin/prowl.pl <a href="http://prowl.weks.net/static/prowl.pl
sudo">http://prowl.weks.net/static/prowl.pl
sudo</a> chmod +x /usr/local/bin/prowl.pl

Next, you will have to install the Crypt::SSLeay and LWP::UserAgent library for perl, so it can access https URLs.

# If you're running debian/ubuntu
sudo apt-get update; sudo apt-get install libcrypt-ssleay-perl liblwp-useragent-determined-perl
# otherwise find a package for your distro, or run:
# sudo cpan install Crypt::SSLeay
# sudo cpan install LWP::UserAgent

Now, try it out to be sure it works:

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

You should get a ‘Notification successfully posted.’ message. (and a popup 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{
_prowl_apikey                   yourAPIkeyGoesHere
}

It is very important that you leave the underscore in front of the _prowl_apikey variable, as Nagios’ custom variables depend on it.

Next, you’ll need to add the custom prowl notification commands. Edit the appropriate file, and add these commands:

define command{
command_name notify-host-by-prowl
command_line /usr/bin/perl -w /usr/local/bin/prowl.pl -apikey="$_CONTACTPROWL_APIKEY$" -priority=1 -application="Nagios" -event="Host" -notification="$HOSTNAME$ $HOSTDESC$ '$HOSTOUTPUT$'"
}

define command{
command_name notify-service-by-prowl
command_line /usr/bin/perl -w /usr/local/bin/prowl.pl -apikey="$_CONTACTPROWL_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 prowl.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/prowl.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.

Just a quick note…

I wanted to let you know this guide helped me a bunch when setting up Nagios to prowl. I was linked here from iNag (which is also an awesome app!)

Thanks for sharing! Rob

Just in the middle of setting up the same thing. Thanks for your excellent guide.

Just thought I’d note that if you’re on Debian/Ubuntu, you’ll also need to apt-get install liblwp-useragent-determined-perl if you haven’t got it already, or else Perl will die with this error:

Can't locate LWP/UserAgent.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.10.0 /usr/local/share/perl/5.10.0 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl .) at /usr/local/bin/prowl.pl line 33. BEGIN failed--compilation aborted at /usr/local/bin/prowl.pl line 33.

Sorry, just nitpicking..

Your host command definition in the example is using $SERVICEDESC$ ‘$SERVICEOUTPUT$’ instead of $HOSTDESC$ $HOSTOUTPUT$, these would result in empty variables in the prowl message.

Also the path to your prowl.pl in the command definitions is /usr/local/nagios3/libexec, but previously we wget it to /usr/local/bin

Otherwise, great! Thanks again.

I recently installed the notify by prowl code. I can get the test message through the linux console but, when i run it through nagios it does not work. any ideas? Here is the command verbage.

# ‘notify-host-by-prowl’ command definition

define command{ command_name notify-host-by-prowl command_line /usr/bin/perl -w /usr/local/bin/prowl.pl -apikey=”$_CONTACTPROWL_APIKEY$” -priority=1 -application=”Nagios” -event=”Host” -notification=”$HOSTNAME$ $HOSTDESC$ ‘$HOSTOUTPUT$’” }

# ‘notify-service-by-prowl’ command definition

define command{ command_name notify-service-by-prowl command_line /usr/bin/perl -w /usr/local/bin/prowl.pl -apikey=”$_CONTACTPROWL_APIKEY$” -priority=1 -application=”Nagios” -event=”Service” -notification=”$HOSTNAME$ $SERVICEDESC$ ‘$SERVICEOUTPUT$’” }

Hi! Thanks for this. Rocks on my system. Query about an improvement (that might not be possible).

Prowl on my iPhone let’s me quiet it during nights unless I get an “emergency”. I know I cant priority to 2 and get that. But is it possible, somehow, to set priority based on severity from Nagios?

Ie. Warning = Priority 1, Info = Priority 0, Critical = Priority 2.. If it is possible somehow.. I’d love it. Why? Because I don’t need to run to my computer if it’s a warning or information - only when theres an emergency..

glad it’s working for you! I can think of two ways to accomplish this - the first would be to write a wrapper script that sets the priority based on the input, and call that instead. The second is what I do - I use nagios escalations so that only the truly critical notifications get sent directly to my phone, and deal with the rest via email.

good luck!

thanks! works like a charm!

Awesome post, works great. But I am cheap and lazy (well too busy to edit cfg in vi every time I add a host)

Do you have any idea on how to incorporate prowl into Opsview ? I have tried but for the life of me, the cfg for Opsview is no where near Nagios, or Icinga or Monarch. I have gotten as far as finding where I should put the config for the custom notification, but actually getting it to work is another story.

Cheers for the help.

W

1. define contact{