Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

clean up prowl contact

  • Loading branch information...
commit 085f82606bebbd8693496c7cdf50d608ef874d03 1 parent bcc89ae
@mojombo mojombo authored
View
30 lib/god/contacts/prowl.rb
@@ -1,5 +1,3 @@
-# Rafael Magaña <raf.magana@gmail.com>
-#
# For Prowl notifications you need the 'prowly' gem
# (gem install prowly)
#
@@ -33,11 +31,13 @@
module God
module Contacts
class Prowl < Contact
-
+
attr_accessor :apikey
-
+
def valid?
valid = true
+ valid &= complain("Attribute 'apikey' must be specified", self) if self.apikey.nil?
+ valid
end
def notify(message, time, priority, category, host)
@@ -56,19 +56,21 @@ def notify(message, time, priority, category, host)
self.info = "failed to send prowl notification to #{self.name}: #{result.message}"
end
end
+ rescue Object => e
+ self.info = "failed to send prowl notification to #{self.name}: #{e.message}"
end
-
+
private
+
def map_priority(priority)
- prowl_priority = case priority
- when 1 then Prowly::Notification::Priority::EMERGENCY
- when 2 then Prowly::Notification::Priority::HIGH
- when 3 then Prowly::Notification::Priority::NORMAL
- when 4 then Prowly::Notification::Priority::MODERATE
- when 5 then Prowly::Notification::Priority::VERY_LOW
- else Prowly::Notification::Priority::NORMAL
- end
- prowl_priority
+ case priority
+ when 1 then Prowly::Notification::Priority::EMERGENCY
+ when 2 then Prowly::Notification::Priority::HIGH
+ when 3 then Prowly::Notification::Priority::NORMAL
+ when 4 then Prowly::Notification::Priority::MODERATE
+ when 5 then Prowly::Notification::Priority::VERY_LOW
+ else Prowly::Notification::Priority::NORMAL
+ end
end
end
end
View
8 test/configs/contact/contact.god
@@ -36,6 +36,12 @@ God.contact(:twitter) do |c|
c.group = 'developers'
end
+God.contact(:prowl) do |c|
+ c.name = 'tom3'
+ c.apikey = 'd31c1f31f7af0f69e263c2f12167263127eab608'
+ c.group = 'developers'
+end
+
God.watch do |w|
w.name = "contact"
w.interval = 5.seconds
@@ -65,7 +71,7 @@ God.watch do |w|
# start if process is not running
w.transition(:up, :start) do |on|
on.condition(:process_exits) do |c|
- c.notify = {:contacts => ['tom2', 'foobar'], :priority => 1, :category => 'product'}
+ c.notify = {:contacts => ['tom2', 'tom3', 'foobar'], :priority => 1, :category => 'product'}
end
end
View
6 test/test_prowl.rb
@@ -2,13 +2,13 @@
require File.dirname(__FILE__) + '/helper'
class TestProwl < Test::Unit::TestCase
-
def test_live_notify
-
prowl = God::Contacts::Prowl.new
prowl.name = "Prowly"
prowl.apikey = 'put_your_apikey_here'
-
+
+ Prowly.expects(:notify).returns(mock(:succeeded? => true))
+
prowl.notify("Test", Time.now, "Test", "Test", "")
assert_equal "sent prowl notification to #{prowl.name}", prowl.info
end
Please sign in to comment.
Something went wrong with that request. Please try again.