notifu 1.6.0 → 1.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9364470e12c8804cc66f80ab480218251a1eb7ab
4
- data.tar.gz: e97654f25362cb83f20f6d7ac8b9d96f8c3efec4
3
+ metadata.gz: 854992e5b4ebb8c15056b86c0a3237040af3b8be
4
+ data.tar.gz: 8328abddbed1e6b6c72f4edc1e3e326c362676ae
5
5
  SHA512:
6
- metadata.gz: 8fe267fffbe74b86fe8076977beba3fd1b7dd0893dbfda97b548434a49cdf00d5cdfde31b95c691e59f77e10587705bb468116cd0a81a5553156aac5731b7e4c
7
- data.tar.gz: b6c714aae5e7e294a47599545dfffec0c5a70356537775e56af2add97b2a5cad9f860dc6535ac7462f9a69c89a6f42f74948daec08a1592ce1ffeb9aa2a0f438
6
+ metadata.gz: d40c16982b46c70b53e4632f1ae7f625b961a81acef48474c4d254e76ca2a78a829bd2a9cf7061ba82ef6ca6d59a0d750bb79368aeea13e8683d445c2510684f
7
+ data.tar.gz: ea4b78c0e5eebbc2f914f3eb7dea09f2ca35cb8c16a09650f8a8c00f5bc63ff5b6e3c88ab304a2354ad91b83f2e719e64f3957fe205ce0e2d9dc19744cdccfe5
@@ -9,43 +9,59 @@ module Notifu
9
9
  self.desc = "Sends event to pagerduty"
10
10
  self.retry = 3
11
11
 
12
- def template
13
- "<%= data[:status] %> [<%= data[:host] %>/<%= data[:service] %>]: <%= data[:message] %> (<%= data[:duration] %>) NID:<%= data[:notifu_id] %>]"
14
- end
15
-
16
- def post_data
12
+ def post_data(type, service_id)
17
13
  {
18
- text: self.text,
19
- username: "notifu",
20
- icon_emoji: self.emoji
21
- }.to_json
14
+ service_key: service_id,
15
+ event_type: type,
16
+ description: self.text,
17
+ incident_key: self.issue.notifu_id,
18
+ details: {
19
+ status: self.issue.code.to_state,
20
+ dc: self.issue.datacenter,
21
+ host: self.issue.host,
22
+ service: self.issue.service,
23
+ message: self.issue.message,
24
+ first_event: Time.at(self.issue.time_created.to_i),
25
+ },
26
+ client: "Sensu",
27
+ client_url: "#{Notifu::CONFIG[:uchiwa_url]}/#/client/#{self.issue.datacenter}/#{self.issue.host}?check=#{self.issue.service}"
28
+ }
22
29
  end
23
30
 
24
31
  def text
25
32
  data = OpenStruct.new({
26
33
  notifu_id: self.issue.notifu_id,
34
+ datacenter: self.issue.datacenter,
27
35
  host: self.issue.host,
28
36
  service: self.issue.service,
29
37
  message: self.issue.message,
30
- status: self.issue.code.to_state,
31
- first_event: Time.at(self.issue.time_created.to_i),
32
- duration: (Time.now.to_i - self.issue.time_created.to_i).duration,
33
- occurrences_count: self.issue.occurrences_count,
34
- occurrences_trigger: self.issue.occurrences_trigger,
35
- uchiwa_url: "#{Notifu::CONFIG[:uchiwa_url]}/#/client/#{self.issue.datacenter}/#{self.issue.host}?check=#{self.issue.service}"
38
+ status: self.issue.code.to_state
36
39
  })
37
40
  ERB.new(self.template).result(data.instance_eval {binding})
38
41
  end
39
42
 
43
+ def template
44
+ "<%= data[:status] %> [<%= data[:datacenter] %>/<%= data[:host] %>/<%= data[:service] %>]: <%= data[:message] %>"
45
+ end
46
+
40
47
  def act
48
+ type = "resolve" if self.issue.code.to_i == 0
49
+ type ||= "trigger"
50
+
41
51
  self.contacts.each do |contact|
