fluent-plugin-slack 0.6.5 → 0.6.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: abca37bc729bcbae33c6550af3a6a271f979e70d
4
- data.tar.gz: d7124e7eed5b0c920bdf0125324683668ff938b2
3
+ metadata.gz: 184b33be08e986aed0759111ca47da646a170b4d
4
+ data.tar.gz: 72fb479769709a04b749d4cf6391f4d1fe86b3c9
5
5
  SHA512:
6
- metadata.gz: b7380082aca202039dee0eef3c69a4c6ee80752245be769c182de7e35dc994967b960c4555cd5658d4b93a53aa5f412d5a75e8f2a8288835a1e7f1f867fc8f49
7
- data.tar.gz: c73f180c32d084c5d7d91434b56a94b189ec19722327d7008a406abe5825eb507be84c2c3e149db86640cfce083e56a4001c07534418796b8e541c6e46105e01
6
+ metadata.gz: ab882482f1f5735a837444220f96ecbc5c68b4b9ff660007c3b4189ef0da812598e2dc8bab147c810a5ff6e2a3724709d95e49f6449ae6a00fb34382d985d7ec
7
+ data.tar.gz: 2b2f9de2865c86ee853a67a512b998d8e29e39081d95385472511f3303e42f8f7940d31c6d14b63945f8055e0d44b02757f711402def1358e96c3cb9d46c78a7
@@ -1,3 +1,9 @@
1
+ ## 0.6.6 (2017/05/23)
2
+
3
+ Enhancements:
4
+
5
+ * Make channel config optional on webhook because webhook has its defaul channel setting (thanks to @hirakiuc)
6
+
1
7
  ## 0.6.5 (2017/05/20)
2
8
 
3
9
  Enhancements:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.5
1
+ 0.6.6
@@ -1,9 +1,9 @@
1
1
  <source>
2
- type forward
2
+ @type forward
3
3
  </source>
4
4
 
5
5
  <match tag>
6
- type slack
6
+ @type slack
7
7
  token "#{ENV['TOKEN']}"
8
8
  username fluentd
9
9
  color good
@@ -86,7 +86,7 @@ DESC
86
86
  config_param :https_proxy, :string, default: nil
87
87
 
88
88
  desc "channel to send messages (without first '#')."
89
- config_param :channel, :string
89
+ config_param :channel, :string, default: nil
90
90
  desc <<-DESC
91
91
  Keys used to format channel.
92
92
  %s will be replaced with value specified by channel_keys if this option is used.
@@ -130,11 +130,13 @@ DESC
130
130
  def configure(conf)
131
131
  conf['time_format'] ||= '%H:%M:%S' # old version compatiblity
132
132
  conf['localtime'] ||= true unless conf['utc']
133
-
133
+
134
134
  super
135
135
 
136
- @channel = URI.unescape(@channel) # old version compatibility
137
- @channel = '#' + @channel unless @channel.start_with?('#')
136
+ if @channel
137
+ @channel = URI.unescape(@channel) # old version compatibility
138
+ @channel = '#' + @channel unless @channel.start_with?('#')
139
+ end
138
140
 
139
141
  if @webhook_url
140
142
  if @webhook_url.empty?
@@ -148,6 +150,10 @@ DESC
148
150
  if @slackbot_url.empty?
149
151
  raise Fluent::ConfigError.new("`slackbot_url` is an empty string")
150
152
  end
153
+ if @channel.nil?
154
+ raise Fluent::ConfigError.new("`channel` parameter required for Slackbot Remote Control")
155
+ end
156
+
151
157
  if @username or @color or @icon_emoji or @icon_url
152
158
  log.warn "out_slack: `username`, `color`, `icon_emoji`, `icon_url` parameters are not available for Slackbot Remote Control"
153
159
  end
@@ -159,6 +165,10 @@ DESC
159
165
  if @token.empty?
160
166
  raise Fluent::ConfigError.new("`token` is an empty string")
161
167
  end
