fluent-plugin-hipchat 0.2.0 → 0.3.0

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: 956ca8f2c269a901d1afd66f55926fd421f2953d
4
- data.tar.gz: a7968c4b26d1d73374ef829508494b1760a112fa
3
+ metadata.gz: 8efeebb26e4e7309f3b935d63e28f9d5dae01ab5
4
+ data.tar.gz: 2bd001e4640837b1114cc1cebd7eefbc52d33b17
5
5
  SHA512:
6
- metadata.gz: 745a459a8b4b8518ac996e584315703850011cc2d0e2f05aee46de958769949e4f37526ea9c2bc223d2f9b86854b250579ff01e32b03dd44fdda3d078bddc1b4
7
- data.tar.gz: 0d997194930e335c75745bfc449e25107dc867a1914e0e2f39c9af7a2d651ec08f8843055cdd38aa343438d7538edff20e48b7a205fad541ff1ec3655ea9d36f
6
+ metadata.gz: a6491adb2c5d5dbe884568ca755513bdcce4d3ad421e7b0beccbcbd02409b257d3b33c7f34980202158607a8229934b89d2720b95098cee1f4dd51abbc9d04be
7
+ data.tar.gz: 6c9e77d859642e54d3b1f8baf4fbe960cd651b825e6fe8b8b4cd666667278e51188654966df28f161c424f1ebde3f122ff4d112e71a7757c8f020079d61757c6
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
15
15
  gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
16
  gem.require_paths = ['lib']
17
17
 
18
- gem.add_dependency "fluentd", ">= 0.10.8"
18
+ gem.add_dependency "fluentd", [">= 0.14.0", "< 2"]
19
19
  gem.add_dependency "hipchat-api", ">= 1.0.0"
20
20
 
21
21
  gem.add_development_dependency "rake", ">= 0.9.2"
@@ -1,10 +1,15 @@
1
+ require 'hipchat-api'
2
+ require 'fluent/plugin/output'
1
3
 
2
- module Fluent
3
- class HipchatOutput < BufferedOutput
4
+ module Fluent::Plugin
5
+ class HipchatOutput < Output
4
6
  COLORS = %w(yellow red green purple gray random)
5
7
  FORMAT = %w(html text)
8
+ DEFAULT_BUFFER_TYPE = "memory"
6
9
  Fluent::Plugin.register_output('hipchat', self)
7
10
 
11
+ helpers :compat_parameters
12
+
8
13
  config_param :api_token, :string, :secret => true
9
14
  config_param :default_room, :string, :default => nil
10
15
  config_param :default_color, :string, :default => 'yellow'
@@ -19,14 +24,19 @@ module Fluent
19
24
  config_param :http_proxy_pass, :string, :default => nil
20
25
  config_param :flush_interval, :time, :default => 1
21
26
 
27
+ config_section :buffer do
28
+ config_set_default :@type, DEFAULT_BUFFER_TYPE
29
+ config_set_default :chunk_keys, ['tag']
30
+ end
31
+
22
32
  attr_reader :hipchat
23
33
 
24
34
  def initialize
25
35
  super
26
- require 'hipchat-api'
27
36
  end
28
37
 
29
38
  def configure(conf)
39
+ compat_parameters_convert(conf, :buffer)
30
40
  super
31
41
 
32
42
  @hipchat = HipChat::API.new(conf['api_token'])
@@ -40,19 +50,28 @@ module Fluent
40
50
  conf['http_proxy_user'],
41
51
  conf['http_proxy_pass'])
42
52
  end
53
+ raise Fluent::ConfigError, "'tag' in chunk_keys is required." if not @chunk_key_tag
43
54
  end
44
55
 
45
56
  def format(tag, time, record)
46
- [tag, time, record].to_msgpack
57
+ [time, record].to_msgpack
58
+ end
59
+
60
+ def formatted_to_msgpack_binary
61
+ true
62
+ end
63
+
64
+ def multi_workers_ready?
65
+ true
47
66
  end
48
67
 
49
68
  def write(chunk)
50
- chunk.msgpack_each do |(tag,time,record)|
69
+ chunk.msgpack_each do |(time,record)|
51
70
  begin
52
71
  send_message(record) if record[@key_name]
53
72
  set_topic(record) if record['topic']
54
73
  rescue => e
55
- $log.error("HipChat Error:", :error_class => e.class, :error => e.message)
74
+ log.error("HipChat Error:", :error_class => e.class, :error => e.message)
56
75
  end
57
76
  end
58
77
  end
@@ -2,6 +2,8 @@ require 'test_helper'
2
2
  require 'fluent/plugin/out_hipchat'
3
3
 
4
4
  class HipchatOutputTest < Test::Unit::TestCase
5
+ include Fluent::Test::Helpers
6
+
5
7
  def setup
6
8
  super
7
9
  Fluent::Test.setup
@@ -23,7 +25,7 @@ class HipchatOutputTest < Test::Unit::TestCase
23
25
  ]
24
26
 
25
27
  def create_driver(conf = CONFIG)
