« My Favorite Commands… | Main | EVDO and SSH Timeouts »
Nagios
By Matt | October 5, 2007
Rest of install to come…
But let’s document connecting to a IM Server (Jabber)
– Create Jabber accounts (goggle will do).
— From a browser, “initialize” the accounts by sending an invitation so they can be added to the “friends” list before we have to deal with command line stuff. Simply send an invite to a chat and accept it.
– In this example, nagiospcf3 is the server and dalmatian90 is myself.
– yum install perl-Net-Jabber.noarch
A lot of the following is based on http://www.gridpp.ac.uk/wiki/Nagios_jabber_notification.
Save the following as /etc/nagios/notify_by_jabber
Change the username and password; username is without @gmail.com as that is put in later (you can change it if necessary — just read through the script and you’ll figure out the changes. You should be able to modify it to work with your own Jabber server)
#!/usr/bin/perl -w
#
# script for nagios notify via Jabber / Google Talk Instant Messaging
# using XMPP protocol and SASL PLAIN authentication.
#
# author: Andrew Elwell
# based on work by Thus0and David Cox
#
# released under the terms of the GNU General Public License v2
# Copyright 2007 Andrew Elwell.use strict;
use Net::XMPP;## Configuration
my $username = “your.google.username”;
my $password = “your.google.password”;
my $resource = “nagios”;
## End of configurationmy $len = scalar @ARGV;
if ($len ne 2) {
die “Usage…\n $0 [jabberid] [message]\n”;
}
my @field=split(/,/,$ARGV[0]);
#————————————# Google Talk & Jabber parameters :my $hostname = ‘talk.google.com’;
my $port = 5222;
my $componentname = ‘gmail.com’;
my $connectiontype = ‘tcpip’;
my $tls = 1;#————————————my $Connection = new Net::XMPP::Client();# Connect to talk.google.com
my $status = $Connection->Connect(
hostname => $hostname, port => $port,
componentname => $componentname,
connectiontype => $connectiontype, tls => $tls);if (!(defined($status))) { print "ERROR: XMPP connection failed.\n"; print " ($!)\n"; exit(0); }# Change hostname my $sid = $Connection->{SESSION}->{id}; $Connection->{STREAM}->{SIDS}->{$sid}->{hostname} = $componentname;# Authenticate my @result = $Connection->AuthSend( username => $username, password => $password, resource => $resource);if ($result[0] ne "ok") { print "ERROR: Authorization failed: $result[0] - $result[1]\n"; exit(0); }# Send messages foreach ( @field ) { $Connection->MessageSend( to => "$_\@$componentname", resource => $resource, subject => "Notification", type => "chat", body => $ARGV[1]); }
chmod755 the file and test like this:
./notify_by_jabber dalmatian90 “King Phillip Came Over for great spaghetti”
In /etc/nagios/commands.cfg append this:
# ‘host-notify-by-jabber’ command definition
define command{
command_name host-notify-by-jabber
command_line /etc/nagios/notify_by_jabber $CONTACTPAGER$ “Host ‘$HOSTALIAS$’ is $HOSTSTATE$ – Info: $HOSTOUTPUT$”
}# ‘notify-by-jabber’ command definition
define command{
command_name notify-by-jabber
command_line /etc/nagios/notify_by_jabber $CONTACTPAGER$ “$NOTIFICATIONTYPE$ $HOSTNAME$ $SERVICEDESC$ $SERVICESTATE$ $SERVICEOUTPUT$ $LONGDATETIME$”
}
Now, in /etc/nagios/contacts.cfg provide a Jabber entry. Since we’re reusing the $CONTACTPAGER$, and my main entry already uses that to page my cellphone, we need another contact for Jabber.
define contact{
contact_name mkivela_jabber
alias Matt Kivela
service_notification_period 24×7
host_notification_period 24×7
service_notification_options w,u,c,r
host_notification_options d,u,r
service_notification_commands notify-by-jabber
host_notification_commands host-notify-by-jabber
pager dalmatian90
}
You will need, of course, to put the jabber user if into contactgroups.cfg is necessary.
Now test your configuration
sudo /usr/sbin/nagios -v /etc/nagios/nagios.cfg
Topics: Sysadmin Tools | No Comments »
Comments
You must be logged in to post a comment.