Class: God::Contacts::Scout

Inherits:
God::Contact show all
Defined in:
lib/god/contacts/scout.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

.client_keyObject

Returns the value of attribute client_key.



14
15
16
# File 'lib/god/contacts/scout.rb', line 14

def client_key
  @client_key
end

.formatObject

Returns the value of attribute format.



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

def format
  @format
end

.plugin_idObject

Returns the value of attribute plugin_id.



14
15
16
# File 'lib/god/contacts/scout.rb', line 14

def plugin_id
  @plugin_id
end

Instance Attribute Details

#client_keyObject

Returns the value of attribute client_key.



26
27
28
# File 'lib/god/contacts/scout.rb', line 26

def client_key
  @client_key
end

#plugin_idObject

Returns the value of attribute plugin_id.



26
27
28
# File 'lib/god/contacts/scout.rb', line 26

def plugin_id
  @plugin_id
end

Instance Method Details

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



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/god/contacts/scout.rb', line 35

def notify(message, time, priority, category, host)
  data = {
    :client_key => arg(:client_key),
    :plugin_id => arg(:plugin_id),
    :format => 'xml',
    'alert[subject]' => message,
    'alert[body]' => Scout.format.call(message, priority, category, host)
  }

  uri = URI.parse('http://scoutapp.com/alerts/create')
  Net::HTTP.post_form(uri, data)

  self.info = "sent scout alert to plugin ##{plugin_id}"
rescue => e
  applog(nil, :info, "failed to send scout alert to plugin ##{plugin_id}: #{e.message}")
  applog(nil, :debug, e.backtrace.join("\n"))
end

#valid?Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
# File 'lib/god/contacts/scout.rb', line 28

def valid?
  valid = true
  valid &= complain("Attribute 'client_key' must be specified", self) unless arg(:client_key)
  valid &= complain("Attribute 'plugin_id' must be specified", self) unless arg(:plugin_id)
  valid
end