fluent-plugin-slack 0.5.3 → 0.5.4

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: 60f17d6deefe9660f802349100a06f0dbb52be82
4
- data.tar.gz: 6be0620df5d0e4e573f2ecb315e5e5134a511587
3
+ metadata.gz: ad20f86b455e8ca489fe6ed2be1aea310505174d
4
+ data.tar.gz: 6a8410c533109fd41cc92c8ee3008841536264f9
5
5
  SHA512:
6
- metadata.gz: 754e0d821c9d4a62e885bc0c48298edfc5a3d60b3780e9c5b1321d1a5ca46eb19569bf39abd072dd6535b865dba6c5471cfa427f50a4a891e68a9c2c98c16161
7
- data.tar.gz: ca145ab4794d3610ad727453b0013ffe2e18544a6a12a0189bb6cfeb0a11fe58f25e321bad7bcffab33957c1f7b9be306ec44b2b717ff902639d6aed46c41243
6
+ metadata.gz: 132d099d24bfe70cb2aa297f2a63ec987981b120e27328d51137896ec2f3b685d7074cefefdcd3ac042fa44ca72ff9a01ba90b6899d0d3f81c3b49a30023d243
7
+ data.tar.gz: d8a789673b0f0c8e68c39abe231a313366c8f1f8e2cd8d24eb26c8022160b72041c83c0b584ba9f2b361f52a56444bd0e43e7cad8ade9fdd760671756607b84c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.5.4 (2015/03/31)
2
+
3
+ Enhancements:
4
+
5
+ * Support `mrkdwn` option
6
+
1
7
  ## 0.5.3 (2015/03/29)
2
8
 
3
9
  Enhancements:
data/README.md CHANGED
@@ -56,6 +56,7 @@ fluent_logger.post('slack', {
56
56
  |color|color to use|good|
57
57
  |icon_emoji|emoji to use as the icon. either of icon_emoji or icon_url can be specified|`:question:`|
58
58
  |icon_url|url to an image to use as the icon. either of icon_emoji or icon_url can be specified|nil|
59
+ |mrkdwn|enable formatting. see https://api.slack.com/docs/formatting|false|
59
60
  |channel|channel to send messages (without first '#')||
60
61
  |channel_keys|keys used to format channel. %s will be replaced with value specified by channel_keys if this option is used|nil|
61
62
  |title|title format. %s will be replaced with value specified by title_keys. title is created from the first appeared record on each tag|nil|
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.3
1
+ 0.5.4
@@ -17,6 +17,7 @@ module Fluent
17
17
  config_param :color, :string, default: 'good'
18
18
  config_param :icon_emoji, :string, default: nil
19
19
  config_param :icon_url, :string, default: nil
20
+ config_param :mrkdwn, :bool, default: false
20
21
  config_param :auto_channels_create, :bool, default: false
21
22
  config_param :https_proxy, :string, default: nil
22
23
 
@@ -34,7 +35,7 @@ module Fluent
34
35
  end
35
36
 
36
37
  # for test
37
- attr_reader :slack, :time_format, :localtime, :timef
38
+ attr_reader :slack, :time_format, :localtime, :timef, :mrkdwn_in
38
39
 
39
40
  def initialize
40
41
  super
@@ -102,6 +103,11 @@ module Fluent
102
103
  end
103
104
  @icon_emoji ||= ':question:' unless @icon_url
104
105
 
106
+ if @mrkdwn
107
+ # Enable markdown for attachments. See https://api.slack.com/docs/formatting
108
+ @mrkdwn_in = %w[text fields]
109
+ end
110
+
105
111
  @post_message_opts = @auto_channels_create ? {auto_channels_create: true} : {}
106
112
  end
107
113
 
@@ -143,6 +149,13 @@ module Fluent
143
149
  @common_payload
144
150
  end
145
151
 
152
+ def common_attachment
153
+ return @common_attachment if @common_attachment
154
+ @common_attachment = {}
155
+ @common_attachment[:mrkdwn_in] = @mrkdwn_in if @mrkdwn_in
156
+ @common_attachment
157
+ end
158
+
146
159
  Field = Struct.new("Field", :title, :value)
147
160
 
148
161
  def build_title_payloads(chunk)
@@ -161,7 +174,7 @@ module Fluent
161
174
  :color => @color,
162
175
  :fallback => fields.values.map(&:title).join(' '), # fallback is the message shown on popup
163
176
  :fields => fields.values.map(&:to_h)
164
- }],
177
+ }.merge(common_attachment)],
165
178
  }.merge(common_payload)
