Skip to content

Instantly share code, notes, and snippets.

@craigw
Created February 17, 2010 16:21
Show Gist options
  • Save craigw/306765 to your computer and use it in GitHub Desktop.
Save craigw/306765 to your computer and use it in GitHub Desktop.
#! /usr/bin/env ruby
# 1. Install the gem.
#
# 2. Test by attaching a stompcat[1] client and running this:
#
# /path/to/notify-service-by-stomp.rb mq.example.com \
# /topic/xeriom.nagios.services.checks service-host.example.com \
# "FSCK" WARNING HARD 86492 6 6
#
# 3. Define an event handler in Nagios like this:
#
# define command {
# command_name notify-service-by-stomp
# command_line /path/to/notify-service-by-stomp.rb mq.example.com /topic/xeriom.nagios.services.checks $HOSTADDRESS$ "$SERVICEDESC$" $SERVICESTATE$ $SERVICESTATETYPE$ $SERVICEDURATIONSEC$ $SERVICEATTEMPT$ $MAXSERVICEATTEMPTS$
# }
#
# 4. Add the event handler. It's possible to do this per-service, but I
# leave that as an exercise to the reader. Here's how to do it
# globally:
#
# global_service_event_handler=notify-service-by-stomp
#
# 5. Restart Nagios.
#
#
#
#
# Notes:
# [1] http://gist.github.com/306764#file_stompcat.rb
require 'rubygems'
require 'smqueue'
require 'json'
message = {
:hostname => ARGV[2],
:service => ARGV[3],
:state => ARGV[4],
:state_type => ARGV[5],
:state_time => ARGV[6],
:attempt => ARGV[7],
:max_attempts => ARGV[8]
}
configuration = {
:host => ARGV[0],
:name => ARGV[1],
:adapter => :StompAdapter
}
broadcast = SMQueue(configuration)
broadcast.put message.to_json, "content-type" => "application/json"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment