fluent-plugin-slack 0.5.2 → 0.5.3

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: 1e923290cae0a22d361507caceed0cbd717effac
4
- data.tar.gz: e91f21aec9e58b4a32ae9795273f66eba888dcbc
3
+ metadata.gz: 60f17d6deefe9660f802349100a06f0dbb52be82
4
+ data.tar.gz: 6be0620df5d0e4e573f2ecb315e5e5134a511587
5
5
  SHA512:
6
- metadata.gz: de4ddc0641fa1c3d1249ea79869376866caceabf93901fb2b8c855d9de041e05009191c6c0fa63715136503fb5f8f0d55eb9ca389a0ceec85d2d22a12357f56b
7
- data.tar.gz: dcabceb85494457fc1644da528257bc34275e164e6d3a1e5ae0326a011f3927f897320577f5c91aa45f8add882449461b97430934b1b1fc0cf195a37df490393
6
+ metadata.gz: 754e0d821c9d4a62e885bc0c48298edfc5a3d60b3780e9c5b1321d1a5ca46eb19569bf39abd072dd6535b865dba6c5471cfa427f50a4a891e68a9c2c98c16161
7
+ data.tar.gz: ca145ab4794d3610ad727453b0013ffe2e18544a6a12a0189bb6cfeb0a11fe58f25e321bad7bcffab33957c1f7b9be306ec44b2b717ff902639d6aed46c41243
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.5.3 (2015/03/29)
2
+
3
+ Enhancements:
4
+
5
+ * Support `https_proxy` option
6
+
1
7
  ## 0.5.2 (2015/03/29)
2
8
 
3
9
  Enhancements:
