fluent-plugin-zabbix-simple 1.0.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.
- data/.gitignore +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +31 -0
- data/LICENSE +13 -0
- data/README-ja.md +123 -0
- data/README.md +122 -0
- data/Rakefile +12 -0
- data/fluent-plugin-zabbix-simple.gemspec +21 -0
- data/lib/fluent/plugin/out_zabbix_simple.rb +119 -0
- data/test/helper.rb +28 -0
- data/test/plugin/test_out_zabbix_simple.rb +186 -0
- metadata +106 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
fluent-plugin-zabbix-simple (1.0.0)
|
5
|
+
fluentd
|
6
|
+
zabbix
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
cool.io (1.1.0)
|
12
|
+
iobuffer (>= 1.0.0)
|
13
|
+
fluentd (0.10.31)
|
14
|
+
cool.io (~> 1.1.0)
|
15
|
+
http_parser.rb (~> 0.5.1)
|
16
|
+
json (>= 1.4.3)
|
17
|
+
msgpack (~> 0.4.4)
|
18
|
+
yajl-ruby (~> 1.0)
|
19
|
+
http_parser.rb (0.5.3)
|
20
|
+
iobuffer (1.1.2)
|
21
|
+
json (1.7.7)
|
22
|
+
msgpack (0.4.7)
|
23
|
+
yajl-ruby (1.1.0)
|
24
|
+
zabbix (0.4.0)
|
25
|
+
|
26
|
+
PLATFORMS
|
27
|
+
ruby
|
28
|
+
|
29
|
+
DEPENDENCIES
|
30
|
+
fluent-plugin-zabbix-simple!
|
31
|
+
fluentd
|
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2013 NAKANO Hideo
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README-ja.md
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
= fluent-plugin-zabbix-simple
|
2
|
+
|
3
|
+
== Component
|
4
|
+
|
5
|
+
=== ZabbixSimpleOutput
|
6
|
+
|
7
|
+
fluent が生成する JSON キーを変換し、Zabbix server へ送信します。
|
8
|
+
|
9
|
+
* 変換するキーは複数個定義でき、個数に制限はありません。
|
10
|
+
|
11
|
+
* 変換するキーには正規表現を使うことができ、正規表現を使った置換もできます。
|
12
|
+
|
13
|
+
== Install
|
14
|
+
|
15
|
+
コマンド `gem install` を実行します。
|
16
|
+
|
17
|
+
$ sudo gem install fluent-plugin-zabbix-simple
|
18
|
+
|
19
|
+
td-agent は専用の Ruby 処理系を持っています。
|
20
|
+
td-agent をインストールしている場合、td-agent 付属の gem コマンドを用いてインストールしなければならないかもしれません。
|
21
|
+
|
22
|
+
$ sudo /usr/lib64/fluent/ruby/bin/gem isntall fluent-plugin-zabbix-simple
|
23
|
+
|
24
|
+
== Configuration
|
25
|
+
|
26
|
+
=== Zabbix Server 設定
|
27
|
+
|
28
|
+
あらかじめ Zabbix server で次のようなアイテムを定義しておきます:
|
29
|
+
|
30
|
+
Key: httpd.status[2xx]
|
31
|
+
Type: Zabbix trapper
|
32
|
+
Type of information: Numeric(unsigned)
|
33
|
+
|
34
|
+
Key: httpd.status[3xx]
|
35
|
+
Type: Zabbix trapper
|
36
|
+
Type of information: Numeric(unsigned)
|
37
|
+
|
38
|
+
こつは:
|
39
|
+
|
40
|
+
* `Type` を `Zabbix trapper` にしなければなりません。
|
41
|
+
|
42
|
+
* `Type of information` は適切な型を選択してください。
|
43
|
+
|
44
|
+
=== Plugin 設定&テスト
|
45
|
+
|
46
|
+
Plugin をテストするため次のようなファイルを作成します。
|
47
|
+
|
48
|
+
<source>
|
49
|
+
type forward
|
50
|
+
</source>
|
51
|
+
<match httpd.access.status_count>
|
52
|
+
type zabbix_simple
|
53
|
+
zabbix_server 192.168.0.1
|
54
|
+
map_key1 httpd.access_(...)_count httpd.status[\1]
|
55
|
+
</match>
|
56
|
+
|
57
|
+
このファイルを fluentd.conf として保存し、fluentd を実行してみましょう。
|
58
|
+
|
59
|
+
$ fluentd -c ./fluent.conf -vv
|
60
|
+
|
61
|
+
もし td-agent をインストールしているなら、代わりに次のコマンドを実行します。
|
62
|
+
|
63
|
+
$ /usr/sbin/td-agent -c ./fluent.conf -vv
|
64
|
+
|
65
|
+
別のターミナルを開き、fluentd サーバに、メッセージを送ってみます。
|
66
|
+
|
67
|
+
$ echo '{"httpd.access_2xx_count":321}' | fluent-cat httpd.access.status_count
|
68
|
+
|
69
|
+
30 秒程度待って、Zabbix Server に 321 が記録されていることを確認します。
|
70
|
+
|
71
|
+
== Too Many Keys
|
72
|
+
|
73
|
+
既定では、キーは 20 番まで検索します。
|
74
|
+
もし 20 個以上のキーを指定する場合、key_size を指定しなければなりません。
|
75
|
+
|
76
|
+
<match httpd.access.status_count>
|
77
|
+
type zabbix_simple
|
78
|
+
zabbix_server 192.168.0.1
|
79
|
+
key_size 25
|
80
|
+
map_key1 pattern1 replace1
|
81
|
+
map_key2 pattern2 replace2
|
82
|
+
map_key3 pattern3 replace3
|
83
|
+
map_key4 pattern4 replace4
|
84
|
+
map_key5 pattern5 replace5
|
85
|
+
map_key6 pattern6 replace6
|
86
|
+
map_key7 pattern7 replace7
|
87
|
+
map_key8 pattern8 replace8
|
88
|
+
map_key9 pattern9 replace9
|
89
|
+
map_key10 pattern10 replace10
|
90
|
+
map_key11 pattern11 replace11
|
91
|
+
map_key12 pattern12 replace12
|
92
|
+
map_key13 pattern13 replace13
|
93
|
+
map_key14 pattern14 replace14
|
94
|
+
map_key15 pattern15 replace15
|
95
|
+
map_key16 pattern16 replace16
|
96
|
+
map_key17 pattern17 replace17
|
97
|
+
map_key18 pattern18 replace18
|
98
|
+
map_key19 pattern19 replace19
|
99
|
+
map_key20 pattern20 replace20
|
100
|
+
map_key21 pattern21 replace21
|
101
|
+
map_key22 pattern22 replace22
|
102
|
+
map_key23 pattern23 replace23
|
103
|
+
map_key24 pattern24 replace24
|
104
|
+
map_key25 pattern25 replace25
|
105
|
+
</match>
|
106
|
+
|
107
|
+
== Specification of `map_key`
|
108
|
+
|
109
|
+
* `map_key0` も使用できます。
|
110
|
+
|
111
|
+
* 0 番目の map_key から順にマッチするかどうかを調べ、最初にマッチした map_key を使い、
|
112
|
+
残りの map_key にマッチするものがあったとしても使用されません。
|
113
|
+
|
114
|
+
* `map_key01` などのように 0 を数値の左に詰めてはいけません。
|
115
|
+
|
116
|
+
== TODO
|
117
|
+
|
118
|
+
- patches welcome!
|
119
|
+
|
120
|
+
== Copyright
|
121
|
+
|
122
|
+
Copyright:: Copyright (c) 2013- NAKANO Hideo
|
123
|
+
License:: Apache License, Version 2.0
|
data/README.md
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
= fluent-plugin-zabbix-simple
|
2
|
+
|
3
|
+
== Component
|
4
|
+
|
5
|
+
=== ZabbixSimpleOutput
|
6
|
+
|
7
|
+
fluent-plugin-zabbix-simple converts fluent JSON key into zabbix key, and sends zabbix key and its value to Zabbix Server.
|
8
|
+
|
9
|
+
* You can define multiple key map, no size limitation.
|
10
|
+
|
11
|
+
* You can use regex and you can replace the fluent JSON key using regex.
|
12
|
+
|
13
|
+
== Install
|
14
|
+
|
15
|
+
execute command `gem install`:
|
16
|
+
|
17
|
+
$ sudo gem install fluent-plugin-zabbix-simple
|
18
|
+
|
19
|
+
td-agent has its own Ruby ecosystem.
|
20
|
+
If you have installed td-agent, You would use `gem` command included with td-agent:
|
21
|
+
|
22
|
+
$ sudo /usr/lib64/fluent/ruby/bin/gem isntall fluent-plugin-zabbix-simple
|
23
|
+
|
24
|
+
== Configuration
|
25
|
+
|
26
|
+
=== Zabbix Server Configuration
|
27
|
+
|
28
|
+
In advance, You shoud define zabbix items like this:
|
29
|
+
|
30
|
+
Key: httpd.status[2xx]
|
31
|
+
Type: Zabbix trapper
|
32
|
+
Type of information: Numeric(unsigned)
|
33
|
+
|
34
|
+
Key: httpd.status[3xx]
|
35
|
+
Type: Zabbix trapper
|
36
|
+
Type of information: Numeric(unsigned)
|
37
|
+
|
38
|
+
Tips:
|
39
|
+
|
40
|
+
* You must set `Type` to `Zabbix trapper`.
|
41
|
+
|
42
|
+
* You must choose a appropriate `Type of information`.
|
43
|
+
|
44
|
+
=== Plugin Configuration and Test
|
45
|
+
|
46
|
+
To test plugin, create file:
|
47
|
+
|
48
|
+
<source>
|
49
|
+
type forward
|
50
|
+
</source>
|
51
|
+
<match httpd.access.status_count>
|
52
|
+
type zabbix_simple
|
53
|
+
zabbix_server 192.168.0.1
|
54
|
+
map_key1 httpd.access_(...)_count httpd.status[\1]
|
55
|
+
</match>
|
56
|
+
|
57
|
+
Save above file to `fluentd.conf`, execute `fluentd`:
|
58
|
+
|
59
|
+
$ fluentd -c ./fluent.conf -vv
|
60
|
+
|
61
|
+
If you have installed td-agent, execute a command like this:
|
62
|
+
|
63
|
+
$ /usr/sbin/td-agent -c ./fluent.conf -vv
|
64
|
+
|
65
|
+
Open another termina, send a test message to fluentd server.
|
66
|
+
|
67
|
+
$ echo '{"httpd.access_2xx_count":321}' | fluent-cat httpd.access.status_count
|
68
|
+
|
69
|
+
after a few seconds, confirm that the 321 has been recorded in the Zabbix Server.
|
70
|
+
|
71
|
+
== Too Many Keys
|
72
|
+
|
73
|
+
By default, key_map is scanned up to 20.
|
74
|
+
you must specify `key_size` if you want to use key_map more than 20.
|
75
|
+
|
76
|
+
<match httpd.access.status_count>
|
77
|
+
type zabbix_simple
|
78
|
+
zabbix_server 192.168.0.1
|
79
|
+
key_size 25
|
80
|
+
map_key1 pattern1 replace1
|
81
|
+
map_key2 pattern2 replace2
|
82
|
+
map_key3 pattern3 replace3
|
83
|
+
map_key4 pattern4 replace4
|
84
|
+
map_key5 pattern5 replace5
|
85
|
+
map_key6 pattern6 replace6
|
86
|
+
map_key7 pattern7 replace7
|
87
|
+
map_key8 pattern8 replace8
|
88
|
+
map_key9 pattern9 replace9
|
89
|
+
map_key10 pattern10 replace10
|
90
|
+
map_key11 pattern11 replace11
|
91
|
+
map_key12 pattern12 replace12
|
92
|
+
map_key13 pattern13 replace13
|
93
|
+
map_key14 pattern14 replace14
|
94
|
+
map_key15 pattern15 replace15
|
95
|
+
map_key16 pattern16 replace16
|
96
|
+
map_key17 pattern17 replace17
|
97
|
+
map_key18 pattern18 replace18
|
98
|
+
map_key19 pattern19 replace19
|
99
|
+
map_key20 pattern20 replace20
|
100
|
+
map_key21 pattern21 replace21
|
101
|
+
map_key22 pattern22 replace22
|
102
|
+
map_key23 pattern23 replace23
|
103
|
+
map_key24 pattern24 replace24
|
104
|
+
map_key25 pattern25 replace25
|
105
|
+
</match>
|
106
|
+
|
107
|
+
== Specification of `map_key`
|
108
|
+
|
109
|
+
* you can use `map_key0`.
|
110
|
+
|
111
|
+
* lookup from `map_key0`, use first matched map_key, ignore the remaining map_keys.
|
112
|
+
|
113
|
+
* you must not padding 0 like `map_key01`.
|
114
|
+
|
115
|
+
== TODO
|
116
|
+
|
117
|
+
- patches welcome!
|
118
|
+
|
119
|
+
== Copyright
|
120
|
+
|
121
|
+
Copyright:: Copyright (c) 2013 NAKANO Hideo
|
122
|
+
License:: Apache License, Version 2.0
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
# -*- mode:ruby -*-
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
|
5
|
+
require 'rake/testtask'
|
6
|
+
Rake::TestTask.new(:test) do |test|
|
7
|
+
test.libs << 'lib' << 'test'
|
8
|
+
test.pattern = 'test/**/test_*.rb'
|
9
|
+
test.verbose = true
|
10
|
+
end
|
11
|
+
|
12
|
+
task :default => :test
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- mode:ruby -*-
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["NAKANO Hideo"]
|
6
|
+
gem.email = ["nakano@ilu.co.jp"]
|
7
|
+
gem.description = %q{Output data plugin to Zabbix}
|
8
|
+
gem.summary = %q{Output data plugin to Zabbix (like zabbix_sender)}
|
9
|
+
gem.homepage = "https://github.com/sunny4381/fluent-plugin-zabbix-simple"
|
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.name = "fluent-plugin-zabbix-simple"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = "1.0.0"
|
17
|
+
|
18
|
+
gem.add_development_dependency "fluentd"
|
19
|
+
gem.add_runtime_dependency "fluentd"
|
20
|
+
gem.add_runtime_dependency "zabbix"
|
21
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
#
|
2
|
+
# Fluent::ZabbixSimpleOutput
|
3
|
+
#
|
4
|
+
# Copyright (C) 2013 NAKANO Hideo
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
class Fluent::ZabbixSimpleOutput < Fluent::Output
|
19
|
+
Fluent::Plugin.register_output('zabbix_simple', self)
|
20
|
+
|
21
|
+
def initialize
|
22
|
+
super
|
23
|
+
require 'zabbix'
|
24
|
+
require 'socket'
|
25
|
+
end
|
26
|
+
|
27
|
+
attr_reader :zabbix_server, :port, :host, :key_size, :map_keys
|
28
|
+
|
29
|
+
config_param :zabbix_server, :string
|
30
|
+
config_param :port, :integer, :default => 10051
|
31
|
+
config_param :host, :string, :default => Socket.gethostname
|
32
|
+
config_param :key_size, :integer, :default => 20
|
33
|
+
|
34
|
+
KeyMap = Struct.new(:id, :pattern, :replace)
|
35
|
+
|
36
|
+
def configure(conf)
|
37
|
+
super
|
38
|
+
|
39
|
+
if @zabbix_server.nil?
|
40
|
+
raise Fluent::ConfigError, "missing zabbix_server"
|
41
|
+
end
|
42
|
+
|
43
|
+
@map_keys = []
|
44
|
+
(0..@key_size).each do |i|
|
45
|
+
next unless conf["map_key#{i}"]
|
46
|
+
pattern,replace = conf["map_key#{i}"].split(' ', 2)
|
47
|
+
@map_keys.push(KeyMap.new(i, Regexp.new(pattern), replace))
|
48
|
+
end
|
49
|
+
|
50
|
+
if @map_keys.nil? or @map_keys.size == 0
|
51
|
+
raise Fluent::ConfigError, "missing map_key[0..]"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def start
|
56
|
+
super
|
57
|
+
end
|
58
|
+
|
59
|
+
def shutdown
|
60
|
+
super
|
61
|
+
end
|
62
|
+
|
63
|
+
def create_zbx_sender
|
64
|
+
Zabbix::Sender.new(:host => @zabbix_server, :port => @port)
|
65
|
+
end
|
66
|
+
|
67
|
+
def send(zbx_sender, name, value, time)
|
68
|
+
begin
|
69
|
+
$log.debug { "name: #{name}, value: #{value}, time: #{time}" }
|
70
|
+
|
71
|
+
opts = { :host => @host, :ts => time }
|
72
|
+
status = zbx_sender.send_data(name, value.to_s, opts)
|
73
|
+
|
74
|
+
rescue IOError, EOFError, SystemCallError
|
75
|
+
# server didn't respond
|
76
|
+
$log.warn "Zabbix::Sender.send_data raises exception: #{$!.class}, '#{$!.message}'"
|
77
|
+
status = false
|
78
|
+
end
|
79
|
+
unless status
|
80
|
+
$log.warn "failed to send to zabbix_server `#{@zabbix_server}(port:`#{@port}`), host:#{@host} '#{name}': #{value}"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def emit(tag, es, chain)
|
85
|
+
zbx_sender = nil
|
86
|
+
begin
|
87
|
+
$log.trace { "connecting to zabbix server `#{@zabbix_server}(port:`#{@port}`)" }
|
88
|
+
zbx_sender = create_zbx_sender
|
89
|
+
zbx_sender.connect
|
90
|
+
$log.trace "done connected to zabbix server"
|
91
|
+
rescue
|
92
|
+
$log.warn "could not connect to zabbix server `#{@zabbix_server}(port:`#{@port})`, exception: #{$!.class}, '#{$!.message}'"
|
93
|
+
end
|
94
|
+
|
95
|
+
if zbx_sender
|
96
|
+
es.each do |time, record|
|
97
|
+
record.each do |key,value|
|
98
|
+
@map_keys.each do |map|
|
99
|
+
zbx_key = map_key(key, map.pattern, map.replace)
|
100
|
+
next unless zbx_key
|
101
|
+
send(zbx_sender, zbx_key, value, time)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
zbx_sender.disconnect
|
106
|
+
end
|
107
|
+
|
108
|
+
# call next chain
|
109
|
+
chain.next
|
110
|
+
end
|
111
|
+
|
112
|
+
def map_key(key, pattern, replace)
|
113
|
+
unless pattern =~ key
|
114
|
+
nil
|
115
|
+
else
|
116
|
+
key.sub(pattern, replace)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
data/test/helper.rb
ADDED
@@ -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_zabbix_simple'
|
26
|
+
|
27
|
+
class Test::Unit::TestCase
|
28
|
+
end
|
@@ -0,0 +1,186 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module Mock
|
4
|
+
class ::Fluent::ZabbixSimpleOutput
|
5
|
+
def self.mock!
|
6
|
+
include MockZabbixSimpleOutput
|
7
|
+
alias_method :old_create_zbx_sender, :create_zbx_sender
|
8
|
+
alias_method :create_zbx_sender, :mock_create_zbx_sender
|
9
|
+
end
|
10
|
+
def self.unmock!
|
11
|
+
return unless method_defined? :mock_say
|
12
|
+
alias_method :say, :old_say
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class MockZbxSender
|
17
|
+
@@data = []
|
18
|
+
def send_data(key, value, opts)
|
19
|
+
@@data.push([key, value, opts])
|
20
|
+
end
|
21
|
+
def connect
|
22
|
+
end
|
23
|
+
def disconnect
|
24
|
+
end
|
25
|
+
def configured?()
|
26
|
+
true
|
27
|
+
end
|
28
|
+
def self.data
|
29
|
+
@@data
|
30
|
+
end
|
31
|
+
def self.clearData
|
32
|
+
@@data = []
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
module MockZabbixSimpleOutput
|
37
|
+
def mock_create_zbx_sender
|
38
|
+
MockZbxSender.new
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class ZabbixOutputSimpleTest < Test::Unit::TestCase
|
44
|
+
def setup
|
45
|
+
Fluent::Test.setup
|
46
|
+
end
|
47
|
+
|
48
|
+
CONFIG = %[
|
49
|
+
zabbix_server 127.0.0.1
|
50
|
+
host clienthost
|
51
|
+
map_key1 x1 y1
|
52
|
+
map_key2 x2 y2
|
53
|
+
]
|
54
|
+
|
55
|
+
def create_driver(conf = CONFIG, tag='test')
|
56
|
+
Fluent::Test::OutputTestDriver.new(Fluent::ZabbixSimpleOutput, tag).configure(conf)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_emit001
|
60
|
+
::Mock::MockZbxSender.clearData
|
61
|
+
Fluent::ZabbixSimpleOutput.mock!
|
62
|
+
d = create_driver
|
63
|
+
d.emit({"x1" => "test value of x1"})
|
64
|
+
Fluent::ZabbixSimpleOutput.unmock!
|
65
|
+
|
66
|
+
assert_equal(1, ::Mock::MockZbxSender.data.size)
|
67
|
+
assert_equal("y1", ::Mock::MockZbxSender.data[0][0])
|
68
|
+
assert_equal("test value of x1", ::Mock::MockZbxSender.data[0][1])
|
69
|
+
assert_equal("clienthost", ::Mock::MockZbxSender.data[0][2][:host])
|
70
|
+
assert_block do
|
71
|
+
::Mock::MockZbxSender.data[0][2][:ts] > 0
|
72
|
+
end
|
73
|
+
::Mock::MockZbxSender.clearData
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_emit002
|
77
|
+
::Mock::MockZbxSender.clearData
|
78
|
+
|
79
|
+
Fluent::ZabbixSimpleOutput.mock!
|
80
|
+
d = create_driver
|
81
|
+
d.emit({"x3" => "test value of x3"})
|
82
|
+
Fluent::ZabbixSimpleOutput.unmock!
|
83
|
+
|
84
|
+
assert_equal(0, ::Mock::MockZbxSender.data.size)
|
85
|
+
|
86
|
+
::Mock::MockZbxSender.clearData
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_emit003
|
90
|
+
::Mock::MockZbxSender.clearData
|
91
|
+
|
92
|
+
Fluent::ZabbixSimpleOutput.mock!
|
93
|
+
d = create_driver %{
|
94
|
+
zabbix_server 127.0.0.1
|
95
|
+
map_key1 input_([^_]+)_count httpd.count[\\1]
|
96
|
+
}
|
97
|
+
d.emit({"input_unmatched_count" => 10, "input_unmatched_rate" => 0.431, "input_unmatched_percentage" => 0.73})
|
98
|
+
d.emit({"input_status2xx_count" => 1884540035, "input_status2xx_rate" => 2041995578.0 / 730602602.0, "input_status2xx_percentage" => 422483907.0 / 426370718.0})
|
99
|
+
Fluent::ZabbixSimpleOutput.unmock!
|
100
|
+
|
101
|
+
assert_equal(2, ::Mock::MockZbxSender.data.size)
|
102
|
+
assert_equal("httpd.count[unmatched]", ::Mock::MockZbxSender.data[0][0])
|
103
|
+
assert_equal("10", ::Mock::MockZbxSender.data[0][1])
|
104
|
+
assert_equal("httpd.count[status2xx]", ::Mock::MockZbxSender.data[1][0])
|
105
|
+
assert_equal("1884540035", ::Mock::MockZbxSender.data[1][1])
|
106
|
+
|
107
|
+
::Mock::MockZbxSender.clearData
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_configure001
|
111
|
+
d = create_driver
|
112
|
+
assert_equal("127.0.0.1", d.instance.zabbix_server)
|
113
|
+
assert_equal(10051, d.instance.port)
|
114
|
+
assert_equal("clienthost", d.instance.host)
|
115
|
+
assert_equal(20, d.instance.key_size)
|
116
|
+
assert_equal(2, d.instance.map_keys.size)
|
117
|
+
|
118
|
+
assert_equal(1, d.instance.map_keys[0][0])
|
119
|
+
assert_equal("/x1/", d.instance.map_keys[0][1].inspect)
|
120
|
+
assert_equal("y1", d.instance.map_keys[0][2])
|
121
|
+
assert_equal(2, d.instance.map_keys[1][0])
|
122
|
+
assert_equal("/x2/", d.instance.map_keys[1][1].inspect)
|
123
|
+
assert_equal("y2", d.instance.map_keys[1][2])
|
124
|
+
|
125
|
+
assert_equal(1, d.instance.map_keys[0].id)
|
126
|
+
assert_equal("/x1/", d.instance.map_keys[0].pattern.inspect)
|
127
|
+
assert_equal("y1", d.instance.map_keys[0].replace)
|
128
|
+
assert_equal(2, d.instance.map_keys[1].id)
|
129
|
+
assert_equal("/x2/", d.instance.map_keys[1].pattern.inspect)
|
130
|
+
assert_equal("y2", d.instance.map_keys[1].replace)
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_configure002
|
134
|
+
assert_raise Fluent::ConfigError do
|
135
|
+
d = create_driver %[
|
136
|
+
host clienthost
|
137
|
+
]
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_configure003
|
142
|
+
assert_raise Fluent::ConfigError do
|
143
|
+
d = create_driver %[
|
144
|
+
zabbix_server 127.0.0.1
|
145
|
+
host clienthost
|
146
|
+
]
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_configure004
|
151
|
+
d = create_driver %[
|
152
|
+
zabbix_server 127.0.0.1
|
153
|
+
port 490478390,
|
154
|
+
host clienthost
|
155
|
+
map_key3 x1 y1
|
156
|
+
]
|
157
|
+
|
158
|
+
assert_equal("127.0.0.1", d.instance.zabbix_server)
|
159
|
+
assert_equal(490478390, d.instance.port)
|
160
|
+
assert_equal("clienthost", d.instance.host)
|
161
|
+
assert_equal(20, d.instance.key_size)
|
162
|
+
assert_equal(1, d.instance.map_keys.size)
|
163
|
+
assert_equal(3, d.instance.map_keys[0][0])
|
164
|
+
assert_equal("/x1/", d.instance.map_keys[0][1].inspect)
|
165
|
+
assert_equal("y1", d.instance.map_keys[0][2])
|
166
|
+
assert_equal(3, d.instance.map_keys[0].id)
|
167
|
+
assert_equal("/x1/", d.instance.map_keys[0].pattern.inspect)
|
168
|
+
assert_equal("y1", d.instance.map_keys[0].replace)
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_map_key
|
172
|
+
d = create_driver
|
173
|
+
|
174
|
+
assert_equal("http.statusCount[2xx]",
|
175
|
+
d.instance.map_key("input_status2xx_count", /^.+_status(...)_count$/,
|
176
|
+
'http.statusCount[\1]'))
|
177
|
+
assert_equal("http.statusCount[2xx]",
|
178
|
+
d.instance.map_key("input_status2xx_count",
|
179
|
+
Regexp.new('^.+_status(...)_count$'),
|
180
|
+
'http.statusCount[\1]'))
|
181
|
+
assert_nil(
|
182
|
+
d.instance.map_key("input_status2xx_rate",
|
183
|
+
Regexp.new('^.+_status(...)_count$'),
|
184
|
+
'http.statusCount[\1]'))
|
185
|
+
end
|
186
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-zabbix-simple
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- NAKANO Hideo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-14 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
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: zabbix
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Output data plugin to Zabbix
|
63
|
+
email:
|
64
|
+
- nakano@ilu.co.jp
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- Gemfile
|
71
|
+
- Gemfile.lock
|
72
|
+
- LICENSE
|
73
|
+
- README-ja.md
|
74
|
+
- README.md
|
75
|
+
- Rakefile
|
76
|
+
- fluent-plugin-zabbix-simple.gemspec
|
77
|
+
- lib/fluent/plugin/out_zabbix_simple.rb
|
78
|
+
- test/helper.rb
|
79
|
+
- test/plugin/test_out_zabbix_simple.rb
|
80
|
+
homepage: https://github.com/sunny4381/fluent-plugin-zabbix-simple
|
81
|
+
licenses: []
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 1.8.25
|
101
|
+
signing_key:
|
102
|
+
specification_version: 3
|
103
|
+
summary: Output data plugin to Zabbix (like zabbix_sender)
|
104
|
+
test_files:
|
105
|
+
- test/helper.rb
|
106
|
+
- test/plugin/test_out_zabbix_simple.rb
|