lib/flapjack/notification/sms.rb in flapjack-0.6.39 vs lib/flapjack/notification/sms.rb in flapjack-0.6.40
- old
+ new
@@ -1,40 +1,52 @@
#!/usr/bin/env ruby
+require 'flapjack/pikelet'
require 'flapjack/notification/sms/messagenet'
module Flapjack
module Notification
class Sms
- extend Flapjack::Notification::Common
- def self.dispatch(notification, opts = {})
- notification_type = notification['notification_type']
- contact_first_name = notification['contact_first_name']
- contact_last_name = notification['contact_last_name']
- state = notification['state']
- summary = notification['summary']
- time = notification['time']
- entity, check = notification['event_id'].split(':')
+ extend Flapjack::ResquePikelet
- headline_map = {'problem' => 'PROBLEM: ',
- 'recovery' => 'RECOVERY: ',
- 'acknowledgement' => 'ACK: ',
- 'unknown' => '',
- '' => '',
- }
+ class << self
- headline = headline_map[notification_type] || ''
+ def perform(notification)
+ @logger.debug "Woo, got a notification to send out: #{notification.inspect}"
+ dispatch(notification, :logger => @logger, :redis => ::Resque.redis)
+ end
- message = "#{headline}'#{check}' on #{entity}"
- message += " is #{state.upcase}" unless notification_type == 'acknowledgement'
- message += " at #{Time.at(time).strftime('%-d %b %H:%M')}, #{summary}"
+ def dispatch(notification, opts = {})
+ notification_type = notification['notification_type']
+ contact_first_name = notification['contact_first_name']
+ contact_last_name = notification['contact_last_name']
+ state = notification['state']
+ summary = notification['summary']
+ time = notification['time']
+ entity, check = notification['event_id'].split(':')
- notification['message'] = message
- Flapjack::Notification::Sms::Messagenet.sender(notification,
- :logger => opts[:logger],
- :config => Flapjack::Notification::Sms.class_variable_get('@@config'))
+ headline_map = {'problem' => 'PROBLEM: ',
+ 'recovery' => 'RECOVERY: ',
+ 'acknowledgement' => 'ACK: ',
+ 'test' => 'TEST NOTIFICATION: ',
+ 'unknown' => '',
+ '' => '',
+ }
+
+ headline = headline_map[notification_type] || ''
+
+ message = "#{headline}'#{check}' on #{entity}"
+ message += " is #{state.upcase}" unless ['acknowledgement', 'test'].include?(notification_type)
+ message += " at #{Time.at(time).strftime('%-d %b %H:%M')}, #{summary}"
+
+ notification['message'] = message
+ Flapjack::Notification::Sms::Messagenet.sender(notification,
+ :logger => opts[:logger],
+ :config => Flapjack::Notification::Sms.instance_variable_get('@config'))
+ end
+
end
end
end
end