All new World-Text Website! Explore Now

Nagios Alerts by Text Message

Nagios is an open source monitoring application used to watch systems and networks. Correctly configured, it can reliably send email and SMS alerts and escalate them to wider groups if required.

This approach should also work with Icinga and Shinken, though without warranty.

Setting Up Notifications Via World Text

You can download the Perl script from the Nagios Exchange or GitHub, or use the example below as a starting point.

#!/usr/bin/perl
# 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;

GetOptions(
 '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: notify_worldtext_sms.pl --id  --key  --dstaddr  --txt  --sim\n";
 exit(0);
}

my $text = uri_escape($args{txt});
my $baseurl = "http://sms.world-text.com/v2.0";
my $getvars = "id=$args{id}&key=$args{key}&dstaddr=$args{dstaddr}&srcaddr=Nagios&txt=$text";

if(defined($args{sim})) {
 $getvars = "$getvars&sim";
}

my $ua = LWP::UserAgent->new();
my $rsp = $ua->request(PUT "$baseurl/sms/send?$getvars");
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";
}

Simulation Mode

If the sim parameter is included, the World Text API accepts the message and generates a simulated delivery receipt. That lets you test notifications and Nagios escalation flows without being charged for each run.

We recommend testing with simulation first, then doing a final round with live SMS sends to confirm that contact numbers are correct.

Nagios Command Definitions

Replace ACCOUNTID and APIKEY with values from your World Text account.

define command {
        command_name notify-by-sms
        command_line $USER1$/notify_worldtext_sms.pl -i ACCOUNTID -k APIKEY -d $CONTACTPAGER$ -t "NOTIFICATIONTYPE$ $SERVICESTATE$ $SERVICEDESC$ Host($HOSTNAME$) Info($SERVICEOUTPUT$) Date($SHORTDATETIME$)"
}

define command {
        command_name host-notify-by-sms
        command_line $USER1$/notify_worldtext_sms.pl -i ACCOUNTID -k APIKEY -d $CONTACTPAGER$ -t "$NOTIFICATIONTYPE$ $HOSTSTATE$ Host($HOSTALIAS$) Info($HOSTOUTPUT$) Time($SHORTDATETIME$)"
}

Contact Configuration

In your Nagios contacts, add the pager field with the contact’s mobile number in full international format:

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
    email engineer@mydomain.com
    pager 447987xxxxxx
}

You will need an active World Text account to send alerts. For operational alerting, we recommend a small auto top-up so the account does not run out of credits.

Transform Messaging with World-Text

Elevate your communication strategy with World-Text. Seamlessly integrate SMS, RCS, and WhatsApp messaging into your business to enable reliable one-way alerts and dynamic two-way conversations. Engage your customers on their preferred platforms with ease, scalability, and the power of cutting-edge messaging solutions.