26
- Fluent::Test::BufferedOutputTestDriver.new(Fluent::HipchatOutput) {
28
+ Fluent::Test::Driver::Output.new(Fluent::Plugin::HipchatOutput) {
27
29
  }.configure(conf)
28
30
  end
29
31
 
@@ -40,6 +42,17 @@ class HipchatOutputTest < Test::Unit::TestCase
40
42
  assert_equal 1, d.instance.flush_interval
41
43
  end
42
44
 
45
+ def test_format
46
+ d = create_driver
47
+ stub(d.instance.hipchat).rooms_message('testroom', 'testuser', 'foo', 0, 'red', 'html')
48
+ assert_equal d.instance.hipchat.instance_variable_get(:@token), 'testtoken'
49
+ time = event_time
50
+ d.run(default_tag: "test") do
51
+ d.feed(time, {'message' => 'foo', 'color' => 'red'})
52
+ end
53
+ assert_equal [time, {'message' => 'foo', 'color' => 'red'}].to_msgpack, d.formatted[0]
54
+ end
55
+
43
56
  def test_default_message
44
57
  d = create_driver(<<-EOF)
45
58
  type hipchat
@@ -48,8 +61,9 @@ class HipchatOutputTest < Test::Unit::TestCase
48
61
  EOF
49
62
  stub(d.instance.hipchat).rooms_message('testroom', 'fluentd', 'foo', 0, 'yellow', 'html')
50
63
  assert_equal d.instance.hipchat.instance_variable_get(:@token), 'xxx'
51
- d.emit({'message' => 'foo'})
52
- d.run
64
+ d.run(default_tag: "test") do
65
+ d.feed({'message' => 'foo'})
66
+ end
53
67
  end
54
68
 
55
69
  def test_set_default_timeout
@@ -59,39 +73,43 @@ class HipchatOutputTest < Test::Unit::TestCase
59
73
  default_timeout 5
60
74
  EOF
61
75
  stub(d.instance.hipchat).set_timeout(5)
62
- d.emit({'message' => 'foo'})
63
- d.run
76
+ d.run(default_tag: "test") do
77
+ d.feed({'message' => 'foo'})
78
+ end
64
79
  end
65
80
 
66
81
  def test_message
67
82
  d = create_driver
68
83
  stub(d.instance.hipchat).rooms_message('testroom', 'testuser', 'foo', 0, 'red', 'html')
69
84
  assert_equal d.instance.hipchat.instance_variable_get(:@token), 'testtoken'
70
- d.emit({'message' => 'foo', 'color' => 'red'})
71
- d.run
85
+ d.run(default_tag: "test") do
86
+ d.feed({'message' => 'foo', 'color' => 'red'})
87
+ end
72
88
  end
73
89
 
74
90
  def test_message_override
75
91
  d = create_driver
76
92
  stub(d.instance.hipchat).rooms_message('my', 'alice', 'aaa', 1, 'random', 'text')
77
- d.emit(
78
- {
79
- 'room' => 'my',
80
- 'from' => 'alice',
81
- 'message' => 'aaa',
82
- 'notify' => true,
83
- 'color' => 'random',
84
- 'format' => 'text',
85
- }
86
- )
87
- d.run
93
+ d.run(default_tag: "test") do
94
+ d.feed(
95
+ {
96
+ 'room' => 'my',
97
+ 'from' => 'alice',
98
+ 'message' => 'aaa',
99
+ 'notify' => true,
100
+ 'color' => 'random',
101
+ 'format' => 'text',
102
+ }
103
+ )
104
+ end
88
105
  end
89
106
 
90
107
  def test_topic
91
108
  d = create_driver
92
109
  stub(d.instance.hipchat).rooms_topic('testroom', 'foo', 'testuser')
93
- d.emit({'topic' => 'foo'})
94
- d.run
110
+ d.run(default_tag: "test") do
111
+ d.feed({'topic' => 'foo'})
112
+ end
95
113
  end
96
114
 
97
115
  def test_set_topic_response_error
@@ -100,8 +118,9 @@ class HipchatOutputTest < Test::Unit::TestCase
100
118
  {'error' => { 'code' => 400, 'type' => 'Bad Request', 'message' => 'Topic body must be between 1 and 250 characters.' } }
101
119
  }
102
120
  stub($log).error("HipChat Error:", :error_class => StandardError, :error => 'Topic body must be between 1 and 250 characters.')
103
- d.emit({'topic' => 'foo'})
104
- d.run
121
+ d.run(default_tag: "test") do
122
+ d.feed({'topic' => 'foo'})
123
+ end
105
124
  end
106
125
 
107
126
  def test_send_message_response_error
@@ -110,15 +129,17 @@ class HipchatOutputTest < Test::Unit::TestCase
110
129
  {'error' => { 'code' => 400, 'type' => 'Bad Request', 'message' => 'From name may not contain HTML.' } }
111
130
  }
112
131
  stub($log).error("HipChat Error:", :error_class => StandardError, :error => 'From name may not contain HTML.')
113
- d.emit({'from' => '<abc>', 'message' => 'foo'})
114
- d.run
132
+ d.run(default_tag: "test") do
133
+ d.feed({'from' => '<abc>', 'message' => 'foo'})
134
+ end
115
135
  end
116
136
 
117
137
  def test_color_validate
118
138
  d = create_driver
119
139
  stub(d.instance.hipchat).rooms_message('testroom', 'testuser', 'foo', 0, 'yellow', 'html')
120
- d.emit({'message' => 'foo', 'color' => 'invalid'})
121
- d.run
140
+ d.run(default_tag: "test") do
141
+ d.feed({'message' => 'foo', 'color' => 'invalid'})
142
+ end
122
143
  end
123
144
 
124
145
  def test_http_proxy
@@ -13,3 +13,5 @@ end
13
13
  require 'test/unit'
14
14
  require 'test/unit/rr'
15
15
  require 'fluent/test'
16
+ require 'fluent/test/driver/output'
17
+ require 'fluent/test/helpers'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-hipchat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuichi Tateno
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-04 00:00:00.000000000 Z
11
+ date: 2017-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -16,14 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.10.8
19
+ version: 0.14.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
27
  - - ">="
25
28
  - !ruby/object:Gem::Version
26
- version: 0.10.8
29
+ version: 0.14.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: hipchat-api
29
35
  requirement: !ruby/object:Gem::Requirement