fluent-plugin-hipchat 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
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
+ Yuichi Tateno <hotchpotch _at_ gmail.com>
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :rubygems
2
+
3
+ gemspec
4
+ gem "simplecov", :require => false
data/README.rdoc ADDED
@@ -0,0 +1,28 @@
1
+ = Fluent event to hipchat plugin.
2
+
3
+ = Installation
4
+
5
+ $ fluent-gem install fluent-plugin-hipchat
6
+
7
+ = Usage
8
+
9
+ <match hipchat>
10
+ type hipchat
11
+ api_token XXX
12
+ default_room my_room
13
+ default_from fluentd
14
+ default_color yellow
15
+ </match>
16
+
17
+
18
+ fluent_logger.post('hipchat', {
19
+ :from => 'alice',
20
+ :message => 'Hello<br>World!',
21
+ :color => 'red',
22
+ :room => 'my_room',
23
+ })
24
+
25
+ = Copyright
26
+
27
+ Copyright:: Copyright (c) 2012- Yuichi Tateno
28
+ License:: Apache License, Version 2.0
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.1.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-hipchat"
6
+ gem.description = "fluent HipChat plugin"
7
+ gem.homepage = "https://github.com/hotchpotch/fluent-plugin-hipchat"
8
+ gem.summary = gem.description
9
+ gem.version = File.read("VERSION").strip
10
+ gem.authors = ["Yuichi Tateno"]
11
+ gem.email = "hotchpotch@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,47 @@
1
+
2
+ module Fluent
3
+ class HipchatOutput < Output
4
+ COLORS = %w(yellow green purple random)
5
+ Fluent::Plugin.register_output('hipchat', self)
6
+
7
+ config_param :api_token, :string
8
+ config_param :default_room, :string, :default => nil
9
+ config_param :default_color, :string, :default => nil
10
+ config_param :default_from, :string, :default => nil
11
+
12
+ attr_reader :hipchat
13
+
14
+ def initialize
15
+ super
16
+ require 'hipchat-api'
17
+ end
18
+
19
+ def configure(conf)
20
+ super
21
+
22
+ @hipchat = HipChat::API.new(conf['api_token'])
23
+ @default_from = conf['default_from'] || 'fluentd'
24
+ @default_room = conf['default_room']
25
+ @default_color = conf['default_color'] || 'yellow'
26
+ end
27
+
28
+ def emit(tag, es, chain)
29
+ es.each {|time, record|
30
+ begin
31
+ send_message(record)
32
+ rescue => e
33
+ $log.error("HipChat Error: #{e} / #{e.message}")
34
+ end
35
+ }
36
+ end
37
+
38
+ def send_message(record)
39
+ room = record['room'] || @default_room
40
+ from = record['from'] || @default_from
41
+ message = record['message'] || ''
42
+ notify = record['notify'] ? 1 : 0
43
+ color = COLORS.include?(record['color']) ? record['color'] : @default_color
44
+ @hipchat.rooms_message(room, from, message, notify, color)
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,79 @@
1
+ require 'test_helper'
2
+ require 'fluent/plugin/out_hipchat'
3
+
4
+ class HipchatOutputTest < Test::Unit::TestCase
5
+ class OutputTestDriver < Fluent::Test::InputTestDriver
6
+ def initialize(klass, tag='test', &block)
7
+ super(klass, &block)
8
+ @tag = tag
9
+ end
10
+
11
+ attr_accessor :tag
12
+
13
+ def emit(record, time=Time.now)
14
+ es = Fluent::OneEventStream.new(time.to_i, record)
15
+ @instance.emit(@tag, es, nil)
16
+ end
17
+ end
18
+
19
+ def setup
20
+ super
21
+ Fluent::Test.setup
22
+ # any_instance_of(HipChat::Client, :redis= => lambda {}, :redis => @subject)
23
+ end
24
+
25
+ CONFIG = %[
26
+ type hipchat
27
+ api_token testtoken
28
+ default_room testroom
29
+ default_from testuser
30
+ default_color red
31
+ ]
32
+
33
+ def create_driver(conf = CONFIG)
34
+ OutputTestDriver.new(Fluent::HipchatOutput) {
35
+ }.configure(conf)
36
+ end
37
+
38
+ def test_default_message
39
+ d = create_driver(<<-EOF)
40
+ type hipchat
41
+ api_token xxx
42
+ default_room testroom
43
+ EOF
44
+ stub(d.instance.hipchat).rooms_message('testroom', 'fluentd', 'foo', 0, 'yellow')
45
+ assert_equal d.instance.hipchat.instance_variable_get(:@token), 'xxx'
46
+ d.emit({'message' => 'foo'})
47
+ d.run
48
+ end
49
+
50
+ def test_message
51
+ d = create_driver
52
+ stub(d.instance.hipchat).rooms_message('testroom', 'testuser', 'foo', 0, 'red')
53
+ assert_equal d.instance.hipchat.instance_variable_get(:@token), 'testtoken'
54
+ d.emit({'message' => 'foo'})
55
+ d.run
56
+ end
57
+
58
+ def test_message_override
59
+ d = create_driver
60
+ stub(d.instance.hipchat).rooms_message('my', 'alice', 'aaa', 1, 'random')
61
+ d.emit(
62
+ {
63
+ 'room' => 'my',
64
+ 'from' => 'alice',
65
+ 'message' => 'aaa',
66
+ 'notify' => true,
67
+ 'color' => 'random',
68
+ }
69
+ )
70
+ d.run
71
+ end
72
+
73
+ def test_color_validate
74
+ d = create_driver
75
+ stub(d.instance.hipchat).rooms_message('testroom', 'testuser', 'foo', 0, 'red')
76
+ d.emit({'message' => 'foo', 'color' => 'invalid'})
77
+ d.run
78
+ end
79
+ 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,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-hipchat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Yuichi Tateno
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: fluentd
16
+ requirement: &2172265700 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.10.8
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2172265700
25
+ - !ruby/object:Gem::Dependency
26
+ name: hipchat-api
27
+ requirement: &2172265000 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 1.0.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2172265000
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ requirement: &2172264540 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: 0.9.2
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *2172264540
47
+ - !ruby/object:Gem::Dependency
48
+ name: simplecov
49
+ requirement: &2172280440 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.5.4
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *2172280440
58
+ - !ruby/object:Gem::Dependency
59
+ name: rr
60
+ requirement: &2172279940 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: 1.0.0
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *2172279940
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: &2172279560 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *2172279560
80
+ description: fluent HipChat plugin
81
+ email: hotchpotch@gmail.com
82
+ executables: []
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - .gitignore
87
+ - .travis.yml
88
+ - AUTHORS
89
+ - Gemfile
90
+ - README.rdoc
91
+ - Rakefile
92
+ - VERSION
93
+ - fluent-plugin-hipchat.gemspec
94
+ - lib/fluent/plugin/out_hipchat.rb
95
+ - test/plugin/out_hipchat.rb
96
+ - test/test_helper.rb
97
+ homepage: https://github.com/hotchpotch/fluent-plugin-hipchat
98
+ licenses: []
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 1.8.17
118
+ signing_key:
119
+ specification_version: 3
120
+ summary: fluent HipChat plugin
121
+ test_files:
122
+ - test/plugin/out_hipchat.rb
123
+ - test/test_helper.rb