notifu 1.5.7 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/notifu +4 -8
- data/lib/notifu/actors/pagerduty.rb +4 -3
- data/lib/notifu/cli.rb +4 -1
- data/lib/notifu/model/contact.rb +1 -1
- data/lib/notifu/model/event.rb +1 -0
- data/lib/notifu/model/issue.rb +1 -0
- data/lib/notifu/workers/processor.rb +11 -12
- data/lib/notifu.rb +4 -9
- metadata +2 -3
- data/lib/notifu/sensu/handler.rb +0 -105
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9364470e12c8804cc66f80ab480218251a1eb7ab
|
4
|
+
data.tar.gz: e97654f25362cb83f20f6d7ac8b9d96f8c3efec4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fe267fffbe74b86fe8076977beba3fd1b7dd0893dbfda97b548434a49cdf00d5cdfde31b95c691e59f77e10587705bb468116cd0a81a5553156aac5731b7e4c
|
7
|
+
data.tar.gz: b6c714aae5e7e294a47599545dfffec0c5a70356537775e56af2add97b2a5cad9f860dc6535ac7462f9a69c89a6f42f74948daec08a1592ce1ffeb9aa2a0f438
|
data/bin/notifu
CHANGED
@@ -1,15 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
path = File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__
|
4
|
-
$basepath = '/' + File.dirname(path).split('/')[1..-2].join('/') + '/lib/notifu/'
|
5
|
-
$actorpath = $basepath + "actors/"
|
6
|
-
# $sidekiq_bin = $basepath.sub(/app\//, '') + ".rvm/wrappers/notifu/sidekiq"
|
7
|
-
$sidekiq_bin = "sidekiq"
|
8
|
-
|
9
3
|
require 'notifu'
|
10
4
|
|
11
|
-
|
5
|
+
$basepath = Gem::Specification.find_by_name('notifu').gem_dir + '/lib/notifu/'
|
6
|
+
$actorpath = $basepath + "actors/"
|
7
|
+
$sidekiq_bin = Gem.bin_path('sidekiq', 'sidekiq')
|
12
8
|
|
9
|
+
Notifu::CONFIG = Notifu::Config.new.get
|
13
10
|
Ohm.redis = Redic.new Notifu::CONFIG[:redis_data]
|
14
|
-
|
15
11
|
Notifu::CLI::Root.start(ARGV)
|
@@ -10,7 +10,7 @@ module Notifu
|
|
10
10
|
self.retry = 3
|
11
11
|
|
12
12
|
def template
|
13
|
-
|
13
|
+
"<%= data[:status] %> [<%= data[:host] %>/<%= data[:service] %>]: <%= data[:message] %> (<%= data[:duration] %>) NID:<%= data[:notifu_id] %>]"
|
14
14
|
end
|
15
15
|
|
16
16
|
def post_data
|
@@ -31,14 +31,15 @@ module Notifu
|
|
31
31
|
first_event: Time.at(self.issue.time_created.to_i),
|
32
32
|
duration: (Time.now.to_i - self.issue.time_created.to_i).duration,
|
33
33
|
occurrences_count: self.issue.occurrences_count,
|
34
|
-
occurrences_trigger: self.issue.occurrences_trigger
|
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}"
|
35
36
|
})
|
36
37
|
ERB.new(self.template).result(data.instance_eval {binding})
|
37
38
|
end
|
38
39
|
|
39
40
|
def act
|
40
41
|
self.contacts.each do |contact|
|
41
|
-
Excon.post(
|
42
|
+
Excon.post(Notifu::CONFIG[:actors][:slack][:url],
|
42
43
|
tcp_nodelay: true,
|
43
44
|
headers: { "ContentType" => "application/json" },
|
44
45
|
body: self.post_data,
|
data/lib/notifu/cli.rb
CHANGED
data/lib/notifu/model/contact.rb
CHANGED
data/lib/notifu/model/event.rb
CHANGED
data/lib/notifu/model/issue.rb
CHANGED
@@ -276,14 +276,14 @@ module Notifu
|
|
276
276
|
|
277
277
|
def silenced?
|
278
278
|
if self.event.service == "keepalive"
|
279
|
-
|
279
|
+
id = "silence/#{self.event.host}"
|
280
280
|
else
|
281
|
-
|
281
|
+
id = "silence/#{self.event.host}/#{self.event.service}"
|
282
282
|
end
|
283
283
|
|
284
|
-
|
284
|
+
get_silenced.each do |stash|
|
285
285
|
begin
|
286
|
-
return true if stash["
|
286
|
+
return true if stash["id"] == id
|
287
287
|
rescue NoMethodError
|
288
288
|
return false
|
289
289
|
end
|
@@ -360,14 +360,13 @@ module Notifu
|
|
360
360
|
##
|
361
361
|
# get stashes from Sensu API
|
362
362
|
#
|
363
|
-
def
|
364
|
-
return @stashes if @stashes
|
363
|
+
def get_silenced
|
365
364
|
begin
|
366
|
-
sensu_api = Excon.get("#{self.event.api_endpoint}/
|
367
|
-
|
368
|
-
rescue
|
369
|
-
|
370
|
-
|
365
|
+
sensu_api = Excon.get("#{self.event.api_endpoint}/silenced", user: Notifu::CONFIG[:sensu_api][:username], password: Notifu::CONFIG[:sensu_api][:password])
|
366
|
+
return JSON.parse sensu_api.body
|
367
|
+
rescue Exception => e
|
368
|
+
log "error", "Failed to get stashes #{self.event.api_endpoint}/stashes (#{e.message})"
|
369
|
+
return []
|
371
370
|
end
|
372
371
|
end
|
373
372
|
|
@@ -377,7 +376,7 @@ module Notifu
|
|
377
376
|
#
|
378
377
|
def unsilence!
|
379
378
|
path = "silence/#{self.event.host}/#{self.event.service}"
|
380
|
-
|
379
|
+
get_silenced.each do |stash|
|
381
380
|
if stash["path"] == path
|
382
381
|
if stash["expire"] < 0
|
383
382
|
if self.event.unsilence
|
data/lib/notifu.rb
CHANGED
@@ -1,17 +1,12 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "yaml"
|
2
|
+
require "json"
|
3
|
+
require "thor"
|
4
|
+
require "ohm"
|
5
5
|
require "notifu/mixins"
|
6
6
|
require "notifu/util"
|
7
7
|
require "notifu/config"
|
8
8
|
require "notifu/logger"
|
9
9
|
require "notifu/model"
|
10
|
-
require "notifu/model/contact"
|
11
|
-
require "notifu/model/event"
|
12
|
-
require "notifu/model/group"
|
13
|
-
require "notifu/model/issue"
|
14
|
-
require "notifu/model/sla"
|
15
10
|
require "notifu/cli/service"
|
16
11
|
require "notifu/cli/object"
|
17
12
|
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.
|
4
|
+
version: 1.6.0
|
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:
|
11
|
+
date: 2017-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -277,7 +277,6 @@ files:
|
|
277
277
|
- lib/notifu/model/group.rb
|
278
278
|
- lib/notifu/model/issue.rb
|
279
279
|
- lib/notifu/model/sla.rb
|
280
|
-
- lib/notifu/sensu/handler.rb
|
281
280
|
- lib/notifu/util.rb
|
282
281
|
- lib/notifu/workers/actor.rb
|
283
282
|
- lib/notifu/workers/processor.rb
|
data/lib/notifu/sensu/handler.rb
DELETED
@@ -1,105 +0,0 @@
|
|
1
|
-
require 'sensu/redis'
|
2
|
-
require 'digest'
|
3
|
-
require 'json'
|
4
|
-
|
5
|
-
module Sensu::Extension
|
6
|
-
class Notifu < Handler
|
7
|
-
|
8
|
-
def definition
|
9
|
-
{
|
10
|
-
type: 'extension',
|
11
|
-
name: 'notifu'
|
12
|
-
}
|
13
|
-
end
|
14
|
-
|
15
|
-
def name
|
16
|
-
definition[:name]
|
17
|
-
end
|
18
|
-
|
19
|
-
def options
|
20
|
-
return @options if @options
|
21
|
-
@options = {
|
22
|
-
:host => '127.0.0.1',
|
23
|
-
:port => 6379,
|
24
|
-
:db => 2
|
25
|
-
}
|
26
|
-
if @settings[:notifu].is_a?(Hash)
|
27
|
-
@options.merge!(@settings[:notifu])
|
28
|
-
end
|
29
|
-
@options
|
30
|
-
end
|
31
|
-
|
32
|
-
def description
|
33
|
-
'Notifu handler for Sensu Server'
|
34
|
-
end
|
35
|
-
|
36
|
-
def post_init
|
37
|
-
|
38
|
-
if @redis
|
39
|
-
yield(@redis)
|
40
|
-
else
|
41
|
-
Sensu::Redis.connect(options) do |connection|
|
42
|
-
connection.auto_reconnect = false
|
43
|
-
connection.reconnect_on_error = true
|
44
|
-
connection.on_error do |error|
|
45
|
-
@logger.warn(error)
|
46
|
-
end
|
47
|
-
@redis = connection
|
48
|
-
end
|
49
|
-
end
|
50
|
-
@redis.sadd("queues", "processor")
|
51
|
-
end
|
52
|
-
|
53
|
-
def run(event_data)
|
54
|
-
event = JSON.parse(event_data, { :symbolize_names => true })
|
55
|
-
notifu_id = Digest::SHA256.hexdigest("#{event[:client][:name]}:#{event[:client][:address]}:#{event[:check][:name]}").to_s[-10,10]
|
56
|
-
|
57
|
-
if event[:check][:name] == "keepalive"
|
58
|
-
sgs = event[:client][:sgs]
|
59
|
-
sgs ||= event[:client][:sla]
|
60
|
-
else
|
61
|
-
sgs = event[:check][:sgs]
|
62
|
-
sgs ||= event[:check][:sla]
|
63
|
-
end
|
64
|
-
|
65
|
-
payload = {
|
66
|
-
notifu_id: notifu_id,
|
67
|
-
datacenter: event[:client][:datacenter] || 'default',
|
68
|
-
host: event[:client][:name],
|
69
|
-
address: event[:client][:address],
|
70
|
-
service: event[:check][:name],
|
71
|
-
occurrences_trigger: event[:check][:occurrences],
|
72
|
-
occurrences_count: event[:occurrences],
|
73
|
-
interval: event[:check][:interval] || 0,
|
74
|
-
time_last_event: event[:check][:executed],
|
75
|
-
sgs: sgs,
|
76
|
-
action: event[:action],
|
77
|
-
code: event[:check][:status],
|
78
|
-
message: event[:check][:output],
|
79
|
-
duration: event[:check][:duration],
|
80
|
-
api_endpoint: "http://" + @settings[:api][:host].to_s + ":" + @settings[:api][:port].to_s
|
81
|
-
}
|
82
|
-
|
83
|
-
job = {
|
84
|
-
'class' => 'Notifu::Processor',
|
85
|
-
'args' => [ payload ],
|
86
|
-
'jid' => SecureRandom.hex(12),
|
87
|
-
'retry' => true,
|
88
|
-
'enqueued_at' => Time.now.to_f
|
89
|
-
}
|
90
|
-
|
91
|
-
begin
|
92
|
-
@redis.lpush("queue:processor", JSON.dump(job))
|
93
|
-
rescue Exception => e
|
94
|
-
yield "failed to send event to Notifu #{e.message}", 1
|
95
|
-
end
|
96
|
-
|
97
|
-
yield "sent event to Notifu #{notifu_id}", 0
|
98
|
-
end
|
99
|
-
|
100
|
-
def stop
|
101
|
-
yield
|
102
|
-
end
|
103
|
-
|
104
|
-
end
|
105
|
-
end
|