166
179
  end
167
180
  end
@@ -180,7 +193,7 @@ module Fluent
180
193
  :color => @color,
181
194
  :fallback => text,
182
195
  :text => text,
183
- }],
196
+ }.merge(common_attachment)],
184
197
  }.merge(common_payload)
185
198
  end
186
199
  end
@@ -17,6 +17,7 @@ module Fluent
17
17
  config_param :color, :string, default: 'good'
18
18
  config_param :icon_emoji, :string, default: nil
19
19
  config_param :icon_url, :string, default: nil
20
+ config_param :mrkdwn, :bool, default: false
20
21
  config_param :auto_channels_create, :bool, default: false
21
22
  config_param :https_proxy, :string, default: nil
22
23
 
@@ -34,7 +35,7 @@ module Fluent
34
35
  end
35
36
 
36
37
  # for test
37
- attr_reader :slack, :time_format, :localtime, :timef
38
+ attr_reader :slack, :time_format, :localtime, :timef, :mrkdwn_in
38
39
 
39
40
  def initialize
40
41
  super
@@ -102,6 +103,11 @@ module Fluent
102
103
  end
103
104
  @icon_emoji ||= ':question:' unless @icon_url
104
105
 
106
+ if @mrkdwn
107
+ # Enable markdown for attachments. See https://api.slack.com/docs/formatting
108
+ @mrkdwn_in = %w[text fields]
109
+ end
110
+
105
111
  @post_message_opts = @auto_channels_create ? {auto_channels_create: true} : {}
106
112
  end
107
113
 
@@ -143,6 +149,13 @@ module Fluent
143
149
  @common_payload
144
150
  end
145
151
 
152
+ def common_attachment
153
+ return @common_attachment if @common_attachment
154
+ @common_attachment = {}
155
+ @common_attachment[:mrkdwn_in] = @mrkdwn_in if @mrkdwn_in
156
+ @common_attachment
157
+ end
158
+
146
159
  Field = Struct.new("Field", :title, :value)
147
160
 
148
161
  def build_title_payloads(chunk)
@@ -161,7 +174,7 @@ module Fluent
161
174
  :color => @color,
162
175
  :fallback => fields.values.map(&:title).join(' '), # fallback is the message shown on popup
163
176
  :fields => fields.values.map(&:to_h)
164
- }],
177
+ }.merge(common_attachment)],
165
178
  }.merge(common_payload)
166
179
  end
167
180
  end
@@ -180,7 +193,7 @@ module Fluent
180
193
  :color => @color,
181
194
  :fallback => text,
182
195
  :text => text,
183
- }],
196
+ }.merge(common_attachment)],
184
197
  }.merge(common_payload)
185
198
  end
186
199
  end
@@ -172,6 +172,18 @@ class SlackOutputTest < Test::Unit::TestCase
172
172
  assert_not_equal Net::HTTP, d.instance.slack.proxy_class # Net::HTTP.Proxy
173
173
  end
174
174
 
175
+ def test_mrkwn_configure
176
+ # default
177
+ d = create_driver(CONFIG)
178
+ assert_equal false, d.instance.mrkdwn
179
+ assert_equal nil, d.instance.mrkdwn_in
180
+
181
+ # mrkdwn
182
+ d = create_driver(CONFIG + %[mrkdwn true])
183
+ assert_equal true, d.instance.mrkdwn
184
+ assert_equal %w[text fields], d.instance.mrkdwn_in
185
+ end
186
+
175
187
  def test_default_incoming_webhook
