Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'sinatra'
- require 'socket'
- require 'json'
- require 'xmpp4r-simple'
- get '/' do
- 'Welcome to your cloudkick webhook handlers!'
- end
- post "/statsd_handler" do
- STATSD_HOST = 'graphite.example.com'
- STATSD_PORT = '8125'
- request.body.rewind # in case someone already read it
- body = request.body.read
- content = JSON.parse(body)
- ['alerts', content['severity'] || 'unknown'].each do |metric|
- UDPSocket.new.send "cloudkick.#{metric.downcase}:1|c", 0, STATSD_HOST, STATSD_PORT
- end
- "Recorded event <br/><pre>#{content.inspect}</pre>"
- end
- post "/jabber_handler" do
- JABBER_USERNAME = 'me@jabber.org'
- JABBER_PASSWORD = 'sekret'
- JABBER_DESTINATION = 'my_room@partychapp.appspotchat.com'
- request.body.rewind # in case someone already read it
- body = request.body.read
- content = JSON.parse(body)
- message = "Cloudkick alert (#{content['severity']}) for #{content['node']['name']}:"
- messagte += " #{content['state_change']['current']['status_details']}"
- im = Jabber::Simple.new(JABBER_USERNAME, JABBER_PASSWORD)
- im.deliver(JABBER_DESTINATION, message)
- # wait a little for relay to complete
- sleep(2)
- "Sent message for event <br/><pre>#{content.inspect}</pre>"
- end
Add Comment
Please, Sign In to add comment