fluent-plugin-slack 0.5.1 → 0.5.2

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: 63fd1c619f76e7bb3df9b2ff11e69af43e23f810
4
- data.tar.gz: 8fd2eb0e8790c71c8689ae88e42f8a4bae3f1d3b
3
+ metadata.gz: 1e923290cae0a22d361507caceed0cbd717effac
4
+ data.tar.gz: e91f21aec9e58b4a32ae9795273f66eba888dcbc
5
5
  SHA512:
6
- metadata.gz: bf331ec94a09e572f2aa1c958842634195dad9078cc7fbf86813c121d88ddeb69568617663cf2012151646c52c6ec64203f95b3738348937bc0b8a417c6da976
7
- data.tar.gz: c16e8a479300bc03539232a4d76d172d7eaa8c0d0e640612424fa483f2b7abd4510de6a3fee5b55d0eb2b70a395cc1a65d2425e3eb62c0e7a1058d9be3418d66
6
+ metadata.gz: de4ddc0641fa1c3d1249ea79869376866caceabf93901fb2b8c855d9de041e05009191c6c0fa63715136503fb5f8f0d55eb9ca389a0ceec85d2d22a12357f56b
7
+ data.tar.gz: dcabceb85494457fc1644da528257bc34275e164e6d3a1e5ae0326a011f3927f897320577f5c91aa45f8add882449461b97430934b1b1fc0cf195a37df490393
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.5.2 (2015/03/29)
2
+
3
+ Enhancements:
4
+
5
+ * Support `icon_url` option (thanks to @jwyjoy)
6
+
1
7
  ## 0.5.1 (2015/03/27)
2
8
 
3
9
  Enhancements:
