SMS Notifications from Nagios

Nagios is an open source software application that is used for monitoring systems and networks.

A Little Bit About Nagios

You can watch hosts, services and files. It’s very flexible, giving the ability to monitor a vast range of hardware and software. Probably not the most user-friendly thing to get started with, whilst it’s incredibly flexible, it’s all manually configured – no auto-discover here. There’s a remarkable range of plugins available, and once configured, a Nagios setup can run happily for years with no intervention beyond adding in new devices.

Correctly configured, Nagios is a godsend, keeping track of your whole infrastructure. There’s a webpage you can view for an instant update of the monitoring at any given moment (If you like to see a page of reassuring green indicators), and it can reliably ping you an alert via email and SMS text message when the need arises, escalating the alert to a wider group if not responded to.

Nagios is a proven, mature platform for infrastructure monitoring, and we use it ourselves.

This script should also work with Icinga (A fork of Nagios), and Shinken (A Nagios replacement aimed at better handling high availability and load balancing), but there’s no warranty on that.

Add text messaging and two-way text messaging into your business.

Over 1100+ networks worldwide.

Market leading coverage and specialist support, HTTP, SMPP and SMTP (Email) interfaces.

Easy Use APIs

Premium Support
20+ Years Experience

Free Cloud SMS Software
Communicator Pro

Auto Responder
Auto SMS Processing

Setting It Up To Notify Via World-Text

You can download the perl script from Nagios Exchange or Github

We provide a plugin script to send sms text messages via the HTTP API:

# id = World Text Account ID
# key = World Text secret API key
# dstaddr = Destination mobile number (the number to send SMS to)
# txt = the text message body
use strict;
use JSON;
use LWP::Simple;
use LWP::UserAgent;
use URI::Escape;
use Getopt::Long;
use HTTP::Request::Common;
my %args;
 'help' => \$args{help},
 'id=i' => \$args{id},
 'key=s' => \$args{key},
 'dstaddr=s' => \$args{dstaddr},
 'txt=s' => \$args{txt},
 'sim' => \$args{sim}
if(defined($args{help}) || !defined($args{id}) || !defined($args{key}) || !defined($args{dstaddr}) || !defined($args{txt}) ) {
 print "usage: --id  --key  --dstaddr  --txt  --sim\n";
## URL Encode the text message text
my $text = uri_escape($args{txt});
## Build the URL
my $baseurl = "";
my $getvars = "id=$args{id}&key=$args{key}&dstaddr=$args{dstaddr}&srcaddr=Nagios&txt=$text";
## Has a simulation been requested
if(defined($args{sim})) {
 $getvars = "$getvars&sim";
## Create the user agent and send the request
my $ua = LWP::UserAgent->new();
my $rsp = $ua->request(PUT "$baseurl/sms/send?$getvars");
## Process the response
my $data = decode_json( $rsp->content );
if(${data}->{status} == 0) {
 print "Message sent succesfully to $args{dstaddr}\n";
} else {
 print "Message submission failure: " . ${data}->{desc} . "\n";

One note on the sim parameter in the perl script above. If this is included the World-Text API will accept the message and generate a simulated delivery receipt. This allows you to test notifications, and Nagios escalations etc extensively without incurring a charge every time.

We'd recommend testing with simulated first, then a final round of testing with live SMS sends to ensure you've got all the phone numbers correct!

If you forget and don't remove sim, NO text messages will be sent!

ACCOUNTID and APIKEY are obtained from within your account page. Replace with the values from there.

Define two commands notify-by-sms and host-notify-by-sms as follows:

define command { 
        command_name notify-by-sms 

define command { 
        command_name host-notify-by-sms 

In your contacts add the field "pager" with the contact's mobile number in full international format e.g.

define contact{
    contact_name	engineer
    alias	Support Engineer
    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-by-email,notify-by-sms
    host_notification_commands	host-notify-by-email,host-notify-by-sms
    pager	447987xxxxxx

You will, of course, need an active World-Text account to be able to send alerts from Nagios. If you don't yet have an account, you can open an account here. Obviously, alerting is an important, but (hopefully) occasional need, so we'd recommend an auto top-up of a small amount on the account so you don't accidentally run out of credits!