Class: Notifu::Actors::Pagerduty

Inherits:
Notifu::Actor show all
Defined in:
lib/notifu/actors/pagerduty.rb

Instance Attribute Summary

Attributes inherited from Notifu::Actor

#contacts, #issue

Instance Method Summary collapse

Methods inherited from Notifu::Actor

#apply_template, #default_template, #load_data, #perform

Methods included from Util

action_log, log, option

Instance Method Details

#actObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/notifu/actors/pagerduty.rb', line 38

def act
  type = "resolve" if self.issue.code.to_i == 0
  type ||= "trigger"

  self.contacts.each do |contact|
    contact.pagerduty_id || next

    begin
      Excon.post(Notifu::CONFIG[:actors][:pagerduty][:url],
        tcp_nodelay: true,
        headers: { "ContentType" => "application/json" },
        body: self.post_data(type, c).to_json,
        expects: [ 200 ],
        idempotent: true,
      )
    rescue Exception => e
      log "error", "Failed to send event to PagerDuty - #{e.class}: #{e.message}"
    end
  end
end

#post_data(type, service_id) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/notifu/actors/pagerduty.rb', line 11

def post_data(type, service_id)
  {
    service_key: service_id,
    event_type: type,
    description: self.text,
    incident_key: self.issue.notifu_id,
    details: {
      host: self.issue.host,
      address: self.issue.address,
      service: self.issue.service,
      message: self.issue.message,
      status: self.issue.code.to_state,
      datacenter: self.issue.datacenter,
      first_event: Time.at(self.issue.time_created.to_i),
    },
    client: "Sensu",
    client_url: "#{Notifu::CONFIG[:uchiwa_url]}/#/client/#{self.issue.datacenter}/#{self.issue.host}?check=#{self.issue.service}"
  }
end

#text(c) ⇒ Object



31
32
33
34
35
# File 'lib/notifu/actors/pagerduty.rb', line 31

def text(c)
  t = c.pagerduty_template
  t ||= self.default_template
  self.apply_template t
end