Sha256: 83d55d039acaae28942035ccab349f54af2c6cb942e2572ee1cd3f30ab3fa2bb

Contents?: true

Size: 1.67 KB

Versions: 2

Compression:

Stored size: 1.67 KB

Contents

#!/usr/bin/env ruby
#

require 'sensu-handler'
require 'xmpp4r/client'
require 'xmpp4r/muc'
include Jabber

class XmppHandler < Sensu::Handler
  def event_name
    @event['client']['name'] + '/' + @event['check']['name']
  end

  def handle
    xmpp_jid = settings['xmpp']['jid']
    xmpp_password = settings['xmpp']['password']
    xmpp_target = settings['xmpp']['target']
    xmpp_target_type = settings['xmpp']['target_type']
    xmpp_server = settings['xmpp']['server']
    xmpp_room_password = settings['xmpp']['room_password']

    body = if @event['action'].eql?('resolve')
             #      body = "Sensu RESOLVED - [#{event_name}] - #{@event['check']['notification']}"
             "Sensu RESOLVED - [#{event_name}] - #{@event['check']['output']} - #{@event['check']['notification']}"
           else
             #      body = "Sensu ALERT - [#{event_name}] - #{@event['check']['notification']}"
             "Sensu ALERT - [#{event_name}] - #{@event['check']['output']} - #{@event['check']['notification']}"
             #      body = "Sensu ALERT - [#{event_name}] - #{@event['check']['output']}"
           end

    jid = JID.new(xmpp_jid)
    cl = Client.new(jid)
    cl.connect(xmpp_server)
    cl.auth(xmpp_password)
    cl.send(Jabber::Presence.new.set_type(:available))
    if xmpp_target_type == 'conference'
      m = Message.new(xmpp_target, body)
      room = MUC::MUCClient.new(cl)
      room.my_jid = jid
      room.join(Jabber::JID.new(xmpp_target + '/' + cl.jid.node), xmpp_room_password)
      room.send m
      room.exit
    else
      m = Message.new(xmpp_target, body).set_type(:normal).set_id('1').set_subject('SENSU ALERT!')
      cl.send m
    end
    cl.close
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sensu-plugins-xmpp-1.0.1 bin/handler-xmpp.rb
sensu-plugins-xmpp-1.0.0 bin/handler-xmpp.rb