Class: God::Contacts::Prowl

Inherits:
God::Contact show all
Defined in:
lib/god/contacts/prowl.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Attributes inherited from God::Contact

#group, #info, #name

Instance Method Summary collapse

Methods inherited from God::Contact

#arg, defaults, #friendly_name, generate, normalize, valid?

Methods included from God::Configurable

#base_name, complain, #complain, #friendly_name, #prepare, #reset

Class Attribute Details

.apikeyObject

Returns the value of attribute apikey.



15
16
17
# File 'lib/god/contacts/prowl.rb', line 15

def apikey
  @apikey
end

Instance Attribute Details

#apikeyObject

Returns the value of attribute apikey.



24
25
26
# File 'lib/god/contacts/prowl.rb', line 24

def apikey
  @apikey
end

Instance Method Details

#map_priority(priority) ⇒ Object



45
46
47
48
49
50
51
52
53
54
# File 'lib/god/contacts/prowl.rb', line 45

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
     when 4 then Prowly::Notification::Priority::MODERATE
     when 5 then Prowly::Notification::Priority::VERY_LOW
     else Prowly::Notification::Priority::NORMAL
  end
end

#notify(message, time, priority, category, host) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/god/contacts/prowl.rb', line 26

def notify(message, time, priority, category, host)
  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
rescue Object => e
  applog(nil, :info, "failed to send prowl notification to #{self.name}: #{e.message}")
  applog(nil, :debug, e.backtrace.join("\n"))
end

#valid?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
# File 'lib/god/contacts/prowl.rb', line 18

def valid?
  valid = true
  valid &= complain("Attribute 'apikey' must be specified", self) if self.apikey.nil?
  valid
end