Views

SkypeSmsNotification

Follow Nagios Community Posting On Twitter

From Nagios Wiki

Contents

Using Skype for SMS notification

Note: this was tested only in Nagios 2

Since Skype now provides a Skype Python API, it can easily be automated to provide SMS notifications for Nagios.

Setting up Skype

  1. Get the appropriate version from the download page
  2. Install it
  3. If you are working on a remote box, install a VNC server so you can do the initial skype setup, in Debian you can use tightvncserver or vnc4server
    1. Under Debian you will also need the packages x11-xserver-utils and xfonts-base
  4. Install a simple window manager like Fluxbox
  5. Start the VNC server and connect to it
  6. Start Skype and enter your login credentials
  7. Start a console in the VNC terminal and use the command xhost localhost so the command line clients can connect from another terminal

Integrate the command line tools

  1. Download and install Skype4Py
  2. Get the Skype linux tools
  3. Extract the tools to a suitable path (eg. /usr/local/lib/nagios/)
  4. Add Media:Check_status_py.txt (rename as check_status.py) to the tools directory
  5. Apply a patch to send_sms.py: Media:Send_sms_py_patch.txt
  6. Start both tools once. If they don't throw any errors, go to the VNC. Skype will pop up a dialog asking if the programs may access Skype. Tick the checkbox to remember this question and acknowledge it.

Integrate Skype into Nagios

Monitor Skype's account status

Insert this wherever you see fit (for example commands.cfg):

define command {
        command_name    check_skype
        command_line    /usr/local/lib/nagios/skype_linux_tools/check_status.py
}

This will notify you when Skype is offline or out of money using the previously added script. Use this check on the host where you have Skype installed (should be the same as the Nagios host).

SMS Notification command

Again, add this to your Nagios configuration:

define command {
        command_name    notify-by-sms
        command_line    /usr/local/lib/nagios/skype_linux_tools/send_sms.py $CONTACTPAGER$ "$NOTIFICATIONTYPE$ alert - $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ since $LONGDATETIME$"
}

This will be used for the actual SMS notifications.

Setting up SMS notifications

You might want to use the SMS notification only in really severe cases. In our setup it occurs only when the HTTPs have already triggered three notifications. This takes about 15 minutes. Until then, regular mail notifications are used.

First define a service to be inherited by all services which should use SMS notifications. Make sure the notification interval is > 0 so the escalation triggers. To ease set-up add all services which should use SMS notifications to a service group.


Do not use the following snippets verbatim, they are just examples.

define service {
        name                            sms
        servicegroups                   sms
        register                        0
        notification_interval           3 # make sure that notifications occur repeatedly
}

define servicegroup {
        servicegroup_name               sms
}


Then define the actual escalation. It should only trigger on the third notification from the service and will only trigger once (notification_interval 0). In order for the escalation to trigger at all the service has to cause several notifications, that is why the notification interval is in the service definition above.

define serviceescalation {
        contact_groups                  +sms
        first_notification              3
        last_notification               4
        notification_interval           0
        escalation_period               24x7
        escalation_options              r,u,c
        name                            sms_notification
        servicegroup_name               sms
}

A sample service that should use the SMS notifications could look like this. Notice that the only crucial line is the use line which must have sms as the first entry.

define service {
        service_description             HTTP
        check_command                   check_http
        use                             sms,some_template # order is IMPORTANT
        hostgroups                      servers
        name                            some_name-http
}

As you can see, the contact group sms will be notified (in addition to the regular contacts) once escalation triggers. So the contact group and contacts look like this:

define contact {
	use				some_template
	contact_name			user_a-sms
	service_notification_commands	notify-by-sms
	pager				cell_phone_number_a
}

define contact {
	contact_name			user_b-sms
	alias				Name of User
	service_notification_commands	notify-by-sms
	pager				cell_phone_number_b
	service_notification_period     24x7
	host_notification_period        24x7
	service_notification_options    w,u,c,r
	host_notification_options       n
	host_notification_commands      host-notify-by-email
}


define contactgroup {
	contactgroup_name		sms
	alias				SMS Notifications
	members				user_a-sms, user_b-sms
}

If you already have a definition for the contact that is used for mail notifications you can simply use this as a template, otherwise you need to provide a full definition. The crucial points are the pager and the service_notification_commands.

The host notifications are turned off as the HTTPs are also down when the host is down, so a notification will occur anyway.

Contact

If you have got any questions feel free to contact me: Georg Sorst