Mezgani blog

July 9, 2009

Nagios jabber notification

Filed under: nagios — Tags: , , — Ali MEZGANI @ 11:25 am

Nagios can be configured to send notifications by various ways email “the default notification for Nagios”, sms and jabber …
It’s very flexible enough to let you develop reel solutions.
In this tutorial we will focus on how to configure nagios to send notification to your jabber account using twisted.

First install python-twisted interface.
On Debian and derive like Ubuntu use apt like this:
$ sudo apt-get install python-twisted

You can check twisted website for more informations : http://twistedmatrix.com/

Later, append to contacts_nagios2.cfg the notifications method notify-host-by-jabber and notify-service-by-jabber
Also, set up a new paramter address1 that must contain your(s) jabber account.

$ sudo vim /etc/nagios3/conf.d/contacts_nagios2.cfg
define contact{
contact_name root
alias Root
service_notification_period 24×7
host_notification_period 24×7
service_notification_options w,u,c,r
host_notification_options d,r
service_notification_commands notify-service-by-email,notify-service-by-jabber
host_notification_commands notify-host-by-email,notify-host-by-jabber
email mezgani@nivose.securfox.org
address1 mezgani@secufox.org
pager +212669119530
}

And let’s define the command that will be interpreted when nagios call notify-host-by-jabber and notify-service-by-jabber
So change /home/mezgani/script/fdbot.py by the path of your python bot, the output of the command will be redirected
to the log file /var/log/nagios3/jabber.log
Add the following to your /etc/nagios3/commands.cfg.

$ sudo vim /etc/nagios3/commands.cfg

# ‘notify-host-by-jabber’ command definition
define command{
command_name notify-host-by-jabber
command_line /home/mezgani/script/fdbot.py “$CONTACTADDRESS1$” “$NOTIFICATIONTYPE$ : Host $HOSTALIAS$ is $HOSTSTATE$ ($OUTPUT$)” > /var/log/nagios3/jabber.log
}

# ‘notify-service-by-jabber’ command definition
define command{
command_name notify-service-by-jabber
command_line /home/mezgani/script/fdbot.py “$CONTACTADDRESS1$” “$NOTIFICATIONTYPE$ : $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ ($OUTPUT$)” > /var/log/nagios3/jabber.log
}

Well, here i define the jabber bot named fdbot, it is a python script based on twisted framework that transforms your message to a valid jabber message.
You can choose your script language it can be done with perl using ‘Net::XMPP’, with ruby using ‘xmpp4r’, and others.
my choise of python was just for my need to learn twisted framework.

You can Get fdbot by git like:
$ git clone git://github.com/mezgani/fdbot.git
set up the undefined variables in the fdbot.py script.

and restart nagios:
$ sudo /etc/init.d/nagios3 restart

The source code at Github. Go visit the Github project page for fdbot.

Theme: Silver is the New Black. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.