Sha256: 7a12e69163493c6eeabf6a2c0165790aecfb4f7d1e662356733724306f2ad6d7
Contents?: true
Size: 1.74 KB
Versions: 2
Compression:
Stored size: 1.74 KB
Contents
#!/usr/bin/env ruby # require 'sensu-handler' require 'xmpp4r/client' require 'xmpp4r/muc' # TODO: investigate if a require is correct and if not how to fix this. 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-3.0.0 | bin/handler-xmpp.rb |
sensu-plugins-xmpp-2.0.0 | bin/handler-xmpp.rb |