Using a ruby-based AIM notifier in nagios

If you use nagios for monitoring of your rails instances, you might want to get notification not only via email or SMS-messages but to your AIM when you are online. The script (libexec/aim_notifier.rb) utilizes the Net::TOC gem for sending out notifications:

#!/usr/bin/env ruby

 require 'rubygems'
 require 'net/toc'

 user = 'your_bot_name'
 password = 'bot_password'

 msg = ARGV[0].to_s.gsub('\n', "\n")

 client = Net::TOC.new(user, password)

 client.connect

 sleep 3

 buddies = []

 client.buddy_list.each_group { |g, b| buddies = b if g == 'Friends' }

 buddies.each do |b|
   b.send_im(msg) if b.available?
 end

 sleep 3

 client.disconnect

You need to add any account you want to be notified to bot’s friends (either by logging to AIM using the bot account or using Net::TOC’s ability to add friends).

The last piece is to add a new notifier in etc/objects/commands.cfg as:

 define command{
         command_name    notify-service-by-aim
         command_line    $USER1$/aim_notifier.rb $ARG1$ $ARG2$ "***** Nagios *****\n\nNotification Ty
 pe: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState:
 $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$"
         }

and to append it to the list of notifiers defined for a contact template in etc/objects/commands.cfg:

 service_notification_commands   notify-service-by-email,notify-service-by-aim

Repeat the configuration if you want to use the AIM notification for hosts as well.

Leave a Reply