data/README.md CHANGED
@@ -54,7 +54,8 @@ fluent_logger.post('slack', {
54
54
  |token|Token for Web API (Required for Web API mode)||
55
55
  |username|name of bot|fluentd|
56
56
  |color|color to use|good|
57
- |icon_emoji|emoji to use as the icon|`:question:`|
57
+ |icon_emoji|emoji to use as the icon. either of icon_emoji or icon_url can be specified|`:question:`|
58
+ |icon_url|url to an image to use as the icon. either of icon_emoji or icon_url can be specified|nil|
58
59
  |channel|channel to send messages (without first '#')||
59
60
  |channel_keys|keys used to format channel. %s will be replaced with value specified by channel_keys if this option is used|nil|
60
61
  |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.1
1
+ 0.5.2
data/example.conf CHANGED
@@ -7,7 +7,8 @@
7
7
  token "#{ENV['TOKEN']}"
8
8
  username fluentd
9
9
  color good
10
- icon_emoji :ghost:
10
+ icon_emoji :ghost: # if you want to use icon_url, delete this param.
11
+ #icon_url http://www.google.com/s2/favicons?domain=www.google.de
11
12
  channel general
12
13
  message %s %s
13
14
  message_keys tag,message
@@ -15,7 +15,8 @@ module Fluent
15
15
  config_param :token, :string, default: nil # api token
16
16
  config_param :username, :string, default: 'fluentd'
17
17
  config_param :color, :string, default: 'good'
18
- config_param :icon_emoji, :string, default: ':question:'
18
+ config_param :icon_emoji, :string, default: nil
19
+ config_param :icon_url, :string, default: nil
19
20
  config_param :auto_channels_create, :bool, default: false
20
21
 
21
22
  config_param :channel, :string
@@ -91,6 +92,11 @@ module Fluent
91
92
  end
92
93
  end
93
94
 
95
+ if @icon_emoji and @icon_url
96
+ raise Fluent::ConfigError, "either of `icon_emoji` or `icon_url` can be specified"
97
+ end
98
+ @icon_emoji ||= ':question:' unless @icon_url
99
+
94
100
  @post_message_opts = @auto_channels_create ? {auto_channels_create: true} : {}
95
101
  end
96
102
 
@@ -124,11 +130,11 @@ module Fluent
124
130
 
125
131
  def common_payload
126
132
  return @common_payload if @common_payload
127
- @common_payload = {
128
- username: @username,
129
- icon_emoji: @icon_emoji,
130
- }
131
- @common_payload[:token] = @token if @token
133
+ @common_payload = {}
134
+ @common_payload[:username] = @username
135
+ @common_payload[:icon_emoji] = @icon_emoji if @icon_emoji
136
+ @common_payload[:icon_url] = @icon_url if @icon_url
137
+ @common_payload[:token] = @token if @token
132
138
  @common_payload
133
139
  end
134
140
 
@@ -15,7 +15,8 @@ module Fluent
15
15
  config_param :token, :string, default: nil # api token
16
16
  config_param :username, :string, default: 'fluentd'
17
17
  config_param :color, :string, default: 'good'
18
- config_param :icon_emoji, :string, default: ':question:'
18
+ config_param :icon_emoji, :string, default: nil
19
+ config_param :icon_url, :string, default: nil
19
20
  config_param :auto_channels_create, :bool, default: false
20
21
 
21
22
  config_param :channel, :string
@@ -91,6 +92,11 @@ module Fluent
91
92
  end
92
93
  end
93
94
 
95
+ if @icon_emoji and @icon_url
96
+ raise Fluent::ConfigError, "either of `icon_emoji` or `icon_url` can be specified"
97
+ end
98
+ @icon_emoji ||= ':question:' unless @icon_url
99
+
94
100
  @post_message_opts = @auto_channels_create ? {auto_channels_create: true} : {}
95
101
  end
96
102
 
@@ -124,11 +130,11 @@ module Fluent
124
130
 
125
131
  def common_payload
126
132
  return @common_payload if @common_payload
127
- @common_payload = {
128
- username: @username,
129
- icon_emoji: @icon_emoji,
130
- }
131
- @common_payload[:token] = @token if @token
133
+ @common_payload = {}
134
+ @common_payload[:username] = @username
135
+ @common_payload[:icon_emoji] = @icon_emoji if @icon_emoji
136
+ @common_payload[:icon_url] = @icon_url if @icon_url
137
+ @common_payload[:token] = @token if @token
132
138
  @common_payload
133
139
  end
134
140
 
@@ -7,6 +7,7 @@ class SlackOutputTest < Test::Unit::TestCase
7
7
  def setup
8
8
  super
9
9
  Fluent::Test.setup
10
+ @icon_url = 'http://www.google.com/s2/favicons?domain=www.google.de'
10
11
  end
11
12
 
12
13
  CONFIG = %[
@@ -137,6 +138,28 @@ class SlackOutputTest < Test::Unit::TestCase
137
138
  end
138
139
  end
139
140
 
141
+ def test_icon_configure
142
+ # default
143
+ d = create_driver(CONFIG)
144
+ assert_equal ':question:', d.instance.icon_emoji
145
+ assert_equal nil, d.instance.icon_url
146
+
147
+ # either of icon_emoji or icon_url can be specified
148
+ assert_raise(Fluent::ConfigError) do
149
+ d = create_driver(CONFIG + %[icon_emoji :ghost:\nicon_url #{@icon_url}])
150
+ end
151
+
152
+ # icon_emoji
153
+ d = create_driver(CONFIG + %[icon_emoji :ghost:])
154
+ assert_equal ':ghost:', d.instance.icon_emoji
155
+ assert_equal nil, d.instance.icon_url
156
+
157
+ # icon_url
158
+ d = create_driver(CONFIG + %[icon_url #{@icon_url}])
159
+ assert_equal nil, d.instance.icon_emoji
160
+ assert_equal @icon_url, d.instance.icon_url
161
+ end
162
+
140
163
  def test_default_incoming_webhook
141
164
  d = create_driver(%[
142
165
  channel channel
@@ -271,4 +294,46 @@ class SlackOutputTest < Test::Unit::TestCase
271
294
  d.run
272
295
  end
273
296
  end
297
+
298
+ def test_icon_emoji
299
+ d = create_driver(CONFIG + %[icon_emoji :ghost:])
300
+ time = Time.parse("2014-01-01 22:00:00 UTC").to_i
301
+ d.tag = 'test'
302
+ mock(d.instance.slack).post_message({
303
+ token: 'XXX-XXX-XXX',
304
+ channel: '#channel',
305
+ username: 'fluentd',
306
+ icon_emoji: ':ghost:',
307
+ attachments: [{
308
+ color: 'good',
309
+ fallback: "foo\n",
310
+ text: "foo\n",
311
+ }]
312
+ }, {})
313
+ with_timezone('Asia/Tokyo') do
314
+ d.emit({message: 'foo'}, time)
315
+ d.run
316
+ end
317
+ end
318
+
319
+ def test_icon_url
320
+ d = create_driver(CONFIG + %[icon_url #{@icon_url}])
321
+ time = Time.parse("2014-01-01 22:00:00 UTC").to_i
322
+ d.tag = 'test'
323
+ mock(d.instance.slack).post_message({
324
+ token: 'XXX-XXX-XXX',
325
+ channel: '#channel',
326
+ username: 'fluentd',
327
+ icon_url: @icon_url,
328
+ attachments: [{
329
+ color: 'good',
330
+ fallback: "foo\n",
331
+ text: "foo\n",
332
+ }]
333
+ }, {})
334
+ with_timezone('Asia/Tokyo') do
335
+ d.emit({message: 'foo'}, time)
336
+ d.run
337
+ end
338
+ end
274
339
  end
@@ -17,6 +17,7 @@ if ENV['WEBHOOK_URL'] and ENV['TOKEN']
17
17
  super
18
18
  @incoming_webhook = Fluent::SlackClient::IncomingWebhook.new(ENV['WEBHOOK_URL'])
19
19
  @api = Fluent::SlackClient::WebApi.new
20
+ @icon_url = 'http://www.google.com/s2/favicons?domain=www.google.de'
20
21
  end
21
22
 
22
23
  def token(client)
@@ -42,27 +43,18 @@ if ENV['WEBHOOK_URL'] and ENV['TOKEN']
42
43
  end
43
44
  end
44
45
 
45
- def test_post_message_fields
46
+ def test_post_message_icon_url
46
47
  [@incoming_webhook, @api].each do |slack|
47
48
  assert_nothing_raised do
48
49
  slack.post_message(
49
50
  {
50
51
  channel: '#general',
51
52
  username: 'fluentd',
52
- icon_emoji: ':question:',
53
+ icon_url: @icon_url,
53
54
  attachments: [{
54
55
  color: 'good',
55
- fallback: 'test1 test2',
56
- fields: [
57
- {
58
- title: 'test1',
59
- value: "[07:00:00] sowawa1\n[07:00:00] sowawa2\n",
60
- },
61
- {
62
- title: 'test2',
63
- value: "[07:00:00] sowawa1\n[07:00:00] sowawa2\n",
64
- },
65
- ],
56
+ fallback: "sowawa1\nsowawa2\n",
57
+ text: "sowawa1\nsowawa2\n",
66
58
  }]
67
59
  }.merge(token(slack))
68
60
  )
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.1
4
+ version: 0.5.2
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-27 00:00:00.000000000 Z
12
+ date: 2015-03-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fluentd