lib/god/contacts/prowl.rb in god-0.10.1 vs lib/god/contacts/prowl.rb in god-0.11.0

- old
+ new

@@ -1,69 +1,49 @@ -# For Prowl notifications you need the 'prowly' gem -# (gem install prowly) +# Send a notice to Prowl (http://prowl.weks.net/). # -# Configure your watches like this: -# -# God.contact(:prowl) do |c| -# c.name = 'georgette' -# c.apikey = 'ffffffffffffffffffffffffffffffffffffffff' -# c.group = 'developers' -# end -# -# -# God.contact(:prowl) do |c| -# c.name = 'johnny' -# c.apikey = 'ffffffffffffffffffffffffffffffffffffffff' -# c.group = 'developers' -# end -# -# -# Define a transition for the process running event -# -# w.transition(:up, :start) do |on| -# on.condition(:process_running) do |c| -# c.running = true -# c.notify = 'developers' -# end -# end +# apikey - The String API key. -require 'prowly' +CONTACT_DEPS[:prowl] = ['prowly'] +CONTACT_DEPS[:prowl].each do |d| + require d +end module God module Contacts class Prowl < Contact - attr_accessor :apikey + class << self + attr_accessor :apikey + end def valid? valid = true valid &= complain("Attribute 'apikey' must be specified", self) if self.apikey.nil? valid end + attr_accessor :apikey + def notify(message, time, priority, category, host) - begin - result = Prowly.notify do |n| - n.apikey = self.apikey - n.priority = map_priority(priority.to_i) - n.application = category || "God" - n.event = "on " + host.to_s - n.description = message.to_s + " at " + time.to_s - end + result = Prowly.notify do |n| + n.apikey = arg(:apikey) + n.priority = map_priority(priority.to_i) + n.application = category || "God" + n.event = "on " + host.to_s + n.description = message.to_s + " at " + time.to_s + end - if result.succeeded? - self.info = "sent prowl notification to #{self.name}" - else - self.info = "failed to send prowl notification to #{self.name}: #{result.message}" - end + if result.succeeded? + self.info = "sent prowl notification to #{self.name}" + else + self.info = "failed to send prowl notification to #{self.name}: #{result.message}" end rescue Object => e - self.info = "failed to send prowl notification to #{self.name}: #{e.message}" + applog(nil, :info, "failed to send prowl notification to #{self.name}: #{e.message}") + applog(nil, :debug, e.backtrace.join("\n")) end - private - def map_priority(priority) case priority when 1 then Prowly::Notification::Priority::EMERGENCY when 2 then Prowly::Notification::Priority::HIGH when 3 then Prowly::Notification::Priority::NORMAL @@ -72,6 +52,6 @@ else Prowly::Notification::Priority::NORMAL end end end end -end \ No newline at end of file +end