notifu 1.6.0 → 1.6.1
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 +34 -18
- data/lib/notifu/actors/slack.rb +8 -9
- data/lib/notifu/workers/processor.rb +3 -3
- data/lib/notifu.rb +0 -2
- 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: 854992e5b4ebb8c15056b86c0a3237040af3b8be
|
4
|
+
data.tar.gz: 8328abddbed1e6b6c72f4edc1e3e326c362676ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
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
|
|
data/lib/notifu/actors/slack.rb
CHANGED
@@ -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
|
-
}
|
38
|
-
{
|
37
|
+
} if rich
|
38
|
+
return {
|
39
39
|
username: "notifu",
|
40
40
|
icon_emoji: ":loudspeaker:",
|
41
41
|
text: self.text
|
42
|
-
}
|
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 "
|
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 "
|
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 "
|
64
|
+
log "debug", "Task finish (in #{t_finish-t_start}ms)"
|
65
65
|
end
|
66
66
|
|
67
67
|
###################################################################
|
data/lib/notifu.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2017-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|