Sending SMS Alerts from Nagios


I am new to linux and nagios, hoping that someone will be able to provide some assistance with a problem I am having.

I have a basic nagios configuration set up on a test network, only monitoring a handful of services on 2 computers and 1 switch.

I am running a Ubuntu 11.04 Virtual Machine as the nagios server.

The problem I am having is with sending SMS alerts.

I have not done anything with email alerts yet, as the network that I will be using nagios on does not have an internet connection.

I have a Nokia Mobile phone handset connected to the Host machine via USB cable for sending the SMS alerts.

I am able to send SMS messages directly from the terminal by using the following command:

/usr/bin/gsmsendsms -d /dev/ttyACM0 +61400111222 "the text of the sms goes here"

That works fine every time, however I am unable to send SMS alerts from nagios.

I have defined a contact in the contacts_nagios2.cfg file as below:

define contact{
       name		generic-contact         		; The nameof this contact template
       service_notification_period     24x7			; service notificationscan be sent anytime
       host_notification_period        24x7                    ; host notificationscan be sent anytime
       service_notification_options    w,u,c,r,f,s             ; sendnotifications for all service states, flapping events, and scheduleddowntime events
       host_notification_options       d,u,r,f,s               ; sendnotifications for all host states, flapping events, and scheduleddowntime events
       service_notification_commands   notify-service-by-sms ; sendservice notifications via SMS      
	host_notification_commands      notify-host-by-sms    ; send	host notifications via SMS
       register                        0                       ; DONT REGISTER THISDEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!

define contact{
	contact_name			contact1
	alias				Mr Jones
	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-sms
	host_notification_commands      notify-host-by-sms
	pager				+61400111222

define contact{
	contact_name			myname
	use				generic-contact
	alias				Mr Jones
	pager				+61400111222

define contactgroup{
        contactgroup_name       admins
        alias                   Nagios Administrators
        members                 contact1

I have defined the command for sending SMS alerts in the commands.cfg file as below:

define command{
	command_name	notify-service-by-sms
	command_line	/usr/bin/gsmsendsms -d /dev/ttyACM0 $CONTACTPAGER$ "Nagios - $NOTIFICATIONTYPE$ : $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ ($OUTPUT$)"

define command{
	command_name notify-host-by-sms
	command_line /usr/bin/gsmsendsms -d /dev/ttyACM0 $CONTACTPAGER$ "Nagios - $NOTIFICATIONTYPE$ : Host $HOSTALIAS$ is $HOSTSTATE$ ($OUTPUT$)"

I have also tried changing the command to the following, just in case any of variables were wrong

define command{
	command_name notify-host-by-sms
	command_line /usr/bin/gsmsendsms -d /dev/ttyACM0 +61400111222 "Nagios - This is a test nagios Alert SMS"

When I restart nagios, I intentionally have a few services and one of the machines I am monitoring turned off
I then look in the nagios web interface and click on any of the critical services. When i click on view notifications for this service, I see the following, which seems to indicate that the command has been run, but no SMS has been sent.

[list] Host Service Type Time Contact Notification Command Information
aws29 04.JSI Task Host CRITICAL 2011-08-30 12:25:09 contact1 notify-service-by-sms CRITICAL: JSI Task Host: stopped (critical)[/list:u]

if anyone can suggest where I might be going wrong, it would be very much appreciated.

As stated earlier, I am new to both linux and nagios, so my apologies if this all just looks like a horrible mess.

At a quick glance everything looks good. Do you have the admins contact group included in the host and service definitions so they are in use? Without binding the group to the templates you want to use there is no way for your messages to get out.

define host{
host_name template
contact_groups admins
register 0
define service{
service_name template
contact_groups admins
register 0

Hi timbCFCA,

Thanks for replying.

I have checked the host and service definations and they are both bound to the admins group

define host{ host_name aws29 alias Workstation29 address check_command check-host-alive max_check_attempts 5 check_period 24x7 process_perf_data 0 retain_nonstatus_information 0 notification_interval 30 notification_period 24x7 notification_options d,u,r hostgroups servers contact_groups admins }

define service{ name generic-service ; The 'name' of this service template active_checks_enabled 1 ; Active service checks are enabled passive_checks_enabled 1 ; Passive service checks are enabled/accepted parallelize_check 1 ; Active service checks should be parallelized (disabling this can lead to major performance problems) obsess_over_service 1 ; We should obsess over this service (if necessary) check_freshness 0 ; Default is to NOT check service 'freshness' notifications_enabled 1 ; Service notifications are enabled event_handler_enabled 1 ; Service event handler is enabled flap_detection_enabled 1 ; Flap detection is enabled failure_prediction_enabled 1 ; Failure prediction is enabled process_perf_data 1 ; Process performance data retain_status_information 1 ; Retain status information across program restarts retain_nonstatus_information 1 ; Retain non-status information across program restarts notification_interval 0 ; Only send notifications on status change by default. is_volatile 0 check_period 24x7 normal_check_interval 5 retry_check_interval 1 max_check_attempts 4 notification_period 24x7 notification_options w,u,c,r contact_groups admins register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE! }

for debug, try sending the output of your gsmsendsms command in the nagios config to a file. Be sure to redirect stderr too.
like so…
command_line /usr/bin/gsmsendsms -d /dev/ttyACM0 +61400111222 “Nagios - This is a test nagios Alert SMS” >> /tmp/test.out 2>&1

Trigger a notification and see what you get for output.

[quote=“derekbrewer”]for debug, try sending the output of your gsmsendsms command in the nagios config to a file. Be sure to redirect stderr too.
like so…
command_line /usr/bin/gsmsendsms -d /dev/ttyACM0 +61400111222 “Nagios - This is a test nagios Alert SMS” >> /tmp/test.out 2>&1

Trigger a notification and see what you get for output.[/quote]

Thanks Derek,

I will do that and post back with the results.

When I run from the command line, the output to the file is:

I tried appending >> /tmp/test.out 2>&1 to the end of the command in the nagios commands definition and then triggered an alert.

No test.out file was generated that time, but according to the nagios web interface, a notification for notify-service-by-sms was sent.

nagios runs a command, if it fails it’s not nagios problem so yes, nagios did indeed send a notification… :slight_smile:

try su - nagios
and then run your smssend from command line. does it work?

Hi Luca,

Thanks so much for your reply.

I tested the sms from the command line as the nagios user, and as you indicated, it did not work.

It gave me an error indication permission to ttyACM0 was denied.

I modified the permissions on ttyAMC0 and tested again from the command line… success :slight_smile:

I then tested again from nagios and it is working beautifully!

Thanks again for your help solving this one :smiley:

happy it worked and thanks for takign the time to post it :slight_smile:

I added SMS functionality to my Nagios System and it was a good choice. I chose Ozeki NG SMS Gateway.