sensu-plugins-slack 0.0.4 → 0.1.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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +14 -2
- data/README.md +3 -2
- data/bin/handler-slack-multichannel.rb +216 -0
- data/bin/handler-slack.rb +2 -6
- data/lib/sensu-plugins-slack/version.rb +2 -2
- data.tar.gz.sig +0 -0
- metadata +9 -7
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa3ad254dff9a4bdacf22ac50e4c1bef87910fb4
|
4
|
+
data.tar.gz: 7b09d2c2e40e949f9248c4b72b9818849a48d7a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8aa5e19e94ce77ee7dad46b0609d57acdaade31620cd95b56ce9591261823590dcc5d72ef752f179faabf3c20edcc597d07b956b975afbac79612c2d58698a9b
|
7
|
+
data.tar.gz: 53ca73e8bc885a05f6336b64aad8650f07bdaa1f32b40e9139b36fe32cd9ceeb2dec7344e442a028cf5a747c2ecc3d713621dc5a3ec3df9ee15efcfa20ec513f
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
@@ -3,8 +3,20 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
3
3
|
|
4
4
|
This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)
|
5
5
|
|
6
|
-
## Unreleased
|
6
|
+
## Unreleased
|
7
7
|
|
8
|
+
## [0.1.0] - 2015-11-12
|
9
|
+
### Added
|
10
|
+
- New handler-slack-multichannel.rb handler for more complex multi-channel alerting to Slack
|
11
|
+
- Allow the client to set the channel
|
12
|
+
|
13
|
+
### Changed
|
14
|
+
- updated sensu-plugin gem to 1.2.0
|
15
|
+
|
16
|
+
### Fixed
|
17
|
+
- Fixed exception caused by missing field
|
18
|
+
|
19
|
+
## [0.0.4] - 2015-07-13
|
8
20
|
### Changed
|
9
21
|
- put gemspec deps in alpha order
|
10
22
|
- remove cruft from sensu-plugins-slack.rb
|
@@ -15,7 +27,7 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
|
|
15
27
|
|
16
28
|
## [0.0.3] - 2015-06-03
|
17
29
|
### Added
|
18
|
-
-additional functionality to slack hander to improve generated output
|
30
|
+
- additional functionality to slack hander to improve generated output
|
19
31
|
|
20
32
|
## [0.0.2] - 2015-06-03
|
21
33
|
### Fixed
|
data/README.md
CHANGED
@@ -5,12 +5,13 @@
|
|
5
5
|
[](https://codeclimate.com/github/sensu-plugins/sensu-plugins-slack)
|
6
6
|
[](https://codeclimate.com/github/sensu-plugins/sensu-plugins-slack)
|
7
7
|
[](https://gemnasium.com/sensu-plugins/sensu-plugins-slack)
|
8
|
-
[
|
8
|
+
[](https://codeship.com/projects/82829)
|
9
9
|
|
10
10
|
## Functionality
|
11
11
|
|
12
12
|
## Files
|
13
|
-
* handler-slack.rb
|
13
|
+
* bin/handler-slack.rb
|
14
|
+
* bin/handler-slack-multichannel.rb
|
14
15
|
|
15
16
|
## Usage
|
16
17
|
```
|
@@ -0,0 +1,216 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Copyright 2014 Dan Shultz and contributors.
|
4
|
+
# Multichannel support added in 2015 by Rob Wilson
|
5
|
+
#
|
6
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
7
|
+
# for details.
|
8
|
+
#
|
9
|
+
# In order to use this plugin, you must first configure an incoming webhook
|
10
|
+
# integration in slack. You can create the required webhook by visiting
|
11
|
+
# https://{your team}.slack.com/services/new/incoming-webhook
|
12
|
+
#
|
13
|
+
# After you configure your webhook, you'll need the webhook URL from the integration.
|
14
|
+
#
|
15
|
+
# Multi-channel support:
|
16
|
+
#
|
17
|
+
# Default channels and compulsory channels can be set in the handler config:
|
18
|
+
#
|
19
|
+
# { "handlers":
|
20
|
+
# "slack": {
|
21
|
+
# "channels" {
|
22
|
+
# "default": [ "#no-team-alerts" ],
|
23
|
+
# "compulsory": [ "#all-alerts" ],
|
24
|
+
# }
|
25
|
+
# }
|
26
|
+
# }
|
27
|
+
#
|
28
|
+
# Alerts are always sent to the compulsory channel(s).
|
29
|
+
#
|
30
|
+
# Alerts are sent to default channels if no channels are configured
|
31
|
+
# in the check config.
|
32
|
+
#
|
33
|
+
# Check specific channels:
|
34
|
+
#
|
35
|
+
# { "checks":
|
36
|
+
# "check_my_db": {
|
37
|
+
# "handlers": [ "default", "slack" ],
|
38
|
+
# "slack" {
|
39
|
+
# "channels" [ "#db-team-alerts" ]
|
40
|
+
# }
|
41
|
+
# ...,
|
42
|
+
# }
|
43
|
+
# }
|
44
|
+
|
45
|
+
require 'sensu-handler'
|
46
|
+
require 'json'
|
47
|
+
|
48
|
+
class Slack < Sensu::Handler
|
49
|
+
option :json_config,
|
50
|
+
description: 'Configuration name',
|
51
|
+
short: '-j JSONCONFIG',
|
52
|
+
long: '--json JSONCONFIG',
|
53
|
+
default: 'slack'
|
54
|
+
|
55
|
+
def slack_webhook_url
|
56
|
+
get_setting('webhook_url')
|
57
|
+
end
|
58
|
+
|
59
|
+
def slack_proxy_addr
|
60
|
+
get_setting('proxy_addr')
|
61
|
+
end
|
62
|
+
|
63
|
+
def slack_proxy_port
|
64
|
+
get_setting('proxy_port')
|
65
|
+
end
|
66
|
+
|
67
|
+
def slack_message_prefix
|
68
|
+
get_setting('message_prefix')
|
69
|
+
end
|
70
|
+
|
71
|
+
def slack_bot_name
|
72
|
+
get_setting('bot_name')
|
73
|
+
end
|
74
|
+
|
75
|
+
def slack_surround
|
76
|
+
get_setting('surround')
|
77
|
+
end
|
78
|
+
|
79
|
+
def default_channels
|
80
|
+
return get_setting('channels')['default']
|
81
|
+
rescue
|
82
|
+
return []
|
83
|
+
end
|
84
|
+
|
85
|
+
def compulsory_channels
|
86
|
+
return get_setting('channels')['compulsory']
|
87
|
+
rescue
|
88
|
+
return false
|
89
|
+
end
|
90
|
+
|
91
|
+
def check_configured_channels
|
92
|
+
return @event['check']['slack']['channels']
|
93
|
+
rescue
|
94
|
+
return false
|
95
|
+
end
|
96
|
+
|
97
|
+
def compile_channel_list
|
98
|
+
channels = []
|
99
|
+
|
100
|
+
if check_configured_channels
|
101
|
+
channels = check_configured_channels
|
102
|
+
puts "using check configured channels: #{channels.join('.').chomp(',')}"
|
103
|
+
else
|
104
|
+
channels = default_channels
|
105
|
+
puts "using check default channels: #{default_channels.join(',').chomp(',')}"
|
106
|
+
end
|
107
|
+
|
108
|
+
if compulsory_channels
|
109
|
+
channels |= compulsory_channels
|
110
|
+
puts "adding compulsory channels: #{compulsory_channels.join(',').chomp(',')}"
|
111
|
+
end
|
112
|
+
|
113
|
+
puts "target channels: #{channels.join(',').chomp(',')}"
|
114
|
+
|
115
|
+
channels
|
116
|
+
end
|
117
|
+
|
118
|
+
def slack_channels
|
119
|
+
@channels ||= compile_channel_list
|
120
|
+
end
|
121
|
+
|
122
|
+
def markdown_enabled
|
123
|
+
get_setting('markdown_enabled') || true
|
124
|
+
end
|
125
|
+
|
126
|
+
def incident_key
|
127
|
+
@event['client']['name'] + '/' + @event['check']['name']
|
128
|
+
end
|
129
|
+
|
130
|
+
def get_setting(name)
|
131
|
+
settings[config[:json_config]][name]
|
132
|
+
end
|
133
|
+
|
134
|
+
def build_notice
|
135
|
+
"#{@event['check']['status'].to_s.rjust(3)} | #{incident_key}: #{@event['check']['output'].strip}"
|
136
|
+
end
|
137
|
+
|
138
|
+
def handle
|
139
|
+
unless slack_channels.is_a?(Array)
|
140
|
+
puts 'nno channels found'
|
141
|
+
return
|
142
|
+
end
|
143
|
+
|
144
|
+
notice = build_notice
|
145
|
+
|
146
|
+
slack_channels.each do |channel|
|
147
|
+
puts "#{channel}: #{notice}"
|
148
|
+
post_data(notice, channel)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def post_data(notice, channel)
|
153
|
+
uri = URI(slack_webhook_url)
|
154
|
+
|
155
|
+
if (defined?(slack_proxy_addr)).nil?
|
156
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
157
|
+
else
|
158
|
+
http = Net::HTTP::Proxy(slack_proxy_addr, slack_proxy_port).new(uri.host, uri.port)
|
159
|
+
end
|
160
|
+
|
161
|
+
http.use_ssl = true
|
162
|
+
|
163
|
+
begin
|
164
|
+
req = Net::HTTP::Post.new("#{uri.path}?#{uri.query}")
|
165
|
+
text = slack_surround ? slack_surround + notice + slack_surround : notice
|
166
|
+
req.body = payload(text, channel).to_json
|
167
|
+
|
168
|
+
puts "request: #{req}"
|
169
|
+
|
170
|
+
response = http.request(req)
|
171
|
+
|
172
|
+
puts "response: #{response}"
|
173
|
+
|
174
|
+
verify_response(response)
|
175
|
+
rescue => error
|
176
|
+
puts "error making http request: #{error}"
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
def verify_response(response)
|
181
|
+
case response
|
182
|
+
when Net::HTTPSuccess
|
183
|
+
true
|
184
|
+
else
|
185
|
+
fail response.error!
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
def payload(notice, channel)
|
190
|
+
{
|
191
|
+
icon_url: 'http://sensuapp.org/img/sensu_logo_large-c92d73db.png',
|
192
|
+
attachments: [{
|
193
|
+
text: [slack_message_prefix, notice].compact.join(' '),
|
194
|
+
color: color
|
195
|
+
}]
|
196
|
+
}.tap do |payload|
|
197
|
+
payload[:channel] = channel
|
198
|
+
payload[:username] = slack_bot_name if slack_bot_name
|
199
|
+
payload[:attachments][0][:mrkdwn_in] = %w(text) if markdown_enabled
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
def color
|
204
|
+
color = {
|
205
|
+
0 => '#36a64f',
|
206
|
+
1 => '#FFCC00',
|
207
|
+
2 => '#FF0000',
|
208
|
+
3 => '#6600CC'
|
209
|
+
}
|
210
|
+
color.fetch(check_status.to_i)
|
211
|
+
end
|
212
|
+
|
213
|
+
def check_status
|
214
|
+
@event['check']['status']
|
215
|
+
end
|
216
|
+
end
|
data/bin/handler-slack.rb
CHANGED
@@ -27,11 +27,7 @@ class Slack < Sensu::Handler
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def slack_channel
|
30
|
-
|
31
|
-
@event['check']['slack_channel']
|
32
|
-
else
|
33
|
-
get_setting('channel')
|
34
|
-
end
|
30
|
+
@event['client']['slack_channel'] || @event['check']['slack_channel'] || get_setting('channel')
|
35
31
|
end
|
36
32
|
|
37
33
|
def slack_message_prefix
|
@@ -113,7 +109,7 @@ class Slack < Sensu::Handler
|
|
113
109
|
fields.each do |field|
|
114
110
|
# arbritary based on what I feel like
|
115
111
|
# -vjanelle
|
116
|
-
is_short = true unless @event['client'][field].length > 50
|
112
|
+
is_short = true unless @event['client'].key?(field) && @event['client'][field].length > 50
|
117
113
|
client_fields << {
|
118
114
|
title: field,
|
119
115
|
value: @event['client'][field],
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-plugins-slack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sensu-Plugins and contributors
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
8sHuVruarogxxKPBzlL2is4EUb6oN/RdpGx2l4254+nyR+abg//Ed27Ym0PkB4lk
|
31
31
|
HP0m8WSjZmFr109pE/sVsM5jtOCvogyujQOjNVGN4gz1wwPr
|
32
32
|
-----END CERTIFICATE-----
|
33
|
-
date: 2015-
|
33
|
+
date: 2015-11-13 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: erubis
|
@@ -52,14 +52,14 @@ dependencies:
|
|
52
52
|
requirements:
|
53
53
|
- - '='
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: 1.
|
55
|
+
version: 1.2.0
|
56
56
|
type: :runtime
|
57
57
|
prerelease: false
|
58
58
|
version_requirements: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
60
|
- - '='
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: 1.
|
62
|
+
version: 1.2.0
|
63
63
|
- !ruby/object:Gem::Dependency
|
64
64
|
name: bundler
|
65
65
|
requirement: !ruby/object:Gem::Requirement
|
@@ -150,14 +150,14 @@ dependencies:
|
|
150
150
|
requirements:
|
151
151
|
- - '='
|
152
152
|
- !ruby/object:Gem::Version
|
153
|
-
version:
|
153
|
+
version: 0.32.1
|
154
154
|
type: :development
|
155
155
|
prerelease: false
|
156
156
|
version_requirements: !ruby/object:Gem::Requirement
|
157
157
|
requirements:
|
158
158
|
- - '='
|
159
159
|
- !ruby/object:Gem::Version
|
160
|
-
version:
|
160
|
+
version: 0.32.1
|
161
161
|
- !ruby/object:Gem::Dependency
|
162
162
|
name: rspec
|
163
163
|
requirement: !ruby/object:Gem::Requirement
|
@@ -190,12 +190,14 @@ description: Sensu plugins for interfacing with Slack chat
|
|
190
190
|
email: "<sensu-users@googlegroups.com>"
|
191
191
|
executables:
|
192
192
|
- handler-slack.rb
|
193
|
+
- handler-slack-multichannel.rb
|
193
194
|
extensions: []
|
194
195
|
extra_rdoc_files: []
|
195
196
|
files:
|
196
197
|
- CHANGELOG.md
|
197
198
|
- LICENSE
|
198
199
|
- README.md
|
200
|
+
- bin/handler-slack-multichannel.rb
|
199
201
|
- bin/handler-slack.rb
|
200
202
|
- lib/sensu-plugins-slack.rb
|
201
203
|
- lib/sensu-plugins-slack/version.rb
|
@@ -225,7 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
225
227
|
version: '0'
|
226
228
|
requirements: []
|
227
229
|
rubyforge_project:
|
228
|
-
rubygems_version: 2.4.
|
230
|
+
rubygems_version: 2.4.8
|
229
231
|
signing_key:
|
230
232
|
specification_version: 4
|
231
233
|
summary: Sensu plugins for interfacing with Slack chat
|
metadata.gz.sig
CHANGED
Binary file
|