Class: God::Contacts::Webhook

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

Instance Attribute Summary collapse

Attributes inherited from God::Contact

#group, #info, #name

Instance Method Summary collapse

Methods inherited from God::Contact

#friendly_name, generate, normalize, valid?

Methods included from God::Configurable

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

Instance Attribute Details

#hook_urlObject

Returns the value of attribute hook_url.



16
17
18
# File 'lib/god/contacts/webhook.rb', line 16

def hook_url
  @hook_url
end

Instance Method Details

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



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

def notify(message, time, priority, category, host)
  begin
    data = {
      :message => message,
      :time => time,
      :priority => priority,
      :category => category,
      :host => host
    }

    uri = URI.parse(self.hook_url)
    Net::HTTP.post_form(uri, data)

    self.info = "sent webhook to #{self.hook_url}"
  rescue => e
    puts e.message
    puts e.backtrace.join("\n")

    self.info = "failed to send webhook to #{self.hook_url}: #{e.message}"
  end
end

#valid?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/god/contacts/webhook.rb', line 18

def valid?
  valid = true
end