Sha256: 6e21ab2c783641e1b86c378386ff9c81c879d4f2ffe54aea89a9502ccb279721
Contents?: true
Size: 1.66 KB
Versions: 2
Compression:
Stored size: 1.66 KB
Contents
#!/usr/bin/env ruby # # Sensu Handler: messagemedia # # This handler formats alerts as SMS messages and sends them off to pre-defined recipients using MessageMedia's SMS gateway # # Copyright 2012 Rafael Fonseca (http://twitter.com/rafaelmagu) # # Released under the same terms as Sensu (the MIT license); see LICENSE # for details. require 'sensu-handler' require 'rumeme' require 'timeout' class MessageMedia < Sensu::Handler def short_name @event['client']['name'] + '/' + @event['check']['name'] end def action_to_string case @event['check']['status'] when 0 'RESOLVED' when 1 'WARNING' when 2 'CRITICAL' else 'UNKNOWN' end end def handle Rumeme.configure do |config| config.username = settings['messagemedia']['username'] || 'xxx' config.password = settings['messagemedia']['password'] || 'yyy' config.use_message_id = true config.secure = true end message = "#{action_to_string} - #{short_name}: #{@event['check']['notification']}" begin timeout 10 do si = Rumeme::SmsInterface.new settings['messagemedia']['mobile_numbers'].each do |mobile_number| puts 'sms -- preparing alert(s) for ' + mobile_number begin si.add_message phone_number: mobile_number, message: message rescue ArgumentError puts 'sms -- failed sending alert(s) for ' + mobile_number end end si.send_messages puts 'sms -- sent alert(s) for ' + short_name end rescue Timeout::Error puts 'sms -- timed out while attempting to ' + @event['action'] + ' an incident -- ' + short_name end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
sensu-plugins-messagemedia-1.0.0 | bin/handler-messagemedia.rb |
sensu-plugins-messagemedia-0.0.2 | bin/handler-messagemedia.rb |