fluent-plugin-zabbix 0.0.1
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 +19 -0
- data/Gemfile +4 -0
- data/LICENSE +13 -0
- data/README.rdoc +51 -0
- data/Rakefile +12 -0
- data/fluent-plugin-zabbix.gemspec +21 -0
- data/lib/fluent/plugin/out_zabbix.rb +87 -0
- data/test/helper.rb +28 -0
- data/test/plugin/test_out_zabbix.rb +25 -0
- metadata +96 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2012 FUJIWARA Shunichiro
|
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.rdoc
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
= fluent-plugin-zabbix
|
2
|
+
|
3
|
+
== Component
|
4
|
+
|
5
|
+
=== ZabbixOutput
|
6
|
+
|
7
|
+
Plugin to output values to Zabbix server.
|
8
|
+
|
9
|
+
== Configuration
|
10
|
+
|
11
|
+
=== ZabbixOutput
|
12
|
+
|
13
|
+
Zabbix configuration of Item:
|
14
|
+
|
15
|
+
Key: metrics.field1
|
16
|
+
Type: Zabbix trapper
|
17
|
+
|
18
|
+
Key: metrics.field2
|
19
|
+
Type: Zabbix trapper
|
20
|
+
|
21
|
+
For messages such as:
|
22
|
+
tag:metrics {"metrics.field1":300, "metrics.field2":20}
|
23
|
+
|
24
|
+
<match metrics>
|
25
|
+
type zabbix
|
26
|
+
zabbix_server 192.168.0.1
|
27
|
+
port 10051
|
28
|
+
host client-hostname
|
29
|
+
name_keys metrics.field1,metrics.field2
|
30
|
+
</match>
|
31
|
+
|
32
|
+
or, use "add_keys_prefix"
|
33
|
+
tag:metrics {"field1":300, "field2":20}
|
34
|
+
|
35
|
+
<match metrics>
|
36
|
+
type zabbix
|
37
|
+
zabbix_server 192.168.0.1
|
38
|
+
port 10051
|
39
|
+
host client-hostname
|
40
|
+
add_key_prefix metrics
|
41
|
+
name_key_pattern ^field
|
42
|
+
</match>
|
43
|
+
|
44
|
+
== TODO
|
45
|
+
|
46
|
+
- patches welcome!
|
47
|
+
|
48
|
+
== Copyright
|
49
|
+
|
50
|
+
Copyright:: Copyright (c) 2012- FUJIWARA Shunichiro
|
51
|
+
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 = ["FUJIWARA Shunichiro"]
|
6
|
+
gem.email = ["fujiwara.shunichiro@gmail.com"]
|
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/fujiwara/fluent-plugin-zabbix"
|
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"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = "0.0.1"
|
17
|
+
|
18
|
+
gem.add_development_dependency "fluentd"
|
19
|
+
gem.add_runtime_dependency "fluentd"
|
20
|
+
gem.add_runtime_dependency "zabbix"
|
21
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
class Fluent::ZabbixOutput < Fluent::Output
|
2
|
+
Fluent::Plugin.register_output('zabbix', self)
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
super
|
6
|
+
require 'zabbix'
|
7
|
+
require 'socket'
|
8
|
+
end
|
9
|
+
|
10
|
+
config_param :zabbix_server, :string
|
11
|
+
config_param :port, :integer, :default => 10051
|
12
|
+
config_param :host, :string, :default => Socket.gethostname
|
13
|
+
config_param :name_keys, :string, :default => nil
|
14
|
+
config_param :name_key_pattern, :string, :default => nil
|
15
|
+
config_param :add_key_prefix, :string, :default => nil
|
16
|
+
|
17
|
+
def configure(conf)
|
18
|
+
super
|
19
|
+
|
20
|
+
if @zabbix_server.nil?
|
21
|
+
raise Fluent::ConfigError, "missing zabbix_server"
|
22
|
+
end
|
23
|
+
|
24
|
+
if @name_keys.nil? and @name_key_pattern.nil?
|
25
|
+
raise Fluent::ConfigError, "missing both of name_keys and name_key_pattern"
|
26
|
+
end
|
27
|
+
if not @name_keys.nil? and not @name_key_pattern.nil?
|
28
|
+
raise Fluent::ConfigError, "cannot specify both of name_keys and name_key_pattern"
|
29
|
+
end
|
30
|
+
if @name_keys
|
31
|
+
@name_keys = @name_keys.split(/ *, */)
|
32
|
+
end
|
33
|
+
if @name_key_pattern
|
34
|
+
@name_key_pattern = Regexp.new(@name_key_pattern)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def start
|
39
|
+
super
|
40
|
+
end
|
41
|
+
|
42
|
+
def shutdown
|
43
|
+
super
|
44
|
+
end
|
45
|
+
|
46
|
+
def send(tag, name, value, time)
|
47
|
+
if @add_key_prefix
|
48
|
+
name = "#{@add_key_prefix}.#{name}"
|
49
|
+
end
|
50
|
+
begin
|
51
|
+
zbx = Zabbix::Sender.new(:host => @zabbix_server, :port => @port)
|
52
|
+
$log.debug("zabbix: #{zbx}, #{name}: #{value}, host: #{@host}, ts: #{time}")
|
53
|
+
|
54
|
+
opts = { :host => @host, :ts => time }
|
55
|
+
status = zbx.send_data(name, value.to_s, opts)
|
56
|
+
|
57
|
+
rescue IOError, EOFError, SystemCallError
|
58
|
+
# server didn't respond
|
59
|
+
$log.warn "Zabbix::Sender.send_data raises exception: #{$!.class}, '#{$!.message}'"
|
60
|
+
status = false
|
61
|
+
end
|
62
|
+
unless status
|
63
|
+
$log.warn "failed to send to zabbix_server: #{@zabbix_server}:#{@port}, host:#{@host} '#{name}': #{value}"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def emit(tag, es, chain)
|
68
|
+
if @name_keys
|
69
|
+
es.each {|time,record|
|
70
|
+
@name_keys.each {|name|
|
71
|
+
if record[name]
|
72
|
+
send(tag, name, record[name], time)
|
73
|
+
end
|
74
|
+
}
|
75
|
+
}
|
76
|
+
else # for name_key_pattern
|
77
|
+
es.each {|time,record|
|
78
|
+
record.keys.each {|key|
|
79
|
+
if @name_key_pattern.match(key) and record[key]
|
80
|
+
send(tag, key, record[key], time)
|
81
|
+
end
|
82
|
+
}
|
83
|
+
}
|
84
|
+
end
|
85
|
+
chain.next
|
86
|
+
end
|
87
|
+
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'
|
26
|
+
|
27
|
+
class Test::Unit::TestCase
|
28
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class ZabbixOutputTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
Fluent::Test.setup
|
6
|
+
end
|
7
|
+
|
8
|
+
CONFIG = %[
|
9
|
+
zabbix_server 127.0.0.1
|
10
|
+
host clienthost
|
11
|
+
add_key_prefix test
|
12
|
+
name_keys foo, bar, baz
|
13
|
+
]
|
14
|
+
|
15
|
+
def create_driver(conf = CONFIG, tag='test')
|
16
|
+
Fluent::Test::OutputTestDriver.new(Fluent::ZabbixOutput, tag).configure(conf)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_write
|
20
|
+
# d = create_driver
|
21
|
+
# d.emit({"foo" => "test value of foo"})
|
22
|
+
# d.emit({"bar" => "test value of bar"})
|
23
|
+
# d.emit({"baz" => rand * 10 })
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-zabbix
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- FUJIWARA Shunichiro
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2012-04-17 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: fluentd
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :development
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: fluentd
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "0"
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: zabbix
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id003
|
48
|
+
description: Output data plugin to Zabbix
|
49
|
+
email:
|
50
|
+
- fujiwara.shunichiro@gmail.com
|
51
|
+
executables: []
|
52
|
+
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files: []
|
56
|
+
|
57
|
+
files:
|
58
|
+
- .gitignore
|
59
|
+
- Gemfile
|
60
|
+
- LICENSE
|
61
|
+
- README.rdoc
|
62
|
+
- Rakefile
|
63
|
+
- fluent-plugin-zabbix.gemspec
|
64
|
+
- lib/fluent/plugin/out_zabbix.rb
|
65
|
+
- test/helper.rb
|
66
|
+
- test/plugin/test_out_zabbix.rb
|
67
|
+
homepage: https://github.com/fujiwara/fluent-plugin-zabbix
|
68
|
+
licenses: []
|
69
|
+
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: "0"
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: "0"
|
87
|
+
requirements: []
|
88
|
+
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 1.8.11
|
91
|
+
signing_key:
|
92
|
+
specification_version: 3
|
93
|
+
summary: Output data plugin to Zabbix (like zabbix_sender)
|
94
|
+
test_files:
|
95
|
+
- test/helper.rb
|
96
|
+
- test/plugin/test_out_zabbix.rb
|