sensu-plugins-edgelab 1.13.0 → 1.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/handler-multi-hipchat.rb +139 -0
- metadata +35 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e25e0c5ae2a5c5b6d69cc607b9d87e115aa3d71f
|
4
|
+
data.tar.gz: 8c680d4beab1d89e0d33c6b58d018c3eac7d8af2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe7ce51186caf435880c94b7b97662dbfe2b9cea1ff87c85573d290bd7bfa7bb02d0d1cd2a3c4df01a7ce9d5f5371dfe1c6f22cd0d893918db8fc5b874d08106
|
7
|
+
data.tar.gz: 7e30e3e28ac3080e213ad0daff4f434fde1334fc496b6756551fbb2e843bf1280df8311b2a3ea48825bb62bb7ce22c92bd1cd1e1ce008f7a9245c558b547afe3
|
@@ -0,0 +1,139 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Sensu Handler: hipchat
|
4
|
+
#
|
5
|
+
# This handler script is used to send notifications to Hipchat rooms.
|
6
|
+
#
|
7
|
+
# Input:
|
8
|
+
# @event - Event attributes.
|
9
|
+
# @event['action'] - Property to figure out the event type i.e. whether it is create or resolve.
|
10
|
+
# @event['check'] - Map of attributes from the check config which is calling this handler
|
11
|
+
# @event['client'] - Map of attributes from the client config for the clients from which this event is generated.
|
12
|
+
# option: json_config - By default, assumes the hipchat config parameters are in the "hipchat" top-level json key.
|
13
|
+
# This command line option allows to specify a custom json key.
|
14
|
+
#
|
15
|
+
# Output:
|
16
|
+
# Green coloured notification on the Hipchat room if a resolve event is seen.
|
17
|
+
# Yellow coloured notification used to notify warning if a create event is seen with a status of 1
|
18
|
+
# Red coloured notification used to notify critical if a create event is seen with a status other than 1
|
19
|
+
#
|
20
|
+
# Note: The handler config is fetched and merged from all json config files. The "hipchat" json key is used by default which can
|
21
|
+
# be overridden with the "json_config" command line option. The hipchat room could also be configured on a per client basis
|
22
|
+
# by defining the "hipchat_room" attribute in the client config file. This will override the default hipchat room where the
|
23
|
+
# alerts are being routed to for that particular client.
|
24
|
+
|
25
|
+
require 'sensu-handler'
|
26
|
+
require 'hipchat'
|
27
|
+
require 'timeout'
|
28
|
+
require 'erb'
|
29
|
+
require 'json'
|
30
|
+
|
31
|
+
class HipChatNotif < Sensu::Handler
|
32
|
+
option :json_config,
|
33
|
+
description: 'JSON config key name',
|
34
|
+
short: '-j JsonKeyName',
|
35
|
+
long: '--json_config JsonKeyName',
|
36
|
+
required: false,
|
37
|
+
default: 'hipchat'
|
38
|
+
|
39
|
+
def event_name
|
40
|
+
@event['client']['name'] + '/' + @event['check']['name']
|
41
|
+
end
|
42
|
+
|
43
|
+
def handle
|
44
|
+
json_config = config[:json_config]
|
45
|
+
server_url = settings[json_config]['server_url'] || 'https://api.hipchat.com'
|
46
|
+
apiversion = settings[json_config]['apiversion'] || 'v1'
|
47
|
+
proxy_url = settings[json_config]['proxy_url']
|
48
|
+
hipchatmsg = HipChat::Client.new(settings[json_config]['apikey'], api_version: apiversion, http_proxy: proxy_url, server_url: server_url)
|
49
|
+
from = settings[json_config]['from'] || 'Sensu'
|
50
|
+
|
51
|
+
room = @event['client']['hipchat_room'] || @event['check']['hipchat_room'] || settings[json_config]['room']
|
52
|
+
|
53
|
+
mentions = @event['check']['hipchat_mentions'] || []
|
54
|
+
if not mentions.kind_of?(Array)
|
55
|
+
mentions = [mentions]
|
56
|
+
end
|
57
|
+
mentions = mentions.map{ |e| String(e) }
|
58
|
+
|
59
|
+
puts "Will mentions: #{mentions}"
|
60
|
+
puts "Will send to room: #{room}"
|
61
|
+
|
62
|
+
message_template = settings[json_config]['message_template']
|
63
|
+
message_format = settings[json_config]['message_format'] || 'html'
|
64
|
+
|
65
|
+
# If the playbook attribute exists and is a URL, "[<a href='url'>playbook</a>]" will be output.
|
66
|
+
# To control the link name, set the playbook value to the HTML output you would like.
|
67
|
+
playbook = ''
|
68
|
+
if @event['check']['playbook']
|
69
|
+
begin
|
70
|
+
uri = URI.parse(@event['check']['playbook'])
|
71
|
+
playbook << if %w( http https ).include?(uri.scheme)
|
72
|
+
" [<a href='#{@event['check']['playbook']}'>Playbook</a>]"
|
73
|
+
else
|
74
|
+
" Playbook: #{@event['check']['playbook']}"
|
75
|
+
end
|
76
|
+
rescue
|
77
|
+
playbook << " Playbook: #{@event['check']['playbook']}"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
if message_template && File.readable?(message_template)
|
82
|
+
template = File.read(message_template)
|
83
|
+
else
|
84
|
+
template = '''<%=
|
85
|
+
[
|
86
|
+
@event["action"].eql?("resolve") ? "RESOLVED" : "ALERT",
|
87
|
+
" - [#{event_name}] - ",
|
88
|
+
@event["check"]["notification"] || @event["check"]["output"],
|
89
|
+
playbook,
|
90
|
+
"."
|
91
|
+
].join
|
92
|
+
%>'''
|
93
|
+
end
|
94
|
+
eruby = ERB.new(template)
|
95
|
+
message = eruby.result(binding)
|
96
|
+
|
97
|
+
if @event['action'].eql?('resolve')
|
98
|
+
color = 'green'
|
99
|
+
notify = false
|
100
|
+
elsif @event['action'].eql?('flapping')
|
101
|
+
color = [0, 1].include?(@event['check']['status']) ? 'yellow' : 'red'
|
102
|
+
notify = false
|
103
|
+
else
|
104
|
+
color = @event['check']['status'] == 1 ? 'yellow' : 'red'
|
105
|
+
notify = true
|
106
|
+
end
|
107
|
+
|
108
|
+
mentions = mentions.map{|user| "@#{user}"}.join(", ")
|
109
|
+
|
110
|
+
if mentions and message_format != "html" and not @event['action'].eql?('resolve')
|
111
|
+
# Add the mention only if the action is not resolved.
|
112
|
+
message = "#{message} #{mentions}"
|
113
|
+
end
|
114
|
+
|
115
|
+
begin
|
116
|
+
Timeout.timeout(5) do
|
117
|
+
hipchatmsg[room].send(from, message,
|
118
|
+
color: color,
|
119
|
+
notify: notify,
|
120
|
+
message_format: message_format)
|
121
|
+
end
|
122
|
+
rescue Timeout::Error
|
123
|
+
puts "Timed out while attempting to message #{room}"
|
124
|
+
end
|
125
|
+
|
126
|
+
if message_format == 'html' and mentions and not @event['action'].eql?('resolve')
|
127
|
+
# HTML messages won't notify when using @mentions.
|
128
|
+
begin
|
129
|
+
Timeout.timeout(5) do
|
130
|
+
hipchatmsg[room].send(from, mentions,
|
131
|
+
color: color,
|
132
|
+
message_format: "text")
|
133
|
+
end
|
134
|
+
rescue Timeout::Error
|
135
|
+
puts "Timed out while attempting to send mentions to #{room}"
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
metadata
CHANGED
@@ -1,29 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-plugins-edgelab
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edgelab
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: aws-sdk
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.3'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: cassandra-driver
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.2.2
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.2.2
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: diplomat
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,33 +53,33 @@ dependencies:
|
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: 2.0.2
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
56
|
+
name: hipchat
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - '='
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
61
|
+
version: 1.5.1
|
48
62
|
type: :runtime
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
66
|
- - '='
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
68
|
+
version: 1.5.1
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: inifile
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - '='
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
75
|
+
version: 3.0.0
|
62
76
|
type: :runtime
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
80
|
- - '='
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
82
|
+
version: 3.0.0
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: json
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,33 +109,33 @@ dependencies:
|
|
95
109
|
- !ruby/object:Gem::Version
|
96
110
|
version: 3.2.1
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
112
|
+
name: rest-client
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
100
114
|
requirements:
|
101
|
-
- -
|
115
|
+
- - '='
|
102
116
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
117
|
+
version: 1.8.0
|
104
118
|
type: :runtime
|
105
119
|
prerelease: false
|
106
120
|
version_requirements: !ruby/object:Gem::Requirement
|
107
121
|
requirements:
|
108
|
-
- -
|
122
|
+
- - '='
|
109
123
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
124
|
+
version: 1.8.0
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
126
|
+
name: sensu-plugin
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
114
128
|
requirements:
|
115
129
|
- - "~>"
|
116
130
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
131
|
+
version: '1.2'
|
118
132
|
type: :runtime
|
119
133
|
prerelease: false
|
120
134
|
version_requirements: !ruby/object:Gem::Requirement
|
121
135
|
requirements:
|
122
136
|
- - "~>"
|
123
137
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
138
|
+
version: '1.2'
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
140
|
name: bundler
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -179,6 +193,7 @@ executables:
|
|
179
193
|
- metrics-redis-key-pattern.rb
|
180
194
|
- check-cassandra-nodes.rb
|
181
195
|
- metrics-aws-elb.rb
|
196
|
+
- handler-multi-hipchat.rb
|
182
197
|
- check-logstash-pipeline.rb
|
183
198
|
- metrics-aws-asg.rb
|
184
199
|
extensions: []
|
@@ -191,6 +206,7 @@ files:
|
|
191
206
|
- bin/check-nomad-jobs.rb
|
192
207
|
- bin/check-nomad-leader.rb
|
193
208
|
- bin/check-swarm-cluster.rb
|
209
|
+
- bin/handler-multi-hipchat.rb
|
194
210
|
- bin/metrics-aws-asg.rb
|
195
211
|
- bin/metrics-aws-elb.rb
|
196
212
|
- bin/metrics-aws-rds.rb
|