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.

4 Comments

  1. Panic says:

    Hi there may I use some of the information here in this post if I provide a link back to your site?

  2. This is a very interesting post, I was looking for this knowledge. Just so you know I discovered your webpage when I was doing research for blogs like mine, so please check out my site sometime and leave me a comment to let me know what you think.

  3. pet care says:

    Hey..just want to let you know i appreciate your i and some of your posts? well..lol..not really many ones, but i like the idea
    Would you be interested in exchanging blogrolls links with my site?

Leave a Reply