42
- Excon.post(Notifu::CONFIG[:actors][:slack][:url],
52
+ begin
53
+ c = contact.pagerduty_id
54
+ rescue
55
+ c = false
56
+ end
57
+
58
+ Excon.post(Notifu::CONFIG[:actors][:pagerduty][:url],
43
59
  tcp_nodelay: true,
44
60
  headers: { "ContentType" => "application/json" },
45
- body: self.post_data,
61
+ body: self.post_data(type, c).to_json,
46
62
  expects: [ 200 ],
47
63
  idempotent: true,
48
- )
64
+ ) if c
49
65
  end
50
66
  end
51
67
 
@@ -9,7 +9,7 @@ module Notifu
9
9
  self.desc = "Notifies to Slack channel via Webhook"
10
10
  self.retry = 3
11
11
 
12
- def post_data(rich)
12
+ def post_data(rich = false)
13
13
  return {
14
14
  username: "notifu",
15
15
  icon_emoji: ":loudspeaker:",
@@ -34,12 +34,12 @@ module Notifu
34
34
  ]
35
35
  }
36
36
  ]
37
- }.to_json if rich
38
- {
37
+ } if rich
38
+ return {
39
39
  username: "notifu",
40
40
  icon_emoji: ":loudspeaker:",
41
41
  text: self.text
42
- }.to_json
42
+ }
43
43
  end
44
44
 
45
45
  def color
@@ -64,10 +64,7 @@ module Notifu
64
64
  service: self.issue.service,
65
65
  message: self.issue.message,
66
66
  status: self.issue.code.to_state,
67
- first_event: Time.at(self.issue.time_created.to_i),
68
67
  duration: (Time.now.to_i - self.issue.time_created.to_i).duration,
69
- occurrences_count: self.issue.occurrences_count,
70
- occurrences_trigger: self.issue.occurrences_trigger,
71
68
  uchiwa_url: "#{Notifu::CONFIG[:uchiwa_url]}/#/client/#{self.issue.datacenter}/#{self.issue.host}?check=#{self.issue.service}"
72
69
  })
73
70
  ERB.new(self.template).result(data.instance_eval {binding})
@@ -81,14 +78,16 @@ module Notifu
81
78
  def act
82
79
  self.contacts.each do |contact|
83
80
  begin
84
- data = { channel: contact.slack_id }.merge(self.post_data(contact.slack_rich))
81
+ data = { channel: contact.slack_id }.merge(self.post_data(contact.slack_rich)) if contact.slack_rich
82
+ data ||= { channel: contact.slack_id }.merge(self.post_data)
85
83
  rescue
86
84
  data = self.post_data
87
85
  end
86
+ puts data.to_yaml
88
87
  Excon.post(Notifu::CONFIG[:actors][:slack][:url],
89
88
  tcp_nodelay: true,
90
89
  headers: { "ContentType" => "application/json" },
91
- body: data,
90
+ body: data.to_json,
92
91
  expects: [ 200 ],
93
92
  idempotent: true
94
93
  )
@@ -45,12 +45,12 @@ module Notifu
45
45
 
46
46
  def perform *args
47
47
  t_start = Time.now.to_f*1000.0
48
- log "info", "Task start"
48
+ log "debug", "Task start"
49
49
 
50
50
  # read event
51
51
  self.event = Notifu::Model::Event.new args
52
52
  self.now = Time.now
53
- log "info", "Processing event NID #{self.event.notifu_id}"
53
+ log "debug", "Processing event NID #{self.event.notifu_id}"
54
54
 
55
55
  # try to check if we already know about the issue, otherwise save it into DB as a new one
56
56
  self.issue = Notifu::Model::Issue.with(:notifu_id, self.event.notifu_id)
@@ -61,7 +61,7 @@ module Notifu
61
61
 
62
62
  t_finish = Time.now.to_f*1000.0
63
63
 
64
- log "info", "Task finish (in #{t_finish-t_start}ms)"
64
+ log "debug", "Task finish (in #{t_finish-t_start}ms)"
65
65
  end
66
66
 
67
67
  ###################################################################
data/lib/notifu.rb CHANGED
@@ -7,6 +7,4 @@ require "notifu/util"
7
7
  require "notifu/config"
8
8
  require "notifu/logger"
9
9
  require "notifu/model"
10
- require "notifu/cli/service"
11
- require "notifu/cli/object"
12
10
  require "notifu/cli"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notifu
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Radek 'blufor' Slavicinsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-10 00:00:00.000000000 Z
11
+ date: 2017-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor