Tweak - Nagios Jabber / XMPP Notifications

Image Nagios Openfire Notification

I wanted to add the feature to send nagios alerts via Jabber, aka XMPP protocol, instant messages.  Our office uses the Openfire platform for corporate instant messaging.  Some googling found this:

I modified the server connection and user variables to fit my Openfire installation.  However after running some simple command line tests, I could not get it to work.  The unable to connect errors were easy enough to understand and fix, but then I got an unauthorized error.

ERROR: Authorization failed: error - not-authorized

The link below has information on solution to the error.  OK, so now we assume you CAN send a test message via Jabber/XMPP.  Let's configure it.

There are two primary scenarios for configuring the Jabber/XMPP notifications. 

Scenario 1 - User wants to be contacted for ALL Nagios alerts via Jabber/XMPP. 

Define the contact command something like:

# 'notify-by-jabber' command definition
define command{
        command_name    notify-by-jabber
        command_line    /usr/local/nagios/bin/notify_via_jabber \
             $CONTACTADDRESS1$ "$NOTIFICATIONTYPE$ $HOSTNAME$ \
             $SERVICEDESC$ $SERVICESTATE$ $SERVICEOUTPUT$ $LONGDATETIME$"
        }

*note - I'm using the backslash for readability only, actually only one line.

Notice how I defined "$CONTACTADDRES1" in the command line.  Now check out  my Contact definition...

define contact{
        contact_name                    jdoe
        use                             generic-contact
        alias                           John Doe
        email                           jdoe@company.com
        address1                        jdoe
        service_notification_commands   +notify-by-jabber
        }

This will use the generic contact info for the email method -and- add the jabber contact method.  Note the "address1" line I am using for the appropriate jabber_id for the user.  Alternatively you could create a contact template called "jabber-contact" using the notify-by-jabber command and then apply both templates to the user contact definition.

Scenario 2 - User only needs specific Nagios service/host alerts via Jabber/XMPP.

Unfortunately this is simple.  You would need to define a second contact entirely to assign to the specific host/service.  Create a "jdoe-jabber" contact so on your Nagios host/service definition you would have a line like:

contacts          jdoe,jdoe-jabber

Maybe with an add-on or future version of Nagios we could define a user/contact method along the lines of:

contacts           jdoe:notify-by-jabber,jdoe:notify-by-email

Anyone listening?  Feel free to send me a note or comment.

AttachmentSize
jabber-xmpp-notications.txt2.45 KB

ERROR - Nagios XMPP Notification with Openfire

ERROR: Authorization failed: error - not-authorized

Obviously this means I am connected am communicating with the server.  So I flipped TLS variable on/off a few times.  I also turned on debug logging on my Openfire server and could see the connections.  With TLS "on" or set to "1", I received this error:

Can't use an undefined value as a HASH reference at /usr/lib/perl5/site_perl/5.8.8\
/XML/Stream.pm line 1165.

So I turned TLS off and started working with the not-authorized error.  Googled around and found the a fix that worked.  I had to edit the Protocol.pm perl module to fix the authentication error.  I found my file here...

/usr/lib/perl5/site_perl/5.8.8/Net/XMPP/Protocol.pm

and just commented out the line:

return $self->AuthSASL(%args);

Now I can annoy myself with all my Nagios alerts via IM as well as email!  Attached is the file with the text used for the commands.cfg entry and the perl script to send the notifications.