notifu 1.5.7 → 1.6.0

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: 430135e0520fe3009d65af3a7f52e3113c88c8c7
4
- data.tar.gz: 962b2ee3c40d65e3b255c992cb2837124bdf1580
3
+ metadata.gz: 9364470e12c8804cc66f80ab480218251a1eb7ab
4
+ data.tar.gz: e97654f25362cb83f20f6d7ac8b9d96f8c3efec4
5
5
  SHA512:
6
- metadata.gz: 7c955f1a0c6b575d53ffe31dabd042d1974d2b3b43698b2ba4f5f0c82bcfdda96f53923b5a69184555767a1c570b00465f5ff73d55228054d68ca8eb45d1465c
7
- data.tar.gz: 912bf319e15d9d43f6409653504cb1eb59202f395c35e97514c88e21079caf7db3ec05420a4df7ffbb9e9ff520108934f4c49b2815817e17e9c3e78f1c2eea76
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
- Notifu::CONFIG = Notifu::Config.new.get
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
- "<%= data[:status] %> [<%= data[:host] %>/<%= data[:service] %>]: <%= data[:message] %> (<%= data[:duration] %>) NID:<%= data[:notifu_id] %>]"
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(contact.slack_url,
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
@@ -1,3 +1,6 @@
1
+ require "notifu/cli/service"
2
+ require "notifu/cli/object"
3
+
1
4
  module Notifu
2
5
  module CLI
3
6
  class Root < Thor
@@ -10,4 +13,4 @@ module Notifu
10
13
  subcommand "service", Service
11
14
  end
12
15
  end
13
- end
16
+ end
@@ -8,7 +8,7 @@ module Notifu
8
8
  attribute :mail
9
9
  attribute :slack_id
10
10
  attribute :slack_rich
11
- attribute :pagerduty_url
11
+ attribute :pagerduty_id
12
12
  index :name
13
13
  unique :name
14
14
 
@@ -18,6 +18,7 @@ module Notifu
18
18
  attr_reader :code
19
19
  attr_reader :aspiring_code
20
20
  attr_reader :message
21
+ attr_reader :playbook
21
22
  attr_reader :api_endpoint
22
23
  attr_reader :duration
23
24
  attr_reader :unsilence
@@ -19,6 +19,7 @@ module Notifu
19
19
  attribute :code
20
20
  attribute :aspiring_code
21
21
  attribute :message
22
+ attribute :playbook
22
23
  attribute :process_result
23
24
  attribute :api_endpoint
24
25
  attribute :duration
@@ -276,14 +276,14 @@ module Notifu
276
276
 
277
277
  def silenced?
278
278
  if self.event.service == "keepalive"
279
- path = "silence/#{self.event.host}"
279
+ id = "silence/#{self.event.host}"
280
280
  else
281
- path = "silence/#{self.event.host}/#{self.event.service}"
281
+ id = "silence/#{self.event.host}/#{self.event.service}"
282
282
  end
283
283
 
284
- get_stashes.each do |stash|
284
+ get_silenced.each do |stash|
285
285
  begin
286
- return true if stash["path"] == path
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 get_stashes
364
- return @stashes if @stashes
363
+ def get_silenced
365
364
  begin
366
- sensu_api = Excon.get("#{self.event.api_endpoint}/stashes", user: Notifu::CONFIG[:sensu_api][:username], password: Notifu::CONFIG[:sensu_api][:password])
367
- @stashes = JSON.parse sensu_api.body
368
- rescue
369
- @stashes = []
370
- log "error", "Failed to get stashes #{self.event.api_endpoint}/stashes"
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
- get_stashes.each do |stash|
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 'yaml'
2
- require 'json'
3
- require 'thor'
4
- require 'ohm'
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.5.7
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: 2016-12-14 00:00:00.000000000 Z
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
@@ -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