Notifo is a great service for sending notifications, in this case to a phone using the mobile app.
To use Notifo with Nagios there’s two solutions. The first (and the easiest one), is to configure Nagios to send emails to the email address provided by Notify. The other (and the one described here), is to configure Nagios to execute a scripts that sends a POST request to the Notifo API.
I’ll asume that you have a working Nagios setup, a Notify account, the client installed and configured on your phone, and your Notifo API key handy.
Lets start by adding two commands to the Nagios configuration, depending on your setup this can be done in many places. If there’s a commands.cfg file present that’s probably a good place to put it. Open the file and add the following:
define command {
command_name notify-host-by-notifo
command_line /usr/bin/perl /usr/local/bin/notifo -username="$_CONTACTNOTIFO_USERNAME$" -apikey="$_CONTACTNOTIFO_APIKEY$" -title="Host" -msg="$HOSTNAME$ $HOSTSTATE$ '$HOSTOUTPUT$'"
}
define command {
command_name notify-service-by-notifo
command_line /usr/bin/perl /usr/local/bin/notifo -username="$_CONTACTNOTIFO_USERNAME$" -apikey="$_CONTACTNOTIFO_APIKEY$" -title="Service" -msg="$HOSTNAME$ $SERVICEDESC$ $SERVICESTATE$ '$SERVICEOUTPUT$'"
}
Then find the file containing the contact you want to use, and add the Notify username and password. Also modify the host and service notification commands. The result should be something like this:
define contact {
contact_name admin
alias Administrator
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,r
service_notification_commands notify-service-by-email,notify-service-by-notifo
host_notification_commands notify-host-by-email,notify-host-by-notifo
email <EMAIL>
_notifo_username <USERNAME>
_notifo_apikey <APIKEY>
}
Of course, make sure you use your own name, email and Notifo credentials.
Then save the following script as /usr/local/bin/notifo (or whatever you want, make sure it’s the same path as the one configured above).
#!/usr/bin/perl use strict; use warnings; use HTTP::Request::Common qw(POST); use LWP::UserAgent; use Getopt::Long; # Get options my %options = (); GetOptions(\%options, 'username=s', 'apikey=s', 'title=s', 'msg=s'); # URL encode msg $options{'msg'} =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg; # The request my $req = POST 'https://api.notifo.com/v1/send_notification', [ 'msg' => $options{'msg'}, 'label' => 'Nagios', 'title' => $options{'title'} ]; # Add auth to the request $req->authorization_basic($options{'username'}, $options{'apikey'}); # Do it my $ua = LWP::UserAgent->new; $ua->request($req);
Make the script executable.
# chmod +x /usr/local/bin/notifo
Try the script to make sure it works.
# /usr/bin/perl /usr/local/bin/notifo -username=<USERNAME> -apikey=<APIKEY> -title=Test -msg=Test
Reload Nagios, depending on your configuration this can be done in many ways, usually it’s the following command.
# /etc/init.d/nagios3 restart
That’s it.

Now, when something goes wrong, you’ll be notified immediately.
