fluent-plugin-irc 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +11 -0
- data/Gemfile +4 -0
- data/LICENSE +3 -0
- data/README.md +59 -0
- data/Rakefile +11 -0
- data/example.conf +18 -0
- data/fluent-plugin-irc.gemspec +22 -0
- data/lib/fluent/plugin/out_irc.rb +133 -0
- data/test/helper.rb +27 -0
- data/test/plugin/test_out_irc.rb +46 -0
- metadata +89 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# Fluent::Plugin::Irc
|
2
|
+
|
3
|
+
Fluent plugin to send messages to IRC server
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
`$ fluent-gem install fluent-plugin-mongo`
|
8
|
+
|
9
|
+
## Configuration
|
10
|
+
|
11
|
+
### Example
|
12
|
+
|
13
|
+
```
|
14
|
+
<match **>
|
15
|
+
type irc
|
16
|
+
host localhost
|
17
|
+
port 6667
|
18
|
+
channel fluentd
|
19
|
+
nick fluentd
|
20
|
+
user fluentd
|
21
|
+
real fluentd
|
22
|
+
message notice: %s [%s] %s
|
23
|
+
out_keys tag,time,msg
|
24
|
+
time_key time
|
25
|
+
time_format %Y/%m/%d %H:%M:%S
|
26
|
+
tag_key tag
|
27
|
+
</match>
|
28
|
+
```
|
29
|
+
|
30
|
+
### Parameter
|
31
|
+
|
32
|
+
* host
|
33
|
+
* IRC server host
|
34
|
+
* port
|
35
|
+
* IRC server port number
|
36
|
+
* channel
|
37
|
+
* channel to send messages (without first '#')
|
38
|
+
* nick
|
39
|
+
* nickname registerd of IRC
|
40
|
+
* user
|
41
|
+
* user name registerd of IRC
|
42
|
+
* real
|
43
|
+
* real name registerd of IRC
|
44
|
+
* message
|
45
|
+
* message format. %s will be replaced with value specified by out_keys
|
46
|
+
* out_keys
|
47
|
+
* keys used to format messages
|
48
|
+
* time_key
|
49
|
+
* key name for time
|
50
|
+
* time_format
|
51
|
+
* time format. This will be formatted with Time#strftime.
|
52
|
+
* tag_key
|
53
|
+
* key name for tag
|
54
|
+
|
55
|
+
## Copyright
|
56
|
+
* Copyright
|
57
|
+
* Copyright (c) 2012 OKUNO Akihiro
|
58
|
+
* License
|
59
|
+
* Apache License, Version 2.0
|
data/Rakefile
ADDED
data/example.conf
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
<source>
|
2
|
+
type forward
|
3
|
+
</source>
|
4
|
+
|
5
|
+
<match **>
|
6
|
+
type irc
|
7
|
+
host localhost
|
8
|
+
port 6667
|
9
|
+
channel fluentd
|
10
|
+
nick fluentd
|
11
|
+
user fluentd
|
12
|
+
real fluentd
|
13
|
+
message notice: %s [%s] %s
|
14
|
+
out_keys tag,time,msg
|
15
|
+
time_key time
|
16
|
+
time_format %Y/%m/%d %H:%M:%S
|
17
|
+
tag_key tag
|
18
|
+
</match>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "fluent-plugin-irc"
|
6
|
+
s.version = "0.0.1"
|
7
|
+
s.authors = ["OKUNO Akihiro"]
|
8
|
+
s.email = ["okuno.akihiro@gmail.com"]
|
9
|
+
s.homepage = "https://github.com/choplin/fluent-plugin-irc"
|
10
|
+
s.summary = %q{Output plugin for IRC}
|
11
|
+
s.description = %q{Output plugin for IRC}
|
12
|
+
|
13
|
+
s.rubyforge_project = "fluent-plugin-irc"
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.add_runtime_dependency "fluentd"
|
21
|
+
s.add_runtime_dependency "irc_parser"
|
22
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
module Fluent
|
2
|
+
class IRCOutput < Fluent::Output
|
3
|
+
Fluent::Plugin.register_output('irc', self)
|
4
|
+
|
5
|
+
include SetTimeKeyMixin
|
6
|
+
include SetTagKeyMixin
|
7
|
+
|
8
|
+
config_set_default :include_time_key, true
|
9
|
+
config_set_default :include_tag_key, true
|
10
|
+
|
11
|
+
config_param :host , :string , :default => 'localhost'
|
12
|
+
config_param :port , :integer , :default => 6667
|
13
|
+
config_param :channel , :string
|
14
|
+
config_param :nick , :string , :default => 'fluentd'
|
15
|
+
config_param :user , :string , :default => 'fluentd'
|
16
|
+
config_param :real , :string , :default => 'fluentd'
|
17
|
+
config_param :message , :string
|
18
|
+
config_param :out_keys do |val|
|
19
|
+
val.split(',')
|
20
|
+
end
|
21
|
+
config_param :time_key , :string , :default => nil
|
22
|
+
config_param :time_format , :string , :default => nil
|
23
|
+
config_param :tag_key , :string , :default => 'tag'
|
24
|
+
|
25
|
+
|
26
|
+
def initialize
|
27
|
+
super
|
28
|
+
require 'irc_parser'
|
29
|
+
end
|
30
|
+
|
31
|
+
def configure(conf)
|
32
|
+
super
|
33
|
+
begin
|
34
|
+
@message % (['1'] * @out_keys.length)
|
35
|
+
rescue ArgumentError
|
36
|
+
raise Fluent::ConfigError, "string specifier '%s' and out_keys specification mismatch"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def start
|
41
|
+
super
|
42
|
+
begin
|
43
|
+
@client = IRCConnection.connect(@host, @port)
|
44
|
+
rescue
|
45
|
+
raise Fluent::ConfigError, "failto connect IRC server #{@host}:#{@port}"
|
46
|
+
end
|
47
|
+
|
48
|
+
@client.channel = '#'+@channel
|
49
|
+
@client.nick = @nick
|
50
|
+
@client.user = @user
|
51
|
+
@client.real = @real
|
52
|
+
@client.attach(Coolio::Loop.default)
|
53
|
+
end
|
54
|
+
|
55
|
+
def shutdown
|
56
|
+
super
|
57
|
+
@client.close
|
58
|
+
end
|
59
|
+
|
60
|
+
def emit(tag, es, chain)
|
61
|
+
chain.next
|
62
|
+
es.each do |time,record|
|
63
|
+
filter_record(tag, time, record)
|
64
|
+
IRCParser.message(:priv_msg) do |m|
|
65
|
+
m.target = @client.channel
|
66
|
+
m.body = build_message(record)
|
67
|
+
@client.send m
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
def build_message(record)
|
74
|
+
values = @out_keys.map {|key| record[key].to_s}
|
75
|
+
@message % values
|
76
|
+
end
|
77
|
+
|
78
|
+
class IRCConnection < Cool.io::TCPSocket
|
79
|
+
attr_accessor :channel, :nick, :user, :real
|
80
|
+
|
81
|
+
def on_connect
|
82
|
+
IRCParser.message(:nick) do |m|
|
83
|
+
m.nick = @nick
|
84
|
+
write m
|
85
|
+
end
|
86
|
+
IRCParser.message(:user) do |m|
|
87
|
+
m.user = @user
|
88
|
+
m.postfix = @real
|
89
|
+
write m
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def on_close
|
94
|
+
#TODO
|
95
|
+
end
|
96
|
+
|
97
|
+
def on_read(data)
|
98
|
+
data.each_line do |line|
|
99
|
+
begin
|
100
|
+
msg = IRCParser.parse(line)
|
101
|
+
case msg.class.to_sym
|
102
|
+
when :rpl_welcome
|
103
|
+
IRCParser.message(:join) do |m|
|
104
|
+
m.channels = @channel
|
105
|
+
write m
|
106
|
+
end
|
107
|
+
when :ping
|
108
|
+
IRCParser.message(:pong) do |m|
|
109
|
+
m.target = msg.target
|
110
|
+
m.body = msg.body
|
111
|
+
write m
|
112
|
+
end
|
113
|
+
end
|
114
|
+
rescue
|
115
|
+
#TODO
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def on_resolve_failed
|
121
|
+
#TODO
|
122
|
+
end
|
123
|
+
|
124
|
+
def on_connect_failed
|
125
|
+
#TODO
|
126
|
+
end
|
127
|
+
|
128
|
+
def send(msg)
|
129
|
+
write msg
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
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
|
+
require 'fluent/plugin/out_irc'
|
25
|
+
|
26
|
+
class Test::Unit::TestCase
|
27
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class IRCOutputTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
Fluent::Test.setup
|
6
|
+
end
|
7
|
+
|
8
|
+
CONFIG = %[
|
9
|
+
type irc
|
10
|
+
host localhost
|
11
|
+
port 6667
|
12
|
+
channel fluentd
|
13
|
+
nick fluentd
|
14
|
+
user fluentd
|
15
|
+
real fluentd
|
16
|
+
message notice: %s [%s] %s
|
17
|
+
out_keys tag,time,msg
|
18
|
+
time_key time
|
19
|
+
time_format %Y/%m/%d %H:%M:%S
|
20
|
+
tag_key tag
|
21
|
+
]
|
22
|
+
|
23
|
+
def create_driver(conf = CONFIG)
|
24
|
+
Fluent::Test::OutputTestDriver.new(Fluent::IRCOutput).configure(conf)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_configure
|
28
|
+
d = create_driver
|
29
|
+
|
30
|
+
assert_equal "localhost", d.instance.host
|
31
|
+
assert_equal 6667, d.instance.port
|
32
|
+
assert_equal "fluentd", d.instance.channel
|
33
|
+
assert_equal "fluentd", d.instance.nick
|
34
|
+
assert_equal "fluentd", d.instance.user
|
35
|
+
assert_equal "fluentd", d.instance.real
|
36
|
+
assert_equal "notice: %s [%s] %s", d.instance.message
|
37
|
+
assert_equal ["tag","time","msg"], d.instance.out_keys
|
38
|
+
assert_equal "time", d.instance.time_key
|
39
|
+
assert_equal "%Y/%m/%d %H:%M:%S", d.instance.time_format
|
40
|
+
assert_equal "tag", d.instance.tag_key
|
41
|
+
end
|
42
|
+
|
43
|
+
#def test_emit
|
44
|
+
#TODO
|
45
|
+
#end
|
46
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-irc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- OKUNO Akihiro
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-27 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: :runtime
|
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: irc_parser
|
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
|
47
|
+
email:
|
48
|
+
- okuno.akihiro@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- example.conf
|
59
|
+
- fluent-plugin-irc.gemspec
|
60
|
+
- lib/fluent/plugin/out_irc.rb
|
61
|
+
- test/helper.rb
|
62
|
+
- test/plugin/test_out_irc.rb
|
63
|
+
homepage: https://github.com/choplin/fluent-plugin-irc
|
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: fluent-plugin-irc
|
83
|
+
rubygems_version: 1.8.23
|
84
|
+
signing_key:
|
85
|
+
specification_version: 3
|
86
|
+
summary: Output plugin for IRC
|
87
|
+
test_files:
|
88
|
+
- test/helper.rb
|
89
|
+
- test/plugin/test_out_irc.rb
|