fluent-plugin-buffered-hipchat 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MWIwYzFlOWJlN2RhOTUzZmE2NTZkNzUxZDFlNjkyNzVkMTU3YzNjMA==
5
+ data.tar.gz: !binary |-
6
+ MWJjMGZiYzQ2NDdkNWQxZDM5MWIyMmY3MmExZjVhNDgyNmY3OGU3YQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MzI1ZDM3NmU0M2RhNmNmODMyZWU5OWRhNGE3ZjQ4OGY4OWQ2MmQ5N2NiNzQ0
10
+ ODE3ODY5OWNjZjcwOTljNzRiMmM4ZjczM2E0YWZmOWZlZmJkODIyODk1MDRj
11
+ NDEwNDNkZGEyOTczNWM5NTA4YTEyN2IyZWIyM2EyZTM3NzUxYmU=
12
+ data.tar.gz: !binary |-
13
+ ZWZhNTNiNjkzOTIzZDk1NDE5NTg4OGMwNGZiNzg1NmY3YmE3ZWMyNWVmMzBh
14
+ NGYyNmFmNGQzOTZlOWQ1OGE5ODZmYTQ1NWFiMzNlNjZhODI0YTA2Mjc5ZDU4
15
+ MzJmYjdlOTg2NTFlYmRlYjU1OWIxZDk0MjU3ODc1NGRjMTI5MGQ=
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ /fluent/
2
+ /pkg/
3
+ /coverage/
4
+ /vendor/
5
+ Gemfile.lock
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ rvm:
2
+ - 1.9.2
3
+ - 1.9.3
4
+
5
+ script: bundle exec rake test
data/AUTHORS ADDED
@@ -0,0 +1 @@
1
+ Keisuke SOGAWA <keisuke.sogawa _at_ gmail.com>
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+ gem "simplecov", :require => false
data/README.rdoc ADDED
@@ -0,0 +1,39 @@
1
+ = Fluent event to hipchat plugin.
2
+
3
+ = Installation
4
+
5
+ $ fluent-gem install fluent-plugin-buffered-hipchat
6
+
7
+ = Usage
8
+
9
+ <match hipchat>
10
+ type buffered_hipchat
11
+ api_token XXX
12
+ default_room my_room
13
+ default_from fluentd
14
+ default_color yellow
15
+ default_notify 0
16
+ default_format html
17
+
18
+ # proxy settings
19
+ # http_proxy_host localhost
20
+ # http_proxy_port 8080
21
+ # http_proxy_user username
22
+ # http_proxy_pass password
23
+ </match>
24
+
25
+ fluent_logger.post('hipchat', {
26
+ :from => 'alice',
27
+ :message => 'Hello<br>World!',
28
+ :color => 'red',
29
+ :room => 'my_room',
30
+ :notify => 1,
31
+ :format => 'text',
32
+ })
33
+
34
+ = Copyright
35
+
36
+ Copyright:: Copyright (c) 2014- Keisuke SOGAWA
37
+ License:: Apache License, Version 2.0
38
+
39
+ This plugin is forked from Yuichi Tateno's fluent-plugin-hipchat[https://github.com/hotchpotch/fluent-plugin-hipchat]
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |test|
7
+ test.libs << 'lib' << 'test'
8
+ test.test_files = FileList['test/plugin/*.rb']
9
+ test.verbose = true
10
+ end
11
+
12
+ task :coverage do |t|
13
+ ENV['SIMPLE_COV'] = '1'
14
+ Rake::Task["test"].invoke
15
+ end
16
+
17
+ task :default => [:build]
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "fluent-plugin-buffered-hipchat"
6
+ gem.description = "fluent buffered HipChat plugin"
7
+ gem.homepage = "https://github.com/sowawa/fluent-plugin-buffered-hipchat"
8
+ gem.summary = gem.description
9
+ gem.version = File.read("VERSION").strip
10
+ gem.authors = ["Keisuke SOGAWA"]
11
+ gem.email = "keisuke.sogawa@gmail.com"
12
+ gem.has_rdoc = false
13
+ gem.files = `git ls-files`.split("\n")
14
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ gem.require_paths = ['lib']
17
+
18
+ gem.add_dependency "fluentd", ">= 0.10.8"
19
+ gem.add_dependency "hipchat-api", ">= 1.0.0"
20
+
21
+ gem.add_development_dependency "rake", ">= 0.9.2"
22
+ gem.add_development_dependency "simplecov", ">= 0.5.4"
23
+ gem.add_development_dependency "rr", ">= 1.0.0"
24
+ gem.add_development_dependency "pry"
25
+ end
@@ -0,0 +1,68 @@
1
+ module Fluent
2
+ class BufferedHipchatOutput < Fluent::TimeSlicedOutput
3
+ Fluent::Plugin.register_output('buffered_hipchat', self)
4
+ config_param :api_token, :string
5
+ config_param :default_room, :string, :default => nil
6
+ config_param :default_color, :string, :default => nil
7
+ config_param :default_from, :string, :default => nil
8
+ config_param :default_notify, :bool, :default => nil
9
+ config_param :default_format, :string, :default => nil
10
+ config_param :http_proxy_host, :string, :default => nil
11
+ config_param :http_proxy_port, :integer, :default => nil
12
+ config_param :http_proxy_user, :string, :default => nil
13
+ config_param :http_proxy_pass, :string, :default => nil
14
+
15
+ attr_reader :hipchat
16
+
17
+ def format(tag, time, record)
18
+ [tag, time, record].to_json + "\n"
19
+ end
20
+
21
+ def write(chunk)
22
+ messages = {}
23
+ chunk.open {|io|
24
+ io.each {|line|
25
+ line_json = JSON.parse(line)
26
+ tag = line_json[0]
27
+ time = line_json[1]
28
+ record = line_json[2]
29
+ messages[tag] = '' unless messages[tag]
30
+ messages[tag] << "[#{Time.at(time)}] #{record['message']}\n"
31
+ }
32
+ }
33
+ # hoge = "ajshdfjalksfjlkasdjf\nlaksjfdl\naksfksadflka;"
34
+ # hoge.scan(/.{1,24}\Z|.{1,24}\n/m)
35
+ messages.each do |tag, message|
36
+ message.scan(/.{1,9500}/m).each {|chunked_message|
37
+ @hipchat.rooms_message(@default_room, @default_from, "#{tag} >>\n" + chunked_message, @default_notify, @default_color, @default_format)
38
+ }
39
+ end
40
+ rescue => e
41
+ $log.error("HipChat Error: #{e} / #{e.message}")
42
+ end
43
+
44
+ def initialize
45
+ super
46
+ require 'hipchat-api'
47
+ end
48
+
49
+ def configure(conf)
50
+ super
51
+
52
+ @hipchat = HipChat::API.new(conf['api_token'])
53
+ @default_room = conf['default_room']
54
+ @default_from = conf['default_from'] || 'fluentd'
55
+ @default_notify = conf['default_notify'] || 0
56
+ @default_color = conf['default_color'] || 'yellow'
57
+ @default_format = conf['default_format'] || 'html'
58
+ if conf['http_proxy_host']
59
+ HipChat::API.http_proxy(
60
+ conf['http_proxy_host'],
61
+ conf['http_proxy_port'],
62
+ conf['http_proxy_user'],
63
+ conf['http_proxy_pass'])
64
+ end
65
+ end
66
+
67
+ end
68
+ end
@@ -0,0 +1,68 @@
1
+ require 'test_helper'
2
+ require 'fluent/plugin/out_buffered_hipchat'
3
+ require 'time'
4
+
5
+ class BufferedHipchatOutputTest < Test::Unit::TestCase
6
+
7
+ def setup
8
+ super
9
+ Fluent::Test.setup
10
+ end
11
+
12
+ CONFIG = %[
13
+ type buffered_hipchat
14
+ api_token testtoken
15
+ default_room testroom
16
+ default_from testuser
17
+ default_color yellow
18
+ default_format text
19
+ buffer_type memory
20
+ compress gz
21
+ utc
22
+ ]
23
+
24
+ CONFIG_FOR_PROXY = %[
25
+ http_proxy_host localhost
26
+ http_proxy_port 8080
27
+ http_proxy_user user
28
+ http_proxy_pass password
29
+ ]
30
+
31
+ def create_driver(conf = CONFIG)
32
+ Fluent::Test::BufferedOutputTestDriver.new(Fluent::BufferedHipchatOutput).configure(conf)
33
+ end
34
+
35
+ def test_format
36
+ d = create_driver
37
+ time = Time.parse("2013-09-12 05:00:00 UTC").to_i
38
+ d.emit({message: 'sowawa'}, time)
39
+ d.expect_format %[#{['test', time, {message: 'sowawa'}].to_json}\n]
40
+ d.run
41
+ end
42
+
43
+ def test_write
44
+ d = create_driver
45
+ time = Time.parse("2013-09-12 05:00:00 UTC").to_i
46
+ d.tag = 'test'
47
+ stub(d.instance.hipchat).rooms_message(
48
+ 'testroom',
49
+ 'testuser',
50
+ "#{d.tag} >>\n" +
51
+ "[#{Time.at(time)}] sowawa1\n" +
52
+ "[#{Time.at(time)}] sowawa2\n",
53
+ 0,
54
+ 'yellow',
55
+ 'text')
56
+ d.emit({message: 'sowawa1'}, time)
57
+ d.emit({message: 'sowawa2'}, time)
58
+ d.run
59
+ end
60
+
61
+ def test_http_proxy
62
+ create_driver(CONFIG + CONFIG_FOR_PROXY)
63
+ assert_equal 'localhost', HipChat::API.default_options[:http_proxyaddr]
64
+ assert_equal '8080', HipChat::API.default_options[:http_proxyport]
65
+ assert_equal 'user', HipChat::API.default_options[:http_proxyuser]
66
+ assert_equal 'password', HipChat::API.default_options[:http_proxypass]
67
+ end
68
+ end
@@ -0,0 +1,20 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ require 'rr'
5
+ require 'test/unit'
6
+ class Test::Unit::TestCase
7
+ include RR::Adapters::TestUnit
8
+ end
9
+
10
+ if ENV['SIMPLE_COV']
11
+ require 'simplecov'
12
+ SimpleCov.start do
13
+ add_filter 'test/'
14
+ add_filter 'pkg/'
15
+ add_filter 'vendor/'
16
+ end
17
+ end
18
+
19
+ require 'test/unit'
20
+ require 'fluent/test'
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-buffered-hipchat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Keisuke SOGAWA
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fluentd
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.10.8
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.10.8
27
+ - !ruby/object:Gem::Dependency
28
+ name: hipchat-api
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.9.2
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.5.4
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.5.4
69
+ - !ruby/object:Gem::Dependency
70
+ name: rr
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: 1.0.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: 1.0.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: fluent buffered HipChat plugin
98
+ email: keisuke.sogawa@gmail.com
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - .gitignore
104
+ - .travis.yml
105
+ - AUTHORS
106
+ - Gemfile
107
+ - README.rdoc
108
+ - Rakefile
109
+ - VERSION
110
+ - fluent-plugin-buffered-hipchat.gemspec
111
+ - lib/fluent/plugin/out_buffered_hipchat.rb
112
+ - test/plugin/out_buffered_hipchat.rb
113
+ - test/test_helper.rb
114
+ homepage: https://github.com/sowawa/fluent-plugin-buffered-hipchat
115
+ licenses: []
116
+ metadata: {}
117
+ post_install_message:
118
+ rdoc_options: []
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ! '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ requirements: []
132
+ rubyforge_project:
133
+ rubygems_version: 2.2.0
134
+ signing_key:
135
+ specification_version: 4
136
+ summary: fluent buffered HipChat plugin
137
+ test_files:
138
+ - test/plugin/out_buffered_hipchat.rb
139
+ - test/test_helper.rb