notifu 1.3 → 1.5.0

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: 994e38866699525bde6908ad8b458c98acd88b89
4
- data.tar.gz: b0e33e904bf623cfc47dcd542b6ed64aa157972a
3
+ metadata.gz: 1761d2e113d9e193af0eabe605988243e0eb1117
4
+ data.tar.gz: 3f092bd0a0e794e93eb8278b8b074cb0a32f6f5a
5
5
  SHA512:
6
- metadata.gz: b87558e9046b0c46c13417ce889bc26031e66dafdc1fd5d08a035334f8cea5468a425bc1a64c563142dce2f7d9942e77b032888bea6f8bbe50c8249e85a7280e
7
- data.tar.gz: 34b271eb7bde8bcc29ab6b4ab69a47b79afd0ff3721296f6ccb1081d55ece1040bac8dc84c8c679ae824e04a052b70506b9d2166604eb2a6426e1173f9b148b0
6
+ metadata.gz: 95133fc5f420c42814deeff1ce6ada2c17f490a3ebf9da03b6b3bfb6cfad92b9460ac20a0a105c7bb0368aa49b86afe719e23dab1739a9045010517cfc2e39d2
7
+ data.tar.gz: 1d32e5bcd08363f8ce7ada2b0d2e576ca6f558504a7d719c39cfd581bd28cc5a8fa9257ace17fecfbc4ac20568aae31d4e7a49178c041ce48101f8912aba66b3
@@ -0,0 +1,66 @@
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
@@ -0,0 +1,66 @@
1
+ module Notifu
2
+ module Actors
3
+ class Slack < Notifu::Actor
4
+
5
+ require 'excon'
6
+ require 'erb'
7
+
8
+ self.name = "slack"
9
+ self.desc = "Notifies to Slack channel via Webhook"
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
@@ -7,9 +7,11 @@ module Notifu
7
7
  attribute :cell
8
8
  attribute :mail
9
9
  attribute :jabber
10
+ attribute :slack_url
11
+ attribute :pagerduty_url
10
12
  index :name
11
13
  unique :name
12
14
 
13
15
  end
14
16
  end
15
- end
17
+ end
@@ -1,6 +1,6 @@
1
1
  require 'sensu/redis'
2
2
  require 'digest'
3
- require 'multi_json'
3
+ require 'json'
4
4
 
5
5
  module Sensu::Extension
6
6
  class Notifu < Handler
@@ -88,7 +88,7 @@ module Sensu::Extension
88
88
  }
89
89
 
90
90
  begin
91
- @redis.lpush("queue:processor", MultiJson.dump(job))
91
+ @redis.lpush("queue:processor", JSON.dump(job))
92
92
  rescue Exception => e
93
93
  yield "failed to send event to Notifu #{e.message}", 1
94
94
  end
@@ -102,4 +102,3 @@ module Sensu::Extension
102
102
 
103
103
  end
104
104
  end
105
-
@@ -1,8 +1,6 @@
1
1
  ##
2
2
  # Require block
3
3
  #
4
- # require 'rubygems'
5
- # require 'bundler/setup'
6
4
  require "ohm"
7
5
  require "elasticsearch"
8
6
  require "log4r/outputter/syslogoutputter"
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.3'
4
+ version: 1.5.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-11-18 00:00:00.000000000 Z
11
+ date: 2016-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -261,8 +261,7 @@ files:
261
261
  - lib/notifu.rb
262
262
  - lib/notifu/actors/gammu_sms_bridge.rb
263
263
  - lib/notifu/actors/pagerduty.rb
264
- - lib/notifu/actors/slack_chan.rb
265
- - lib/notifu/actors/slack_msg.rb
264
+ - lib/notifu/actors/slack.rb
266
265
  - lib/notifu/actors/smtp.rb
267
266
  - lib/notifu/actors/stdout.rb
268
267
  - lib/notifu/actors/twilio_call.rb
@@ -1,29 +0,0 @@
1
- module Notifu
2
- module Actors
3
- class SlackChan < Notifu::Actor
4
-
5
- require 'excon'
6
- require 'erb'
7
-
8
- self.name = "slack_msg"
9
- self.desc = "Sends message to a Slack contact"
10
- self.retry = 3
11
-
12
-
13
- def act
14
- cfg = Notifu::CONFIG[:actors][:slack]
15
- contacts = self.contacts.map { |contact| contact.cell }
16
- req_string = Notifu::CONFIG[:actors][:twilio_call][:api] +
17
- "?token=" + Notifu::CONFIG[:actors][:twilio_call][:token] +
18
- "&status=" + self.issue.code.to_state +
19
- "&hostname=" + self.issue.host +
20
- "&service=" + self.issue.service +
21
- "&description=" + ERB::Util.url_encode(self.issue.message.to_s) +
22
- "&call_group=" + ERB::Util.url_encode(contacts.to_json) +
23
- "&init=1"
24
- Excon.get req_string if self.issue.code.to_i == 2
25
- end
26
-
27
- end
28
- end
29
- end
@@ -1,29 +0,0 @@
1
- module Notifu
2
- module Actors
3
- class SlackMsg < Notifu::Actor
4
-
5
- require 'excon'
6
- require 'erb'
7
-
8
- self.name = "slack_msg"
9
- self.desc = "Sends message to a Slack contact"
10
- self.retry = 3
11
-
12
-
13
- def act
14
- cfg = Notifu::CONFIG[:actors][:slack]
15
- contacts = self.contacts.map { |contact| contact.cell }
16
- req_string = Notifu::CONFIG[:actors][:twilio_call][:api] +
17
- "?token=" + Notifu::CONFIG[:actors][:twilio_call][:token] +
18
- "&status=" + self.issue.code.to_state +
19
- "&hostname=" + self.issue.host +
20
- "&service=" + self.issue.service +
21
- "&description=" + ERB::Util.url_encode(self.issue.message.to_s) +
22
- "&call_group=" + ERB::Util.url_encode(contacts.to_json) +
23
- "&init=1"
24
- Excon.get req_string if self.issue.code.to_i == 2
25
- end
26
-
27
- end
28
- end
29
- end