Wednesday, April 29, 2009

Receiving the Nagios Notifications Via Jabber

Basically the nagios calls a script written in Perl that connect to the Jabber server and sends a notice to you. 
Downloading and configuring the script 
Download the script, we should also make it executable and make sure that nagios is the owner with the commands below: 

  1. Cd / usr / local / nagios / libexec 

  2. Wget http://gnusys.net/downloads/notify_via_jabber.pl

  3. Chown nagios.nagios notify_via_jabber.pl 

  4. Chmod 755 notify_via_jabber.pl 


You must install a Perl library so that it can interact with the jabber: 

  1. Aptitude install libnet-jabber-perl 


Okay, we already have the script, now we need to make some changes so that it can connect to our server Jabber. 

Here we see what must be changed, look for this section and put the server name, port connection, the user who send the messages and password. 
use constant SERVER => ‘jabberserver.net’; 
use constant PORT => 5222; 
use constant USER => ‘user@jabberserver.net’; 
use constant PASSWORD => ‘password’; 

 
Configuring nagios 
We have to define the commands related to the hosts to be used by nagios to get him to send us messages. You can check your file and see something like commands.cfg notify-host-by-email, similar to that we need to define a Jabber. 

Edit the file commands.cfg (usually in /us / local/nagios/etc/ objects) and add the following section: 

  1. This command is used to notify recipients of service problems: 

  2. ‘Notify-by-jabber’ command definition 


define command ( 
command_name notify-by-jabber 
command_line / usr / local / nagios / libexec / notify_via_jabber.pl CONTACTADDRESS1 $ $ “$ $HostName / $SERVICEDESC is$ $ $ SERVICESTATE \ r \ nAdditional Info: SERVICEOUTPUT $ $” 


  1. This command is used to notify recipients host of problems: 

  2. ‘Host-notify-by-jabber’ command definition 


define command ( 
command_name host-notify-by-jabber 
command_line / usr / local / nagios / libexec / notify_via_jabber.pl CONTACTADDRESS1 $ $ “$ $ NOTIFICATIONTYPE: $ HostName $ HOSTSTATE is $ $ \ n $ $ HOSTOUTPUT” 


As you can see, was a program called => / usr / local / nagios / libexec / notify_via_jabber.pl, which is our script in Perl. 

Now we use these commands somewhere. Edit the file contacts.cfg (usually in / usr / local / nagios / etc / objects) and add the following section: 

Note: Set your contact information such as name, alias, email and address1, where messages are sent. 
define contact ( 
contact_name CONTACT 
use generic-contact 
Contact alias 
email user@jabberserver.net
address1 user@jabberserver.net 

host_notification_commands notify-host-by-email, host-notify-by-jabber 
service_notification_commands notify-by-jabber 
host_notification_period 24×7 
service_notification_period 24×7 
service_notification_options c, r 
)

No comments:

sanjay's shared items

My Blog List