def notify(condition, message)
spec = Contact.normalize(condition.notify)
unmatched = []
resolved_contacts =
spec[:contacts].inject([]) do |acc, contact_name_or_group|
cons = Array(God.contacts[contact_name_or_group] || God.contact_groups[contact_name_or_group])
unmatched << contact_name_or_group if cons.empty?
acc += cons
acc
end
unless unmatched.empty?
msg = "#{condition.watch.name} no matching contacts for '#{unmatched.join(", ")}'"
applog(condition.watch, :warn, msg)
end
resolved_contacts.each do |c|
host = `hostname`.chomp rescue 'none'
begin
c.notify(message, Time.now, spec[:priority], spec[:category], host)
msg = "#{condition.watch.name} #{c.info ? c.info : "notification sent for contact: #{c.name}"} (#{c.base_name})"
applog(condition.watch, :info, msg % [])
rescue Exception => e
applog(condition.watch, :error, "#{e.message} #{e.backtrace}")
msg = "#{condition.watch.name} Failed to deliver notification for contact: #{c.name} (#{c.base_name})"
applog(condition.watch, :error, msg % [])
end
end
end