logstash-output-slack 2.0.3 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +3 -0
- data/README.md +1 -1
- data/docs/index.asciidoc +1 -1
- data/lib/logstash/outputs/slack.rb +2 -1
- data/logstash-output-slack.gemspec +1 -1
- data/spec/outputs/slack_spec.rb +201 -240
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7e2dae06476ae2f501462eb76832aa5d2b24e6686bfe0bacc64a422a6b3676c7
|
4
|
+
data.tar.gz: 8115f85427fe509cfc28bf6812a77af90054530514ca511c84572c0ec8046df1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0c28f6a9714e3b1f39ef046c3583b5601c359ca72cd2f13c760472e4ce33c83a1584add02538d87153acb184f5410cd083da0820ae68e1ebd051a7221a3a515
|
7
|
+
data.tar.gz: def643b508f11e9859b4257da6ff193bd8e92f3c5717e9d5f5f0224283bd20c6606a0277cff16d96e17c3b8923a0d47f749452c81347cc9e6d63fc18ed676f6f
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
[![Build Status](https://travis-ci.org/
|
1
|
+
[![Build Status](https://travis-ci.org/logstash-plugins/logstash-output-slack.svg?branch=master)](https://travis-ci.org/logstash-plugins/logstash-output-slack)
|
2
2
|
|
3
3
|
Reviews of the code/contributions are very welcome (particularly with testing!), since I don't really know Ruby.
|
4
4
|
|
data/docs/index.asciidoc
CHANGED
@@ -42,6 +42,7 @@ class LogStash::Outputs::Slack < LogStash::Outputs::Base
|
|
42
42
|
|
43
43
|
payload_json = Hash.new
|
44
44
|
payload_json['text'] = event.sprintf(@format)
|
45
|
+
url = event.sprintf(@url)
|
45
46
|
|
46
47
|
if not @channel.nil?
|
47
48
|
payload_json['channel'] = event.sprintf(@channel)
|
@@ -75,7 +76,7 @@ class LogStash::Outputs::Slack < LogStash::Outputs::Base
|
|
75
76
|
|
76
77
|
begin
|
77
78
|
RestClient.post(
|
78
|
-
|
79
|
+
url,
|
79
80
|
"payload=#{CGI.escape(JSON.dump(payload_json))}",
|
80
81
|
:accept => "application/json",
|
81
82
|
:'User-Agent' => "logstash-output-slack",
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'logstash-output-slack'
|
3
|
-
s.version = '2.0
|
3
|
+
s.version = '2.1.0'
|
4
4
|
s.licenses = ['MIT','Apache License (2.0)']
|
5
5
|
s.summary = "Write events to Slack"
|
6
6
|
s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"
|
data/spec/outputs/slack_spec.rb
CHANGED
@@ -2,17 +2,22 @@ require_relative "../spec_helper"
|
|
2
2
|
|
3
3
|
describe LogStash::Outputs::Slack do
|
4
4
|
|
5
|
+
subject { described_class.new(config) }
|
6
|
+
let(:config) { { } }
|
7
|
+
let(:event) { LogStash::Event.new(data) }
|
8
|
+
let(:data) { {} }
|
9
|
+
|
5
10
|
# Actually do most of the boiler plate by stubbing out the request, running
|
6
11
|
# the logstash pipeline, and asserting that a request was made with the
|
7
12
|
# expected JSON.
|
8
|
-
def test_one_event(
|
13
|
+
def test_one_event(event, expected_json, expected_url = "http://requestb.in/r9lkbzr9")
|
9
14
|
stub_request(:post, "requestb.in").
|
10
15
|
to_return(:body => "", :status => 200,
|
11
16
|
:headers => { 'Content-Length' => 0 })
|
12
17
|
|
13
|
-
|
18
|
+
subject.receive(event)
|
14
19
|
|
15
|
-
expect(a_request(:post,
|
20
|
+
expect(a_request(:post, expected_url).
|
16
21
|
with(:body => "payload=#{CGI.escape(JSON.dump(expected_json))}",
|
17
22
|
:headers => {
|
18
23
|
'Content-Type' => 'application/x-www-form-urlencoded',
|
@@ -22,275 +27,231 @@ describe LogStash::Outputs::Slack do
|
|
22
27
|
to have_been_made.once
|
23
28
|
end
|
24
29
|
|
25
|
-
before do
|
30
|
+
before(:each) do
|
31
|
+
subject.register
|
26
32
|
WebMock.disable_net_connect!
|
27
33
|
end
|
28
34
|
|
29
|
-
after do
|
35
|
+
after(:each) do
|
30
36
|
WebMock.reset!
|
31
37
|
WebMock.allow_net_connect!
|
32
38
|
end
|
33
39
|
|
34
|
-
context "passes the right payload to slack
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
}
|
39
|
-
logstash_config = <<-CONFIG
|
40
|
-
input {
|
41
|
-
generator {
|
42
|
-
message => "This message should show in slack"
|
43
|
-
count => 1
|
44
|
-
}
|
45
|
-
}
|
46
|
-
output {
|
47
|
-
slack {
|
48
|
-
url => "http://requestb.in/r9lkbzr9"
|
49
|
-
}
|
50
|
-
}
|
51
|
-
CONFIG
|
40
|
+
context "passes the right payload to slack" do
|
41
|
+
context "simple" do
|
42
|
+
let(:data) { { "message" => "This message should show in slack" } }
|
43
|
+
let(:config) { { "url" => "http://requestb.in/r9lkbzr9" } }
|
52
44
|
|
53
|
-
|
45
|
+
it "uses all default values" do
|
46
|
+
expected_json = { :text => "This message should show in slack" }
|
47
|
+
test_one_event(event, expected_json)
|
48
|
+
end
|
54
49
|
end
|
55
50
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
}
|
84
|
-
}
|
85
|
-
CONFIG
|
86
|
-
|
87
|
-
test_one_event(logstash_config, expected_json)
|
51
|
+
context "with multiple interpolations" do
|
52
|
+
let(:data) { {
|
53
|
+
"message" => "This message should show in slack",
|
54
|
+
"x" => "3",
|
55
|
+
"channelname" => "mychannel",
|
56
|
+
"username" => "slackbot"
|
57
|
+
} }
|
58
|
+
|
59
|
+
let(:config) { {
|
60
|
+
"url" => "http://requestb.in/r9lkbzr9",
|
61
|
+
"format" => "%{message} %{x}",
|
62
|
+
"channel" => "%{channelname}",
|
63
|
+
"username" => "%{username}",
|
64
|
+
"icon_emoji" => ":chart_with_upwards_trend:",
|
65
|
+
"icon_url" => "http://lorempixel.com/48/48",
|
66
|
+
} }
|
67
|
+
|
68
|
+
it "uses and formats all provided values" do
|
69
|
+
expected_json = {
|
70
|
+
:text => "This message should show in slack 3",
|
71
|
+
:channel => "mychannel",
|
72
|
+
:username => "slackbot",
|
73
|
+
:icon_emoji => ":chart_with_upwards_trend:",
|
74
|
+
:icon_url => "http://lorempixel.com/48/48"
|
75
|
+
}
|
76
|
+
test_one_event(event, expected_json)
|
77
|
+
end
|
88
78
|
end
|
89
79
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
}
|
116
|
-
CONFIG
|
117
|
-
|
118
|
-
test_one_event(logstash_config, expected_json)
|
80
|
+
context "if the message contains no interpolations" do
|
81
|
+
|
82
|
+
let(:data) { {
|
83
|
+
"message" => "This message should show in slack"
|
84
|
+
} }
|
85
|
+
|
86
|
+
let(:config) { {
|
87
|
+
"url" => "http://requestb.in/r9lkbzr9",
|
88
|
+
"format" => "Unformatted message",
|
89
|
+
"channel" => "mychannel",
|
90
|
+
"username" => "slackbot",
|
91
|
+
"icon_emoji" => ":chart_with_upwards_trend:",
|
92
|
+
"icon_url" => "http://lorempixel.com/48/48"
|
93
|
+
} }
|
94
|
+
|
95
|
+
it "uses and formats all provided values" do
|
96
|
+
expected_json = {
|
97
|
+
:text => "Unformatted message",
|
98
|
+
:channel => "mychannel",
|
99
|
+
:username => "slackbot",
|
100
|
+
:icon_emoji => ":chart_with_upwards_trend:",
|
101
|
+
:icon_url => "http://lorempixel.com/48/48"
|
102
|
+
}
|
103
|
+
test_one_event(event, expected_json)
|
104
|
+
end
|
119
105
|
end
|
120
106
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
}
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
}
|
107
|
+
describe "default attachements" do
|
108
|
+
let(:config) { {
|
109
|
+
"url" => "http://requestb.in/r9lkbzr9",
|
110
|
+
"attachments" => [{ "image_url" => "http://example.com/image.png" }]
|
111
|
+
} }
|
112
|
+
|
113
|
+
context "when none are in the event" do
|
114
|
+
let(:data) { { "message" => "This message should show in slack" } }
|
115
|
+
it "uses the default" do
|
116
|
+
expected_json = {
|
117
|
+
:text => "This message should show in slack",
|
118
|
+
:attachments => [{:image_url => "http://example.com/image.png"}]
|
133
119
|
}
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
120
|
+
test_one_event(event, expected_json)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
context "when using multiple attachments" do
|
125
|
+
let(:data) { { "message" => "This message should show in slack" } }
|
126
|
+
let(:config) { {
|
127
|
+
"url" => "http://requestb.in/r9lkbzr9",
|
128
|
+
"attachments" => [
|
129
|
+
{"image_url" => "http://example.com/image1.png"},
|
130
|
+
{"image_url" => "http://example.com/image2.png"}
|
131
|
+
]
|
132
|
+
} }
|
133
|
+
it "sends them" do
|
134
|
+
expected_json = {
|
135
|
+
:text => "This message should show in slack",
|
136
|
+
:attachments => [{:image_url => "http://example.com/image1.png"},
|
137
|
+
{:image_url => "http://example.com/image2.png"}]
|
141
138
|
}
|
142
|
-
|
143
|
-
|
144
|
-
|
139
|
+
test_one_event(event, expected_json)
|
140
|
+
end
|
141
|
+
end
|
145
142
|
end
|
146
143
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
url => "http://requestb.in/r9lkbzr9"
|
164
|
-
attachments => [
|
165
|
-
{image_url => "http://example.com/image1.png"},
|
166
|
-
{image_url => "http://example.com/image2.png"}
|
167
|
-
]
|
168
|
-
}
|
169
|
-
}
|
170
|
-
CONFIG
|
171
|
-
|
172
|
-
test_one_event(logstash_config, expected_json)
|
144
|
+
context "empty default attachments" do
|
145
|
+
let(:data) { {
|
146
|
+
"message" => "This message should show in slack"
|
147
|
+
}}
|
148
|
+
|
149
|
+
let(:config) { {
|
150
|
+
"url" => "http://requestb.in/r9lkbzr9",
|
151
|
+
"attachments" => []
|
152
|
+
}}
|
153
|
+
|
154
|
+
it "are ignored" do
|
155
|
+
expected_json = {
|
156
|
+
:text => "This message should show in slack"
|
157
|
+
}
|
158
|
+
test_one_event(event, expected_json)
|
159
|
+
end
|
173
160
|
end
|
174
161
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
}
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
162
|
+
context "when both event attachments and default attachments are set" do
|
163
|
+
|
164
|
+
let(:data) { {
|
165
|
+
"message" => "This message should show in slack",
|
166
|
+
"attachments" => [{"thumb_url" => "http://other.com/thumb.png"}]
|
167
|
+
} }
|
168
|
+
|
169
|
+
let(:config) { {
|
170
|
+
"url" => "http://requestb.in/r9lkbzr9",
|
171
|
+
"attachments" => [
|
172
|
+
{"image_url" => "http://example.com/image1.png"},
|
173
|
+
{"image_url" => "http://example.com/image2.png"}
|
174
|
+
]
|
175
|
+
} }
|
176
|
+
|
177
|
+
it "event attachements prevail" do
|
178
|
+
expected_json = {
|
179
|
+
:text => "This message should show in slack",
|
180
|
+
:attachments => [{:thumb_url => "http://other.com/thumb.png"}]
|
181
|
+
}
|
182
|
+
test_one_event(event, expected_json)
|
183
|
+
end
|
196
184
|
end
|
197
185
|
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
}
|
221
|
-
output {
|
222
|
-
slack {
|
223
|
-
url => "http://requestb.in/r9lkbzr9"
|
224
|
-
attachments => [
|
225
|
-
{image_url => "http://example.com/image1.png"},
|
226
|
-
{image_url => "http://example.com/image2.png"}
|
227
|
-
]
|
228
|
-
}
|
229
|
-
}
|
230
|
-
CONFIG
|
186
|
+
context "if event attachments empty" do
|
187
|
+
|
188
|
+
let(:data) { {
|
189
|
+
"message" => "This message should show in slack",
|
190
|
+
"attachments" => []
|
191
|
+
} }
|
192
|
+
|
193
|
+
let(:config) { {
|
194
|
+
"url" => "http://requestb.in/r9lkbzr9",
|
195
|
+
"attachments" => [
|
196
|
+
{"image_url" => "http://example.com/image1.png"},
|
197
|
+
{"image_url" => "http://example.com/image2.png"}
|
198
|
+
]
|
199
|
+
} }
|
200
|
+
|
201
|
+
it "erases default attachments" do
|
202
|
+
expected_json = {
|
203
|
+
:text => "This message should show in slack"
|
204
|
+
}
|
205
|
+
test_one_event(event, expected_json)
|
206
|
+
end
|
207
|
+
end
|
231
208
|
|
232
|
-
|
209
|
+
context "when event attachements field isn't an array" do
|
210
|
+
let(:data) { {
|
211
|
+
"message" => "This message should show in slack",
|
212
|
+
"attachments" => "baddata"
|
213
|
+
} }
|
214
|
+
|
215
|
+
let(:config) { {
|
216
|
+
"url" => "http://requestb.in/r9lkbzr9",
|
217
|
+
"attachments" => [
|
218
|
+
{"image_url" => "http://example.com/image.png"}
|
219
|
+
]
|
220
|
+
} }
|
221
|
+
|
222
|
+
|
223
|
+
it "is ignored" do
|
224
|
+
expected_json = {
|
225
|
+
:text => "This message should show in slack",
|
226
|
+
:attachments => [{:image_url => "http://example.com/image.png"}]
|
227
|
+
}
|
228
|
+
test_one_event(event, expected_json)
|
229
|
+
end
|
233
230
|
end
|
231
|
+
end
|
234
232
|
|
235
|
-
|
236
|
-
|
237
|
-
:text => "This message should show in slack"
|
238
|
-
}
|
233
|
+
describe "interpolation in url field" do
|
234
|
+
let(:expected_url) { "http://incoming-webhook.example.com" }
|
239
235
|
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
count => 1
|
246
|
-
add_field => {attachments => '[]'}
|
247
|
-
}
|
248
|
-
}
|
249
|
-
filter {
|
250
|
-
json {
|
251
|
-
source => "attachments"
|
252
|
-
target => "attachments"
|
253
|
-
}
|
254
|
-
}
|
255
|
-
output {
|
256
|
-
slack {
|
257
|
-
url => "http://requestb.in/r9lkbzr9"
|
258
|
-
attachments => [
|
259
|
-
{image_url => "http://example.com/image1.png"},
|
260
|
-
{image_url => "http://example.com/image2.png"}
|
261
|
-
]
|
262
|
-
}
|
263
|
-
}
|
264
|
-
CONFIG
|
236
|
+
let(:event) {
|
237
|
+
event = LogStash::Event.new("message" => "This message should show in slack")
|
238
|
+
event.set("[@metadata][slack_url]", "#{expected_url}")
|
239
|
+
event
|
240
|
+
}
|
265
241
|
|
266
|
-
|
267
|
-
|
242
|
+
let(:config) { {
|
243
|
+
"url" => "%{[@metadata][slack_url]}",
|
244
|
+
"attachments" => [
|
245
|
+
{"image_url" => "http://example.com/image.png"}
|
246
|
+
]
|
247
|
+
} }
|
268
248
|
|
269
|
-
it "
|
249
|
+
it "allows interpolation in url field" do
|
270
250
|
expected_json = {
|
271
251
|
:text => "This message should show in slack",
|
272
252
|
:attachments => [{:image_url => "http://example.com/image.png"}]
|
273
253
|
}
|
274
|
-
|
275
|
-
logstash_config = <<-CONFIG
|
276
|
-
input {
|
277
|
-
generator {
|
278
|
-
message => "This message should show in slack"
|
279
|
-
count => 1
|
280
|
-
add_field => {attachments => "baddata"}
|
281
|
-
}
|
282
|
-
}
|
283
|
-
output {
|
284
|
-
slack {
|
285
|
-
url => "http://requestb.in/r9lkbzr9"
|
286
|
-
attachments => [
|
287
|
-
{image_url => "http://example.com/image.png"}
|
288
|
-
]
|
289
|
-
}
|
290
|
-
}
|
291
|
-
CONFIG
|
292
|
-
|
293
|
-
test_one_event(logstash_config, expected_json)
|
254
|
+
test_one_event(event, expected_json, expected_url)
|
294
255
|
end
|
295
256
|
end
|
296
257
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-output-slack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ying Li
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -140,7 +140,9 @@ dependencies:
|
|
140
140
|
- - ">="
|
141
141
|
- !ruby/object:Gem::Version
|
142
142
|
version: 1.21.0
|
143
|
-
description: This gem is a logstash plugin required to be installed on top of the
|
143
|
+
description: This gem is a logstash plugin required to be installed on top of the
|
144
|
+
Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not
|
145
|
+
a stand-alone program
|
144
146
|
email: cyli@ying.com
|
145
147
|
executables: []
|
146
148
|
extensions: []
|
@@ -178,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
178
180
|
version: '0'
|
179
181
|
requirements: []
|
180
182
|
rubyforge_project:
|
181
|
-
rubygems_version: 2.
|
183
|
+
rubygems_version: 2.6.13
|
182
184
|
signing_key:
|
183
185
|
specification_version: 4
|
184
186
|
summary: Write events to Slack
|