Tuesday, March 2, 2010

Sending SMS Notifications From Nagios

In my last article I have discuses how to install Gnokii for sending/receiving SMS from your computer. Today I'll explain how we are using Gnokii + Nagios for sending SMS notifications to our cell phones. Its a great way to get notify of the problems while on road.

I assume that you have working Nagios and its monitoring the devices in your infrastructure and sending notifications via Email and you are looking how to get these problem notifications on your phones.

Gnokii is also working and you can send SMS from CLI.

Lets cut it short and back to actual business.

In my setup we have Nagios and Gnokii install on same host running Centos 5.4, but it can easily be followed for any other Linux distro or even with setup where Gnokii is install on separate host.

1. Make sure you can send SMS from CLI with "gnokii --sendsms +92xxxxx" using root or the user under which Nagios process is running normally its 'nagios' user, sending under nagios user requires to add nagios to groups which have permission to access the device files.

a) So add nagios to 'uucp' group (you can do this with usermod command)

Gnokii also acquire a lock under /var/lock

b) So add nagios user to 'lock' group also.

su to nagios user and send sms from CLI using gnokii --sendsms, when it works move forward for defining commands.

2. Define command for send notification via SMS in commands.cfg

# 'notify-service-by-sms' command definition
define command{
command_name notify-service-by-sms
command_line /usr/bin/printf "%.120s" "*** Nagios Alert*** $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$" | /usr/local/bin/gnokii --sendsms $CONTACTPAGER$
}

# 'notify-host-by-sms' command definition
define command{
command_name notify-host-by-sms
command_line /usr/bin/printf "%.120s" "*** Nagios Alert*** $NOTIFICATIONTYPE$ : Host $HOSTALIAS$ is $HOSTSTATE$" | /usr/local/bin/gnokii --sendsms $CONTACTPAGER$
}

3. Modify contacts.cfg and add or modify a contact by calling new commands

define contact{
contact_name askarali
use generic-contact
alias Askar Ali Khan
email emailaddress
pager +92xxxxxx
service_notification_commands notify-service-by-email,notify-service-by-sms
host_notification_commands notify-host-by-email,notify-host-by-sms
}

The key in the contact detail is the service/host notifications commands

service_notification_commands notify-service-by-email,notify-service-by-sms
host_notification_commands notify-host-by-email,notify-host-by-sms

I have configured a contact so that he can receive notifications via Email 'notify-service-by-email' as well as via SMS 'notify-service-by-sms'


That's all, finally reload nagios, before reload better to run syntax check

'nagios -v PathTo nagios.cfg'

and then reload

/etc/init.d/nagios reload

Now Nagios will send SMS notifications on your phone whenever there is problem with any host/service which being monitor with Nagios.

I hope this could help.

32 comments:

  1. Thanks Ali, that helped alot!

    ReplyDelete
  2. Do you know TeamTILT ? This is a little java client to install on your Nagios server. No Modem or other things are needed ! The alerts are relayed on several medias like SMS, Voice call or iPhone push !

    Check www.alarmtilt.com/nagios

    It is also available for Centreon and Zenoss ;) !

    ReplyDelete
  3. Please Help.
    Im getting this error "notify-service-by-sms;Connection refused".
    How can I solve this.

    ReplyDelete
    Replies
    1. These configurations are hectic and sometimes they dont work. The best is to try Nagios SMS Notification. It sends out SMS text message to you whenever you get email from nagios. Its fast and works in more than 200 counties. Try it.

      Delete
  4. Hi,

    can we send sms notifications to 3 administrator i.e. for 3 different mobiles numbers

    ReplyDelete
  5. Yes you can send as many sms notifications to number of Admins..

    For this you need to create a contact and add that contact to contactgroup please refer to nagios docs for more detail

    ReplyDelete
  6. [1326368152] HOST NOTIFICATION: nagiosadmin;CTD Router Backup WAN Interface;DOWN;notify-host-by-sms;(Host Check Timed Out)

    [1326368152] HOST NOTIFICATION: nagiosadmin;CTD Router Backup WAN Interface;DOWN;notify-host-by-email;(Host Check Timed Out)

    Unable to receive sms but nagios log is showing me above logs. Kindly help me to resolve this issue.

    ReplyDelete
    Replies
    1. Hi Nishith,
      sorry for late reply, i am afraid i'll not be able to help you coz these days i am busy with my work. i would advice you to check with nagios mailing list and i am sure you will get your problem solved
      thanks

      Delete
  7. I have getting this log from nagios but sms not comming. What can I do now??

    [1333624622] SERVICE NOTIFICATION: nagiosadmin;smtp.test.com;Root Partition;OK;notify-service-by-sms;DISK OK - free space: / 16131 MB (83% inode=97%)



    Mosharaf

    ReplyDelete
  8. I have getting this log from nagios but sms not comming. What can I do now??

    [1333624622] SERVICE NOTIFICATION: nagiosadmin;smtp.test.com;Root Partition;OK;notify-service-by-sms;DISK OK - free space: / 16131 MB (83% inode=97%)

    ReplyDelete
  9. Wow! so Brilliant! As I was reading your post my head is having question marks, Anyways I'll re read these. Hope I can get this for me to send SMS. Thanks so much for the post Ali.. Your Blog was so helpful!

    morning greetings | love messages | friendly SMS | text message

    ReplyDelete
    Replies
    1. Hey thanks man, hope you will get sending SMS notifications working its easy ;)

      Delete
  10. This comment has been removed by a blog administrator.

    ReplyDelete
  11. This comment has been removed by a blog administrator.

    ReplyDelete
  12. Hii do you know how to integrate mrtg with nagios, that is, how to display the nagios output into mrtg graph?

    Thanks for the help

    ReplyDelete
    Replies
    1. Look into pnp4nagios.org its a nice addon addon to Nagios which analyzes performance data provided by plugins and stores them automatically into RRD-databases.

      Delete
  13. Assallamu alikum

    can i install nagios and gnokii in a different machine? if so please tell me the procedures to perform.

    thanks

    ReplyDelete
    Replies
    1. Yes its can be done by enabling ssh-key authentication between the two machines this enable nagios to call 'gnokii' command from another machine.

      Delete
  14. Nice post with great details. I really appreciate your work. Thanks for sharing.

    emergency mass notification software

    ReplyDelete
  15. Thanks for the bunch of good resourceful site.I really appreciate your blog,
    you have done the great job.
    cool fb status
    best fb status
    condolence messages

    ReplyDelete
  16. hey your blog design is very nice,
    clean and fresh and with updated content, make people feel peace and I always like browsing your site.

    charoli
    semolina benefits
    lassi benefits
    amla candy benefits
    tulsi benefits
    rice flakes

    ReplyDelete

  17. Your Blog post has very helpful information.
    Thanks for share....

    Send Bulk SMS Software

    ReplyDelete
  18. What to do if your server went down? Your selling site will be stop. But if you will order in advance SMS monitoring on http://www.intistele.com/, you can anticipate loss of money.

    ReplyDelete
  19. www.raviparscha.com
    http://www.raviparscha.com/janiye-nimbu-pani-ke-gunkari-labh-balo-sehat-skin-ke-liye-hindi.html

    ReplyDelete
  20. I don't know that how to use these apps. Can you give me some suggestion through by your post. Thanks
    จีคลับ
    gclub
    gclub casino

    ReplyDelete