176
188
  d = create_driver(%[
177
189
  channel channel
@@ -242,7 +254,7 @@ class SlackOutputTest < Test::Unit::TestCase
242
254
  title: d.tag,
243
255
  value: "sowawa1\nsowawa2\n",
244
256
  }
245
- ]
257
+ ],
246
258
  }]
247
259
  }, {})
248
260
  with_timezone('Asia/Tokyo') do
@@ -348,4 +360,26 @@ class SlackOutputTest < Test::Unit::TestCase
348
360
  d.run
349
361
  end
350
362
  end
363
+
364
+ def test_mrkdwn
365
+ d = create_driver(CONFIG + %[mrkdwn true])
366
+ time = Time.parse("2014-01-01 22:00:00 UTC").to_i
367
+ d.tag = 'test'
368
+ mock(d.instance.slack).post_message({
369
+ token: 'XXX-XXX-XXX',
370
+ channel: '#channel',
371
+ username: 'fluentd',
372
+ icon_emoji: ':question:',
373
+ attachments: [{
374
+ color: 'good',
375
+ fallback: "foo\n",
376
+ text: "foo\n",
377
+ mrkdwn_in: ["text", "fields"],
378
+ }]
379
+ }, {})
380
+ with_timezone('Asia/Tokyo') do
381
+ d.emit({message: 'foo'}, time)
382
+ d.run
383
+ end
384
+ end
351
385
  end
@@ -114,7 +114,7 @@ if ENV['WEBHOOK_URL'] and ENV['TOKEN']
114
114
  end
115
115
 
116
116
  def test_post_message_icon_url
117
- [@incoming_webhook, @api, @incoming_webhook_proxy, @api_proxy].each do |slack|
117
+ [@incoming_webhook, @api].each do |slack|
118
118
  assert_nothing_raised do
119
119
  slack.post_message(
120
120
  {
@@ -132,6 +132,49 @@ if ENV['WEBHOOK_URL'] and ENV['TOKEN']
132
132
  end
133
133
  end
134
134
 
135
+ def test_post_message_text_mrkdwn
136
+ [@incoming_webhook, @api].each do |slack|
137
+ assert_nothing_raised do
138
+ slack.post_message(
139
+ {
140
+ channel: '#general',
141
+ username: 'fluentd',
142
+ attachments: [{
143
+ color: 'good',
144
+ fallback: "plain *bold* _italic_ `preformat`\n", # mrkdwn not work
145
+ text: "plain *bold* _italic_ `preformat`\n",
146
+ mrkdwn_in: ['text', 'fields'],
147
+ }]
148
+ }.merge(token(slack))
149
+ )
150
+ end
151
+ end
152
+ end
153
+
154
+ def test_post_message_fields_mrkdwn
155
+ [@incoming_webhook, @api].each do |slack|
156
+ assert_nothing_raised do
157
+ slack.post_message(
158
+ {
159
+ channel: '#general',
160
+ username: 'fluentd',
161
+ attachments: [{
162
+ color: 'good',
163
+ fallback: "plain *bold* _italic_ `preformat`\n", # mrkdwn not work
164
+ fields: [
165
+ {
166
+ title: 'plain *bold* _italic* `preformat`', # mrkdwn not work
167
+ value: "plain *bold* _italic* `preformat`\n",
168
+ },
169
+ ],
170
+ mrkdwn_in: ['text', 'fields'],
171
+ }]
172
+ }.merge(token(slack))
173
+ )
174
+ end
175
+ end
176
+ end
177
+
135
178
  # Hmm, I need to delete channels to test repeatedly,
136
179
  # but slack does not provide channels.delete API
137
180
  def test_channels_create
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.5.3
4
+ version: 0.5.4
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: 2015-03-29 00:00:00.000000000 Z
12
+ date: 2015-03-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fluentd
@@ -167,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
167
  version: '0'
168
168
  requirements: []
169
169
  rubyforge_project:
170
- rubygems_version: 2.2.2
170
+ rubygems_version: 2.4.5
171
171
  signing_key:
172
172
  specification_version: 4
173
173
  summary: fluent Slack plugin