class Eye::Notify
Constants
- TIMEOUT
- TYPES
Public Class Methods
get_class(type)
click to toggle source
# File lib/eye/notify.rb, line 12 def self.get_class(type) klass = eval("Eye::Notify::#{TYPES[type]}") rescue nil raise "unknown notifier :#{type}" unless klass if deps = klass.requires Array(deps).each { |d| require d } end klass end
new(options = {}, message_h = {})
click to toggle source
# File lib/eye/notify.rb, line 55 def initialize(options = {}, message_h = {}) @message_h = message_h @options = options debug "created notifier #{options}" end
notify(contact, message_h)
click to toggle source
# File lib/eye/notify.rb, line 25 def self.notify(contact, message_h) contact = contact.to_s settings = Eye::Control.settings needed_hash = (settings[:contacts] || {})[contact] if needed_hash.blank? error "contact #{contact} not found; check your configuration" return end create_proc = lambda do |nh| type = nh[:type] config = (settings[type] || {}).merge(nh[:opts] || {}).merge(:contact => nh[:contact]) klass = get_class(type) notify = klass.new_link(config, message_h) notify.async_notify if notify end if needed_hash.is_a?(Array) needed_hash.each{|nh| create_proc[nh] } else create_proc[needed_hash] end rescue Exception, Timeout::Error => ex log_ex(ex) end
register(base)
click to toggle source
# File lib/eye/notify.rb, line 92 def self.register(base) name = base.to_s.gsub('Eye::Notify::', '') type = name.underscore.to_sym Eye::Notify::TYPES[type] = name Eye::Notify.const_set(name, base) Eye::Dsl::ConfigOpts.add_notify(type) end
requires()
click to toggle source
# File lib/eye/notify.rb, line 100 def self.requires end
validate!(options)
click to toggle source
# File lib/eye/notify.rb, line 21 def self.validate!(options) get_class(options[:type]).validate(options) end
Public Instance Methods
async_notify()
click to toggle source
# File lib/eye/notify.rb, line 66 def async_notify async.notify after(TIMEOUT){ terminate } end
execute()
click to toggle source
# File lib/eye/notify.rb, line 78 def execute raise NotImplementedError end
logger_sub_tag()
click to toggle source
# File lib/eye/notify.rb, line 62 def logger_sub_tag @options[:contact] end
message_body()
click to toggle source
# File lib/eye/notify.rb, line 88 def message_body "#{message_subject} at #{Eye::Utils.human_time2(msg_at)}" end
message_subject()
click to toggle source
# File lib/eye/notify.rb, line 84 def message_subject "[#{msg_host}] [#{msg_full_name}] #{msg_message}" end
notify()
click to toggle source
# File lib/eye/notify.rb, line 71 def notify debug "start notify #{@message_h}" execute debug "end notify #{@message_h}" terminate end