data/README.md CHANGED
@@ -63,6 +63,7 @@ fluent_logger.post('slack', {
63
63
  |message|message format. %s will be replaced with value specified by message_keys|%s|
64
64
  |message_keys|keys used to format messages|message|
65
65
  |auto_channels_create|Create channels if not exist. Available only with Web API mode, and a token for Normal User is required (Bot User can not create channels. See https://api.slack.com/bot-users)|false|
66
+ |https_proxy|https proxy url such as `https://proxy.foo.bar:443`|nil|
66
67
 
67
68
  `fluent-plugin-slack` uses `SetTimeKeyMixin` and `SetTagKeyMixin`, so you can also use:
68
69
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.2
1
+ 0.5.3
@@ -18,6 +18,7 @@ module Fluent
18
18
  config_param :icon_emoji, :string, default: nil
19
19
  config_param :icon_url, :string, default: nil
20
20
  config_param :auto_channels_create, :bool, default: false
21
+ config_param :https_proxy, :string, default: nil
21
22
 
22
23
  config_param :channel, :string
23
24
  config_param :channel_keys, default: nil do |val|
@@ -72,6 +73,10 @@ module Fluent
72
73
  @slack.log = log
73
74
  @slack.debug_dev = log.out if log.level <= Fluent::Log::LEVEL_TRACE
74
75
 
76
+ if @https_proxy
77
+ @slack.https_proxy = @https_proxy
78
+ end
79
+
75
80
  begin
76
81
  @message % (['1'] * @message_keys.length)
77
82
  rescue ArgumentError
@@ -18,6 +18,7 @@ module Fluent
18
18
  config_param :icon_emoji, :string, default: nil
19
19
  config_param :icon_url, :string, default: nil
20
20
  config_param :auto_channels_create, :bool, default: false
21
+ config_param :https_proxy, :string, default: nil
21
22
 
22
23
  config_param :channel, :string
23
24
  config_param :channel_keys, default: nil do |val|
@@ -72,6 +73,10 @@ module Fluent
72
73
  @slack.log = log
73
74
  @slack.debug_dev = log.out if log.level <= Fluent::Log::LEVEL_TRACE
74
75
 
76
+ if @https_proxy
77
+ @slack.https_proxy = @https_proxy
78
+ end
79
+
75
80
  begin
76
81
  @message % (['1'] * @message_keys.length)
77
82
  rescue ArgumentError
@@ -1,5 +1,6 @@
1
1
  require 'uri'
2
2
  require 'net/http'
3
+ require 'net/https'
3
4
  require 'logger'
4
5
  require_relative 'slack_client/error'
5
6
 
@@ -8,13 +9,41 @@ module Fluent
8
9
  # The base framework of slack client
9
10
  class Base
10
11
  attr_accessor :log, :debug_dev
12
+ attr_reader :endpoint, :https_proxy
11
13
 
12
- def initialize
14
+ # @param [String] endpoint
15
+ #
16
+ # (Incoming Webhook) required
17
+ # https://hooks.slack.com/services/XXX/XXX/XXX
18
+ #
19
+ # (Web API) optional and default to be
20
+ # https://slack.com/api/
21
+ #
22
+ # @param [String] https_proxy (optional)
23
+ #
24
+ # https://proxy.foo.bar:port
25
+ #
26
+ def initialize(endpoint = nil, https_proxy = nil)
27
+ self.endpoint = endpoint if endpoint
28
+ self.https_proxy = https_proxy if https_proxy
13
29
  @log = Logger.new('/dev/null')
14
30
  end
15
31
 
32
+ def endpoint=(endpoint)
33
+ @endpoint = URI.parse(endpoint)
34
+ end
35
+
36
+ def https_proxy=(https_proxy)
37
+ @https_proxy = URI.parse(https_proxy)
38
+ @proxy_class = Net::HTTP.Proxy(@https_proxy.host, @https_proxy.port)
39
+ end
40
+
41
+ def proxy_class
42
+ @proxy_class ||= Net::HTTP
43
+ end
44
+
16
45
  def post(endpoint, params)
17
- http = Net::HTTP.new(endpoint.host, endpoint.port)
46
+ http = proxy_class.new(endpoint.host, endpoint.port)
18
47
  http.use_ssl = (endpoint.scheme == 'https')
19
48
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
20
49
  http.set_debug_output(debug_dev) if debug_dev
@@ -44,12 +73,9 @@ module Fluent
44
73
 
45
74
  # Slack client for Incoming Webhook
46
75
  class IncomingWebhook < Base
47
- attr_accessor :endpoint
48
-
49
- # @param [String] endpoint Configure Incoming Webhook endpoint
50
- def initialize(endpoint)
51
- super()
52
- @endpoint = URI.parse(endpoint)
76
+ def endpoint
77
+ return @endpoint if @endpoint
78
+ raise ArgumentError, "Incoming Webhook endpoint is not configured"
53
79
  end
54
80
 
55
81
  def post_message(params = {}, opts = {})
@@ -75,12 +101,16 @@ module Fluent
75
101
  class WebApi < Base
76
102
  DEFAULT_ENDPOINT = "https://slack.com/api/".freeze
77
103
 
104
+ def endpoint
105
+ @endpoint ||= URI.parse(DEFAULT_ENDPOINT)
106
+ end
107
+
78
108
  def post_message_endpoint
79
- @post_message_endpoint ||= URI.join(DEFAULT_ENDPOINT, "chat.postMessage")
109
+ @post_message_endpoint ||= URI.join(endpoint, "chat.postMessage")
80
110
  end
81
111
 
82
112
  def channels_create_endpoint
83
- @channels_create_endpoint ||= URI.join(DEFAULT_ENDPOINT, "channels.create")
113
+ @channels_create_endpoint ||= URI.join(endpoint, "channels.create")
84
114
  end
85
115
 
86
116
  # Sends a message to a channel.
@@ -160,6 +160,18 @@ class SlackOutputTest < Test::Unit::TestCase
160
160
  assert_equal @icon_url, d.instance.icon_url
161
161
  end
162
162
 
163
+ def test_https_proxy_configure
164
+ # default
165
+ d = create_driver(CONFIG)
166
+ assert_equal nil, d.instance.slack.https_proxy
167
+ assert_equal Net::HTTP, d.instance.slack.proxy_class
168
+
169
+ # https_proxy
170
+ d = create_driver(CONFIG + %[https_proxy https://proxy.foo.bar:443])
171
+ assert_equal URI.parse('https://proxy.foo.bar:443'), d.instance.slack.https_proxy
172
+ assert_not_equal Net::HTTP, d.instance.slack.proxy_class # Net::HTTP.Proxy
173
+ end
174
+
163
175
  def test_default_incoming_webhook
164
176
  d = create_driver(%[
165
177
  channel channel
@@ -2,6 +2,8 @@ require_relative '../test_helper'
2
2
  require 'fluent/plugin/slack_client'
3
3
  require 'time'
4
4
  require 'dotenv'
5
+ require 'webrick'
6
+ require 'webrick/httpproxy'
5
7
 
6
8
  # HOW TO RUN
7
9
  #
@@ -12,20 +14,60 @@ require 'dotenv'
12
14
  #
13
15
  Dotenv.load
14
16
  if ENV['WEBHOOK_URL'] and ENV['TOKEN']
17
+
18
+ class TestProxyServer
19
+ def initialize
20
+ @proxy = WEBrick::HTTPProxyServer.new(
21
+ :BindAddress => '127.0.0.1',
22
+ :Port => unused_port,
23
+ )
24
+ end
25
+
26
+ def proxy_url
27
+ "https://127.0.0.1:#{unused_port}"
28
+ end
29
+
30
+ def start
31
+ @thread = Thread.new do
32
+ @proxy.start
33
+ end
34
+ end
35
+
36
+ def shutdown
37
+ @proxy.shutdown
38
+ end
39
+
40
+ def unused_port
41
+ return @unused_port if @unused_port
42
+ s = TCPServer.open(0)
43
+ port = s.addr[1]
44
+ s.close
45
+ @unused_port = port
46
+ end
47
+ end
48
+
15
49
  class SlackClientTest < Test::Unit::TestCase
16
50
  def setup
17
51
  super
52
+ @proxy = TestProxyServer.new.tap {|proxy| proxy.start }
18
53
  @incoming_webhook = Fluent::SlackClient::IncomingWebhook.new(ENV['WEBHOOK_URL'])
19
54
  @api = Fluent::SlackClient::WebApi.new
55
+ @incoming_webhook_proxy = Fluent::SlackClient::IncomingWebhook.new(ENV['WEBHOOK_URL'], @proxy.proxy_url)
56
+ @api_proxy = Fluent::SlackClient::WebApi.new(nil, @proxy.proxy_url)
57
+
20
58
  @icon_url = 'http://www.google.com/s2/favicons?domain=www.google.de'
21
59
  end
22
60
 
61
+ def teardown
62
+ @proxy.shutdown
63
+ end
64
+
23
65
  def token(client)
24
- client == @api ? {token: ENV['TOKEN']} : {}
66
+ client.is_a?(Fluent::SlackClient::WebApi) ? {token: ENV['TOKEN']} : {}
25
67
  end
26
68
 
27
69
  def test_post_message_text
28
- [@incoming_webhook, @api].each do |slack|
70
+ [@incoming_webhook, @api, @incoming_webhook_proxy, @api_proxy].each do |slack|
29
71
  assert_nothing_raised do
30
72
  slack.post_message(
31
73
  {
@@ -43,8 +85,36 @@ if ENV['WEBHOOK_URL'] and ENV['TOKEN']
43
85
  end
44
86
  end
45
87
 
88
+ def test_post_message_fields
89
+ [@incoming_webhook, @api, @incoming_webhook_proxy, @api_proxy].each do |slack|
90
+ assert_nothing_raised do
91
+ slack.post_message(
92
+ {
93
+ channel: '#general',
94
+ username: 'fluentd',
95
+ icon_emoji: ':question:',
96
+ attachments: [{
97
+ color: 'good',
98
+ fallback: 'test1 test2',
99
+ fields: [
100
+ {
101
+ title: 'test1',
102
+ value: "[07:00:00] sowawa1\n[07:00:00] sowawa2\n",
103
+ },
104
+ {
105
+ title: 'test2',
106
+ value: "[07:00:00] sowawa1\n[07:00:00] sowawa2\n",
107
+ },
108
+ ],
109
+ }]
110
+ }.merge(token(slack))
111
+ )
112
+ end
113
+ end
114
+ end
115
+
46
116
  def test_post_message_icon_url
47
- [@incoming_webhook, @api].each do |slack|
117
+ [@incoming_webhook, @api, @incoming_webhook_proxy, @api_proxy].each do |slack|
48
118
  assert_nothing_raised do
49
119
  slack.post_message(
50
120
  {
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.2
4
+ version: 0.5.3
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-28 00:00:00.000000000 Z
12
+ date: 2015-03-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fluentd