168
+ if @channel.nil?
169
+ raise Fluent::ConfigError.new("`channel` parameter required for Slack WebApi")
170
+ end
171
+
162
172
  @slack = Fluent::SlackClient::WebApi.new
163
173
  else
164
174
  raise Fluent::ConfigError.new("One of `webhook_url` or `slackbot_url`, or `token` is required")
@@ -184,7 +194,7 @@ DESC
184
194
  raise Fluent::ConfigError, "string specifier '%s' for `title` and `title_keys` specification mismatch"
185
195
  end
186
196
  end
187
- if @channel_keys
197
+ if @channel && @channel_keys
188
198
  begin
189
199
  @channel % (['1'] * @channel_keys.length)
190
200
  rescue ArgumentError
@@ -288,13 +298,14 @@ DESC
288
298
  fields.values.map(&:title).join(' ')
289
299
  end
290
300
 
291
- {
292
- channel: channel,
301
+ msg = {
293
302
  attachments: [{
294
303
  :fallback => fallback_text, # fallback is the message shown on popup
295
304
  :fields => fields.values.map(&:to_h)
296
305
  }.merge(common_attachment)],
297
- }.merge(common_payload)
306
+ }
307
+ msg.merge!(channel: channel) if channel
308
+ msg.merge!(common_payload)
298
309
  end
299
310
  end
300
311
 
@@ -306,13 +317,14 @@ DESC
306
317
  messages[channel] << "#{build_message(record)}\n"
307
318
  end
308
319
  messages.map do |channel, text|
309
- {
310
- channel: channel,
320
+ msg = {
311
321
  attachments: [{
312
322
  :fallback => text,
313
323
  :text => text,
314
324
  }.merge(common_attachment)],
315
- }.merge(common_payload)
325
+ }
326
+ msg.merge!(channel: channel) if channel
327
+ msg.merge!(common_payload)
316
328
  end
317
329
  end
318
330
 
@@ -324,10 +336,9 @@ DESC
324
336
  messages[channel] << "#{build_message(record)}\n"
325
337
  end
326
338
  messages.map do |channel, text|
327
- {
328
- channel: channel,
329
- text: text,
330
- }.merge(common_payload)
339
+ msg = {text: text}
340
+ msg.merge!(channel: channel) if channel
341
+ msg.merge!(common_payload)
331
342
  end
332
343
  end
333
344
 
@@ -344,6 +355,7 @@ DESC
344
355
  end
345
356
 
346
357
  def build_channel(record)
358
+ return nil if @channel.nil?
347
359
  return @channel unless @channel_keys
348
360
 
349
361
  values = fetch_keys(record, @channel_keys)
@@ -114,15 +114,30 @@ class SlackOutputTest < Test::Unit::TestCase
114
114
  create_driver(%[channel foo\nwebhook_url])
115
115
  end
116
116
 
117
- # webhook_url is an empty string
117
+ # webhook without channel (it works because webhook has a default channel)
118
+ assert_nothing_raised do
119
+ create_driver(%[webhook_url https://example.com/path/to/webhook])
120
+ end
121
+
122
+ # slackbot_url is an empty string
118
123
  assert_raise(Fluent::ConfigError) do
119
124
  create_driver(%[channel foo\nslackbot_url])
120
125
  end
121
126
 
127
+ # slackbot without channel
128
+ assert_raise(Fluent::ConfigError) do
129
+ create_driver(%[slackbot_url https://example.com/path/to/slackbot])
130
+ end
131
+
122
132
  # token is an empty string
123
133
  assert_raise(Fluent::ConfigError) do
124
134
  create_driver(%[channel foo\ntoken])
125
135
  end
136
+
137
+ # slack webapi token without channel
138
+ assert_raise(Fluent::ConfigError) do
139
+ create_driver(%[token some_token])
140
+ end
126
141
  end
127
142
 
128
143
  def test_timezone_configure
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-slack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.5
4
+ version: 0.6.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keisuke SOGAWA
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-05-20 00:00:00.000000000 Z
12
+ date: 2017-05-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fluentd