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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e8704318472d7accf7172d0e3f58b35897b61052
4
- data.tar.gz: 4c4be284cdb705f6b60f613b14c3dcfa85feec9d
3
+ metadata.gz: 891bf686f630e7da27233f067a15204226062373
4
+ data.tar.gz: 99c6841b45bcfbe93eeb05ba58727f4cc13425bc
5
5
  SHA512:
6
- metadata.gz: 631757991b3c8662cdadaeb7df9a7408384297f04a2ef36f38b8417ca56747b80001f26f1e19a380b61ca2380032a3b11a38243374c446db192c1b3f69c40c07
7
- data.tar.gz: 6dc1ec4e3f218a0d8dbde1164135ee7b3d86ab9b60ea98477faed2c08a08384bf53ce3df80bbeaa37c3b355d6869e339cc5a75c91321f767a49d9738eb8122e2
6
+ metadata.gz: 93d4fd6775f014e4046d1753465f11016708ba46e011984676669ab149c6b10bfc96822251e607599e1bb729ae0644e9b00bf4e66e168a80c6060f0dd7002dec
7
+ data.tar.gz: 306d42e62ba6dd27603a7ae5a09c5b76c59fec1ae957642ee3c39f61d47af321ec642bf4e88dae3629b7ad115ff4e8dc44e1f0cbc27ab1dc94203229b2e5bf59
@@ -1,66 +1,53 @@
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 emoji
25
- # case self.issue.code
26
- # when 0
27
- # ":happy_obama:"
28
- # when 1
29
- # ":sad_obama:"
30
- # when 2
31
- # ":surprised_obama"
32
- # else
33
- # ":obama_mic_drop"
34
- # end
35
- # end
36
- #
37
- # def text
38
- # data = OpenStruct.new({
39
- # notifu_id: self.issue.notifu_id,
40
- # host: self.issue.host,
41
- # service: self.issue.service,
42
- # message: self.issue.message,
43
- # status: self.issue.code.to_state,
44
- # first_event: Time.at(self.issue.time_created.to_i),
45
- # duration: (Time.now.to_i - self.issue.time_created.to_i).duration,
46
- # occurrences_count: self.issue.occurrences_count,
47
- # occurrences_trigger: self.issue.occurrences_trigger
48
- # })
49
- # ERB.new(self.template).result(data.instance_eval {binding})
50
- # end
51
- #
52
- # def act
53
- # self.contacts.each do |contact|
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
@@ -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 template
13
- "<%= data[:status] %> [<%= data[:host] %>/<%= data[:service] %>]: <%= data[:message] %> (<%= data[:duration] %>) NID:<%= data[:notifu_id] %>]"
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: "https://sensu.skypicker.com/#/client/#{Notifu::CONFIG[:actors][:slack][:dc]}/#{self.issue.host}?check=#{self.issue.service}",
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: self.post_data,
91
+ body: data,
78
92
  expects: [ 200 ],
79
93
  idempotent: true
80
94
  )
data/lib/notifu/config.rb CHANGED
@@ -3,7 +3,7 @@ module Notifu
3
3
 
4
4
  attr_reader :config
5
5
 
6
- @@config_path = "/etc/notifu/"
6
+ @@config_path = "/etc/notifu/" # FIXME: should be parametrized
7
7
 
8
8
  def initialize
9
9
  begin
@@ -117,4 +117,4 @@ module Notifu
117
117
  end
118
118
  end
119
119
  end
120
- end
120
+ end
@@ -6,8 +6,8 @@ module Notifu
6
6
  attribute :full_name
7
7
  attribute :cell
8
8
  attribute :mail
9
- attribute :jabber
10
- attribute :slack_url
9
+ attribute :slack_id
10
+ attribute :slack_rich
11
11
  attribute :pagerduty_url
12
12
  index :name
13
13
  unique :name
@@ -3,6 +3,7 @@ module Notifu
3
3
  class Event
4
4
  include Notifu::Util
5
5
  attr_reader :notifu_id
6
+ attr_reader :datacenter
6
7
  attr_reader :host
7
8
  attr_reader :address
8
9
  attr_reader :service
@@ -3,6 +3,7 @@ module Notifu
3
3
  class Issue < Ohm::Model
4
4
  include Notifu::Util
5
5
  attribute :notifu_id
6
+ attribute :datacenter
6
7
  attribute :host
7
8
  attribute :address
8
9
  attribute :service
@@ -64,6 +64,7 @@ module Sensu::Extension
64
64
 
65
65
  payload = {
66
66
  notifu_id: notifu_id,
67
+ datacenter: event[:client][:datacenter] || 'default',
67
68
  host: event[:client][:name],
68
69
  address: event[:client][:address],
69
70
  service: event[:check][:name],
@@ -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
- silenced = true if stash["path"] == path
285
+ return true if stash["path"] == path
287
286
  end
288
287
 
289
- return silenced
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 "#{self.event.api_endpoint}/stashes"
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 "#{self.event.api_endpoint}/stashes/silence/#{self.event.host}/#{self.event.service}"
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
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-25 00:00:00.000000000 Z
11
+ date: 2016-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor