fluent-plugin-ikachan 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ test.conf
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-ikachan.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 TAGOMORI Satoshi
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,50 @@
1
+ # fluent-plugin-ikachan
2
+
3
+ ## Component
4
+
5
+ ### IkachanOutput
6
+
7
+ Plugin to send message to IRC, over IRC-HTTP bridge 'Ikachan' by yappo.
8
+
9
+ About Ikachan:
10
+ * https://metacpan.org/module/ikachan
11
+ * http://blog.yappo.jp/yappo/archives/000760.html (Japanese)
12
+
13
+ ## Configuration
14
+
15
+ ### IkachanOutput
16
+
17
+ Before testing of fluent-plugin-ikachan, you should invoke 'ikachan' process::
18
+
19
+ ### at first, install perl and cpanm (App::cpanminus)
20
+ cpanm App::ikachan
21
+ ikachan -S your.own.irc.server -P port
22
+
23
+ And then, configure out_ikachan::
24
+
25
+ <match alert.**>
26
+ # ikachan host/port(default 4979)
27
+ host localhost
28
+ port 4979
29
+ # channel to notify (this means #morischan)
30
+ channel morischan
31
+ message notice: %s [%s] %s
32
+ out_keys tag,time,msg
33
+ time_key time
34
+ time_format %Y/%m/%d %H:%M:%S
35
+ tag_key tag
36
+ </match>
37
+
38
+ You will got message like 'notice: alert.servicename [2012/05/10 18:51:59] alert message in attribute "msg"'.
39
+
40
+ ## TODO
41
+
42
+ * implement 'tag_mapped'
43
+ * implement 'time' and 'tag' in key_names
44
+
45
+ ## Copyright
46
+
47
+ * Copyright
48
+ * Copyright (c) 2012- TAGOMORI Satoshi (tagomoris)
49
+ * License
50
+ * Apache License, Version 2.0
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rake/testtask'
5
+ Rake::TestTask.new(:test) do |test|
6
+ test.libs << 'lib' << 'test'
7
+ test.pattern = 'test/**/test_*.rb'
8
+ test.verbose = true
9
+ end
10
+
11
+ task :default => :test
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ Gem::Specification.new do |gem|
3
+ gem.name = "fluent-plugin-ikachan"
4
+ gem.version = "0.1.0"
5
+ gem.authors = ["TAGOMORI Satoshi"]
6
+ gem.email = ["tagomoris@gmail.com"]
7
+ gem.summary = %q{output plugin for IRC-HTTP gateway 'ikachan'}
8
+ gem.description = %q{output plugin for IRC-HTTP gateway 'ikachan' (see: https://metacpan.org/module/ikachan and (jpn) http://blog.yappo.jp/yappo/archives/000760.html)}
9
+ gem.homepage = "https://github.com/tagomoris/fluent-plugin-ikachan"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.require_paths = ["lib"]
15
+
16
+ gem.add_development_dependency "fluentd"
17
+ gem.add_runtime_dependency "fluentd"
18
+ end
@@ -0,0 +1,92 @@
1
+ class Fluent::IkachanOutput < Fluent::Output
2
+ Fluent::Plugin.register_output('ikachan', self)
3
+
4
+ config_param :host, :string
5
+ config_param :port, :integer, :default => 4979
6
+ config_param :channel, :string
7
+ config_param :message, :string
8
+ config_param :out_keys, :string
9
+ config_param :time_key, :string, :default => nil
10
+ config_param :time_format, :string, :default => nil
11
+ config_param :tag_key, :string, :default => 'tag'
12
+
13
+ def initialize
14
+ super
15
+ require 'net/http'
16
+ require 'uri'
17
+ end
18
+
19
+ def configure(conf)
20
+ super
21
+
22
+ @channel = '#' + @channel
23
+ @join_uri = URI.parse "http://#{@host}:#{@port}/join"
24
+ @notice_uri = URI.parse "http://#{@host}:#{@port}/notice"
25
+
26
+ @out_keys = conf['out_keys'].split(',')
27
+
28
+ begin
29
+ @message % (['1'] * @out_keys.length)
30
+ rescue ArgumentError
31
+ raise Fluent::ConfigError, "string specifier '%s' and out_keys specification mismatch"
32
+ end
33
+
34
+ if @time_key
35
+ if @time_format
36
+ f = @time_format
37
+ tf = Fluent::TimeFormatter.new(f, @localtime)
38
+ @time_format_proc = tf.method(:format)
39
+ @time_parse_proc = Proc.new {|str| Time.strptime(str, f).to_i }
40
+ else
41
+ @time_format_proc = Proc.new {|time| time.to_s }
42
+ @time_parse_proc = Proc.new {|str| str.to_i }
43
+ end
44
+ end
45
+ end
46
+
47
+ def start
48
+ res = Net::HTTP.post_form(@join_uri, {'channel' => @channel})
49
+ if res.code.to_i == 200
50
+ # ok
51
+ elsif res.code.to_i == 403 and res.body == "joinned channel: #{@channel}"
52
+ # ok
53
+ else
54
+ raise Fluent::ConfigError, "failed to connect ikachan server #{@host}:#{@port}"
55
+ end
56
+ end
57
+
58
+ def shutdown
59
+ end
60
+
61
+ def emit(tag, es, chain)
62
+ messages = []
63
+
64
+ es.each {|time,record|
65
+ values = []
66
+ last = @out_keys.length - 1
67
+
68
+ values = @out_keys.map do |key|
69
+ case key
70
+ when @time_key
71
+ @time_format_proc.call(time)
72
+ when @tag_key
73
+ tag
74
+ else
75
+ record[key].to_s
76
+ end
77
+ end
78
+ messages.push (@message % values)
79
+ }
80
+
81
+ messages.each do |msg|
82
+ begin
83
+ res = Net::HTTP.post_form(@notice_uri, {'channel' => @channel, 'message' => msg})
84
+ rescue
85
+ $log.warn "out_ikachan: failed to send notice to #{@host}:#{@port}, #{@channel}, message: #{msg}"
86
+ end
87
+ end
88
+
89
+ chain.next
90
+ end
91
+
92
+ end
@@ -0,0 +1,28 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+
12
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
14
+ require 'fluent/test'
15
+ unless ENV.has_key?('VERBOSE')
16
+ nulllogger = Object.new
17
+ nulllogger.instance_eval {|obj|
18
+ def method_missing(method, *args)
19
+ # pass
20
+ end
21
+ }
22
+ $log = nulllogger
23
+ end
24
+
25
+ require 'fluent/plugin/out_ikachan'
26
+
27
+ class Test::Unit::TestCase
28
+ end
@@ -0,0 +1,33 @@
1
+ require 'helper'
2
+
3
+ class IkachanOutputTest < Test::Unit::TestCase
4
+ CONFIG = %[
5
+ host localhost
6
+ channel morischan
7
+ message out_ikachan: %s [%s] %s
8
+ out_keys tag,time,msg
9
+ time_key time
10
+ time_format %Y/%m/%d %H:%M:%S
11
+ tag_key tag
12
+ ]
13
+
14
+ def create_driver(conf=CONFIG,tag='test')
15
+ Fluent::Test::OutputTestDriver.new(Fluent::IkachanOutput, tag).configure(conf)
16
+ end
17
+
18
+ def test_configure
19
+ d = create_driver
20
+ assert_equal '#morischan', d.instance.channel
21
+ end
22
+
23
+ def test_notice
24
+ # To test this code, execute ikachan on your own host
25
+ d = create_driver
26
+ time = Time.now.to_i
27
+ d.run do
28
+ d.emit({'msg' => "message from fluentd out_ikachan: testing now"}, time)
29
+ d.emit({'msg' => "message from fluentd out_ikachan: testing second line"}, time)
30
+ end
31
+ end
32
+
33
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-ikachan
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - TAGOMORI Satoshi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: fluentd
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: fluentd
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: ! 'output plugin for IRC-HTTP gateway ''ikachan'' (see: https://metacpan.org/module/ikachan
47
+ and (jpn) http://blog.yappo.jp/yappo/archives/000760.html)'
48
+ email:
49
+ - tagomoris@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE
57
+ - README.md
58
+ - Rakefile
59
+ - fluent-plugin-ikachan.gemspec
60
+ - lib/fluent/plugin/out_ikachan.rb
61
+ - test/helper.rb
62
+ - test/plugin/test_out_ikachan.rb
63
+ homepage: https://github.com/tagomoris/fluent-plugin-ikachan
64
+ licenses: []
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 1.8.21
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: output plugin for IRC-HTTP gateway 'ikachan'
87
+ test_files:
88
+ - test/helper.rb
89
+ - test/plugin/test_out_ikachan.rb