notifu 1.5.4 → 1.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/notifu/actors/pagerduty.rb +53 -66
- data/lib/notifu/actors/slack.rb +23 -9
- data/lib/notifu/config.rb +2 -2
- data/lib/notifu/model/contact.rb +2 -2
- data/lib/notifu/model/event.rb +1 -0
- data/lib/notifu/model/issue.rb +1 -0
- data/lib/notifu/sensu/handler.rb +1 -0
- data/lib/notifu/workers/processor.rb +4 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 891bf686f630e7da27233f067a15204226062373
|
4
|
+
data.tar.gz: 99c6841b45bcfbe93eeb05ba58727f4cc13425bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93d4fd6775f014e4046d1753465f11016708ba46e011984676669ab149c6b10bfc96822251e607599e1bb729ae0644e9b00bf4e66e168a80c6060f0dd7002dec
|
7
|
+
data.tar.gz: 306d42e62ba6dd27603a7ae5a09c5b76c59fec1ae957642ee3c39f61d47af321ec642bf4e88dae3629b7ad115ff4e8dc44e1f0cbc27ab1dc94203229b2e5bf59
|
@@ -1,66 +1,53 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
# Excon.post(contact.slack_url,
|
55
|
-
# tcp_nodelay: true,
|
56
|
-
# headers: { "ContentType" => "application/json" },
|
57
|
-
# body: self.post_data,
|
58
|
-
# expects: [ 200 ],
|
59
|
-
# idempotent: true,
|
60
|
-
# )
|
61
|
-
# end
|
62
|
-
# end
|
63
|
-
#
|
64
|
-
# end
|
65
|
-
# end
|
66
|
-
# end
|
1
|
+
module Notifu
|
2
|
+
module Actors
|
3
|
+
class Pagerduty < Notifu::Actor
|
4
|
+
|
5
|
+
require 'excon'
|
6
|
+
require 'erb'
|
7
|
+
|
8
|
+
self.name = "pagerduty"
|
9
|
+
self.desc = "Sends event to pagerduty"
|
10
|
+
self.retry = 3
|
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
|
17
|
+
{
|
18
|
+
text: self.text,
|
19
|
+
username: "notifu",
|
20
|
+
icon_emoji: self.emoji
|
21
|
+
}.to_json
|
22
|
+
end
|
23
|
+
|
24
|
+
def text
|
25
|
+
data = OpenStruct.new({
|
26
|
+
notifu_id: self.issue.notifu_id,
|
27
|
+
host: self.issue.host,
|
28
|
+
service: self.issue.service,
|
29
|
+
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
|
+
})
|
36
|
+
ERB.new(self.template).result(data.instance_eval {binding})
|
37
|
+
end
|
38
|
+
|
39
|
+
def act
|
40
|
+
self.contacts.each do |contact|
|
41
|
+
Excon.post(contact.slack_url,
|
42
|
+
tcp_nodelay: true,
|
43
|
+
headers: { "ContentType" => "application/json" },
|
44
|
+
body: self.post_data,
|
45
|
+
expects: [ 200 ],
|
46
|
+
idempotent: true,
|
47
|
+
)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/notifu/actors/slack.rb
CHANGED
@@ -9,12 +9,8 @@ module Notifu
|
|
9
9
|
self.desc = "Notifies to Slack channel via Webhook"
|
10
10
|
self.retry = 3
|
11
11
|
|
12
|
-
def
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
def post_data
|
17
|
-
{
|
12
|
+
def post_data(rich)
|
13
|
+
return {
|
18
14
|
username: "notifu",
|
19
15
|
icon_emoji: ":loudspeaker:",
|
20
16
|
attachments: [
|
@@ -22,7 +18,7 @@ module Notifu
|
|
22
18
|
fallback: self.text,
|
23
19
|
color: self.color,
|
24
20
|
title: "#{self.issue.host} - #{self.issue.service}",
|
25
|
-
title_link: "
|
21
|
+
title_link: "#{Notifu::CONFIG[:uchiwa_url]}/#/client/#{self.issue.datacenter}/#{self.issue.host}?check=#{self.issue.service}",
|
26
22
|
text: self.issue.message,
|
27
23
|
fields: [
|
28
24
|
{
|
@@ -38,6 +34,11 @@ module Notifu
|
|
38
34
|
]
|
39
35
|
}
|
40
36
|
]
|
37
|
+
}.to_json if rich
|
38
|
+
{
|
39
|
+
username: "notifu",
|
40
|
+
icon_emoji: ":loudspeaker:",
|
41
|
+
text: self.text
|
41
42
|
}.to_json
|
42
43
|
end
|
43
44
|
|
@@ -54,9 +55,11 @@ module Notifu
|
|
54
55
|
end
|
55
56
|
end
|
56
57
|
|
58
|
+
# fallback simple message (templated, see below)
|
57
59
|
def text
|
58
60
|
data = OpenStruct.new({
|
59
61
|
notifu_id: self.issue.notifu_id,
|
62
|
+
datacenter: self.issue.datacenter,
|
60
63
|
host: self.issue.host,
|
61
64
|
service: self.issue.service,
|
62
65
|
message: self.issue.message,
|
@@ -64,17 +67,28 @@ module Notifu
|
|
64
67
|
first_event: Time.at(self.issue.time_created.to_i),
|
65
68
|
duration: (Time.now.to_i - self.issue.time_created.to_i).duration,
|
66
69
|
occurrences_count: self.issue.occurrences_count,
|
67
|
-
occurrences_trigger: self.issue.occurrences_trigger
|
70
|
+
occurrences_trigger: self.issue.occurrences_trigger,
|
71
|
+
uchiwa_url: "#{Notifu::CONFIG[:uchiwa_url]}/#/client/#{self.issue.datacenter}/#{self.issue.host}?check=#{self.issue.service}"
|
68
72
|
})
|
69
73
|
ERB.new(self.template).result(data.instance_eval {binding})
|
70
74
|
end
|
71
75
|
|
76
|
+
# template for fallback message
|
77
|
+
def template
|
78
|
+
"**<%= data[:status] %>** [<<%= data[:uchiwa_url] %>|<%= data[:datacenter]%>/<%= data[:host] %>/<%= data[:service] %>>]: <%= data[:message] %> (<%= data[:duration] %>)"
|
79
|
+
end
|
80
|
+
|
72
81
|
def act
|
73
82
|
self.contacts.each do |contact|
|
83
|
+
begin
|
84
|
+
data = { channel: contact.slack_id }.merge(self.post_data(contact.slack_rich))
|
85
|
+
rescue
|
86
|
+
data = self.post_data
|
87
|
+
end
|
74
88
|
Excon.post(contact.slack_url,
|
75
89
|
tcp_nodelay: true,
|
76
90
|
headers: { "ContentType" => "application/json" },
|
77
|
-
body:
|
91
|
+
body: data,
|
78
92
|
expects: [ 200 ],
|
79
93
|
idempotent: true
|
80
94
|
)
|
data/lib/notifu/config.rb
CHANGED
data/lib/notifu/model/contact.rb
CHANGED
data/lib/notifu/model/event.rb
CHANGED
data/lib/notifu/model/issue.rb
CHANGED
data/lib/notifu/sensu/handler.rb
CHANGED
@@ -281,12 +281,11 @@ module Notifu
|
|
281
281
|
path = "silence/#{self.event.host}/#{self.event.service}"
|
282
282
|
end
|
283
283
|
|
284
|
-
silenced = false
|
285
284
|
get_stashes.each do |stash|
|
286
|
-
|
285
|
+
return true if stash["path"] == path
|
287
286
|
end
|
288
287
|
|
289
|
-
|
288
|
+
false
|
290
289
|
end
|
291
290
|
|
292
291
|
def is_ok?
|
@@ -361,7 +360,7 @@ module Notifu
|
|
361
360
|
def get_stashes
|
362
361
|
return @stashes if @stashes
|
363
362
|
begin
|
364
|
-
sensu_api = Excon.get
|
363
|
+
sensu_api = Excon.get("#{self.event.api_endpoint}/stashes", user: Notifu::CONFIG[:sensu_api][:username], password: Notifu::CONFIG[:sensu_api][:password])
|
365
364
|
@stashes = JSON.parse sensu_api.body
|
366
365
|
rescue
|
367
366
|
@stashes = []
|
@@ -380,7 +379,7 @@ module Notifu
|
|
380
379
|
if stash["expire"] < 0
|
381
380
|
if self.event.unsilence
|
382
381
|
begin
|
383
|
-
Excon.delete
|
382
|
+
Excon.delete("#{self.event.api_endpoint}/stashes/silence/#{self.event.host}/#{self.event.service}", user: Notifu::CONFIG[:sensu_api][:username], password: Notifu::CONFIG[:sensu_api][:password])
|
384
383
|
log "info", "Unstashed #{self.event.host}/#{self.event.service} after recovery"
|
385
384
|
rescue
|
386
385
|
log "warning", "Failed to fetch stashes from Sensu API: #{self.event.api_endpoint}/stashes"
|
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.5.
|
4
|
+
version: 1.5.5
|
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: 2016-
|
11
|
+
date: 2016-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|