This tutorial shows how to send Nagios' notifications to an instant messaging client. The client has to be connected to a private Jabber server.
Here is a screenshot of Exodus, showing a Nagios message:

Jabber server
Jabberd 2 is an instant messaging server (open source), that supports chatting, messaging, and if corresponding plug-in is installed, chatrooms, etc. What we need here is only messaging. Jabber protocol is suported by many clients. As far as I'm concerned, Exodus for Windows works well.
To install Jabber, please refer to jabberstudio web site. It must be installed on the same Linux box that runs Nagios.
This tutorial works for the following versions :
- Jabberd v2.0 s4
- Nagios v2.4
- Exodus v 0.9.1.0
Server configuration
Jabber domain should match your internal DNS domain, so things will be simpler for clients configuration. All other settings were left to default.
Option: my server is configured so not to automatically register new users (it's not supposed to be a public general-purpose server). This is done in configuration file c2s.xml, item <register>: just comment <enable/> line. This settings implies manually creating users in mysql database. Here is a sample mysql command:
mysql -u jabberd2 -p
<mysql password>
mysql> use jabberd2
mysql> insert into authreg (username, realm, password) values ('login_name', 'your.jabber.domain', 'password');
And to delete a user:
mysql> delete from authreg where username='login_name';
Two accounts at least have to be created: yours (to connect your client) and "nagios" (who sends messages to you).
Connecting from a Jabber client
This concerns Exodus but can be easily transposed to any other client:
Profile tab
- Username : <login_name>
- Server : <your.jabber.domain>
- Resource : <we don't care>
- Password : <password>
Connection tab
- Host : <Jabber server full name>
- Port : 5222
In this tab, you also can use Jabber server automatic discovery. This is were domain matching comes into play. In your internal DNS server (Active Directory for me), add the following lines in _tcp subdomain:
- _jabber, type SRV, port number 5269, host <jabber server full name>
- _xmpp-server, type SRV, port number 5269, host <jabber server full name>
- _xmpp-client, type SRV, port number 5222, host <jabber server full name
Your jabber client will then ask your DNS where to find a jabber service. Nice, isn't it? Use your Jabber client to log in as "nagios" at least once, just to check its account works. Then log in as yourself.
Sending a message from Nagios
Message sending script
The script is written in Perl, so I tried using Perl module Net::Jabber. David Cox did that, and shares a script named notify_via_jabber.pl. You can find it at Nagios Exchange.
But I couldn't have that script to work. So I did something really bad: telnet on Jabber server's TCP port, and write Jabber commands. My script is called send_jabber.pl. Change the Jabber domain name "domaine.com" with yours if you plan to use this script.
Nagios Configuration
The following configuration works with my script send_jabber.pl.
First, create contacts in configuration file contacts.cfg. I personaly use a template, and an inherited contact:
define contact{
name generic-contact
register 0
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-by-email
host_notification_commands host-notify-by-email
}
define contact{
use generic-contact
contact_name my-jabber-name
alias Myself
pager login_name@my.jabber.domain
service_notification_commands notify-by-jabber
host_notification_commands host-notify-by-jabber
service_notification_period workhours
host_notification_period workhours
}
Notification commands are defined in misccommands.cfg, one for services notification, the other for hosts notification:
define command{
command_name notify-by-jabber
command_line /usr/local/nagios/libexec/send_jabber.pl $CONTACTPAGER$ $NOTIFICATIONTYPE$ "$HOSTNAME$" "$SERVICEDESC$" "$SERVICESTATE$" "$OUTPUT$" "$DATETIME$"
}
define command{
command_name host-notify-by-jabber
command_line /usr/local/nagios/libexec/send_jabber.pl $CONTACTPAGER$ $NOTIFICATIONTYPE$ "$HOSTNAME$" "" "$HOSTSTATE$" "$OUTPUT$" "$DATETIME$"
}
You still need to associate that contact with a contactgroup, then put the contactgroup in the concerned host or service configuration. As a Nagios admin, you already know how to do this.