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.

About these ads

6 Comments »

  1. Hi Mezgani!

    Just what I was looking for. Works perfectly.

    Thanks!

    Comment by Scott Donnelly — July 14, 2009 @ 7:50 am

  2. Great work Mezgani,
    Worked perfectly out of the box.
    Thanks a lot!

    Comment by Kim Hage — August 19, 2009 @ 4:02 am

  3. It looks like something we could make good use of, does it support SSL connections though?

    Comment by Leon de Jager — August 19, 2009 @ 5:18 pm

  4. Do you know if it’s possible to have usernames with the ‘at’ sign in them as well (in addition to having the server name)? I keep getting “twisted.words.protocols.jabber.jid.InvalidFormat: Invalid character in hostname”

    Comment by Doug Warner — November 16, 2009 @ 8:59 pm

  5. [...] XMPP / Jabber to send Instant Messages is pretty popular. Here is a short tutorial on how to set this [...]

    Pingback by Clever nagios alert methods - Admins Goodies — August 23, 2011 @ 3:45 am

  6. Excellent write-up. I definitely love this website. Keep writing!

    Comment by Safety Jabber — December 28, 2012 @ 1:00 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

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

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: