fluent-plugin-zabbix-agent 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 95b4a81abb2b8f9c15ead559177ffb99af51bee5
4
+ data.tar.gz: 3ff836e8e4f56e616c77824871a3f04232bae5b7
5
+ SHA512:
6
+ metadata.gz: 8c93b0599c818262bbe41605d4d5d6d466dbc2757bee0e11b58e7057e89ecaf31136cf1695ee65f983f36171e7162c003a82abfd9ba7d32b5e9407b99ead5703
7
+ data.tar.gz: d8694cd8bf37d8301d5279a485ce63927264b576189452d9868b2f9720bca4afe9f732cc03bd2a8dbef387fb195aa3497d8c473a0907956c1e6173c1495d660b
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ test.rb
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --require spec_helper
2
+ --colour
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1
5
+ - 2.2
6
+ script:
7
+ - bundle install
8
+ - bundle exec rake
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-zabbix-agent.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,86 @@
1
+ # fluent-plugin-zabbix-agent
2
+
3
+ Fluentd input plugin for Zabbix agent.
4
+
5
+ It gets items of zabbix using [passive check](https://www.zabbix.com/documentation/2.4/manual/appendix/items/activepassive#passive_checks).
6
+
7
+ [![Gem Version](https://badge.fury.io/rb/fluent-plugin-zabbix-agent.svg)](http://badge.fury.io/rb/fluent-plugin-zabbix-agent)
8
+ [![Build Status](https://travis-ci.org/winebarrel/fluent-plugin-zabbix-agent.svg)](https://travis-ci.org/winebarrel/fluent-plugin-zabbix-agent)
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'fluent-plugin-zabbix-agent'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install fluent-plugin-zabbix-agent
25
+
26
+ ## Configuration
27
+
28
+ ```apache
29
+ <source>
30
+ type zabbix_agent
31
+
32
+ #agent_host 127.0.0.1
33
+ #agent_port 10050
34
+ #interval 60
35
+ #tag zabbix.item
36
+ #extra {}
37
+ #bulk false
38
+
39
+ items {
40
+ "system.cpu.load[all,avg1]": "load_avg1",
41
+ "system.cpu.load[all,avg5]": "load_avg5",
42
+ ...
43
+ }
44
+ </source>
45
+
46
+ ```
47
+
48
+ ## Usage
49
+
50
+ ### Get zabbix items as multiple records
51
+
52
+ ```apache
53
+ <source>
54
+ type zabbix_agent
55
+ extra {"hostname", "my-host"}
56
+ items {
57
+ "system.cpu.load[all,avg1]": "load_avg1",
58
+ "system.cpu.load[all,avg5]": null
59
+ }
60
+ </source>
61
+
62
+ ```
63
+
64
+ ```
65
+ 2015-01-02 12:30:40 +0000 zabbix.item: {"load_avg1":0.0,"hostname":"my-host"}
66
+ 2015-01-02 12:30:40 +0000 zabbix.item: {"system.cpu.load[all,avg5]":0.01,"hostname":"my-host"}
67
+ ```
68
+
69
+ ## Get zabbix items as a single record
70
+
71
+ ```apache
72
+ <source>
73
+ type zabbix_agent
74
+ extra {"hostname", "my-host"}
75
+ bulk true
76
+ items {
77
+ "system.cpu.load[all,avg1]": "load_avg1",
78
+ "system.cpu.load[all,avg5]": null
79
+ }
80
+ </source>
81
+
82
+ ```
83
+
84
+ ```
85
+ 2015-01-02 12:30:40 +0000 zabbix.item: {"load_avg1":0.06,"system.cpu.load[all,avg5]":0.03,"hostname":"my-server"}
86
+ ```
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "fluent/plugin/zabbix/agent"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fluent_plugin_zabbix_agent/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'fluent-plugin-zabbix-agent'
8
+ spec.version = FluentPluginZabbixAgent::VERSION
9
+ spec.authors = ['Genki Sugawara']
10
+ spec.email = ['sugawara@cookpad.com']
11
+
12
+ spec.summary = %q{Fluentd input plugin for Zabbix agent.}
13
+ spec.description = %q{Fluentd input plugin for Zabbix agent.}
14
+ spec.homepage = 'https://github.com/winebarrel/fluent-plugin-zabbix-agent'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_dependency 'fluentd'
23
+ spec.add_dependency 'zabbix_protocol'
24
+ spec.add_development_dependency 'bundler'
25
+ spec.add_development_dependency 'rake'
26
+ spec.add_development_dependency 'rspec', '>= 3.0.0'
27
+ spec.add_development_dependency 'test-unit', '>= 3.1.0'
28
+ spec.add_development_dependency 'timecop'
29
+ end
@@ -0,0 +1,128 @@
1
+ require 'fluent_plugin_zabbix_agent/version'
2
+
3
+ class Fluent::ZabbixAgentInput < Fluent::Input
4
+ Fluent::Plugin.register_input('zabbix_agent', self)
5
+
6
+ unless method_defined?(:log)
7
+ define_method('log') { $log }
8
+ end
9
+
10
+ unless method_defined?(:router)
11
+ define_method('router') { Fluent::Engine }
12
+ end
13
+
14
+ def initialize
15
+ super
16
+ require 'csv'
17
+ require 'fileutils'
18
+ require 'logger'
19
+ require 'time'
20
+ require 'addressable/uri'
21
+ require 'aws-sdk'
22
+ end
23
+
24
+ config_param :agent_host, :string, :default => '127.0.0.1'
25
+ config_param :agent_port, :integer, :default => 10050
26
+ config_param :interval, :time, :default => 60
27
+ config_param :tag, :string, :default => 'zabbix.item'
28
+ config_param :items, :hash
29
+ config_param :extra, :hash, :default => {}
30
+ config_param :bulk, :bool, :default => false
31
+
32
+ def initialize
33
+ super
34
+ require 'socket'
35
+ require 'zabbix_protocol'
36
+ end
37
+
38
+ def configure(conf)
39
+ super
40
+
41
+ @items.keys.each do |key|
42
+ value = @items[key]
43
+ @items[key] = key if value.nil?
44
+ end
45
+ end
46
+
47
+ def start
48
+ super
49
+
50
+ @loop = Coolio::Loop.new
51
+ timer = TimerWatcher.new(@interval, true, log, &method(:fetch_items))
52
+ @loop.attach(timer)
53
+ @thread = Thread.new(&method(:run))
54
+ end
55
+
56
+ def shutdown
57
+ @loop.watchers.each(&:detach)
58
+ @loop.stop
59
+
60
+ # XXX: Comment out for exit soon. Is it OK?
61
+ #@thread.join
62
+ end
63
+
64
+ private
65
+
66
+ def run
67
+ @loop.run
68
+ rescue => e
69
+ log.error(e.message)
70
+ log.error_backtrace(e.backtrace)
71
+ end
72
+
73
+ def fetch_items
74
+ value_by_item = {}
75
+
76
+ @items.each do |key, record_key|
77
+ value = zabbix_get(key)
78
+ value_by_item[record_key] = value
79
+ end
80
+
81
+ emit_items(value_by_item)
82
+ end
83
+
84
+ def zabbix_get(key)
85
+ value = nil
86
+
87
+ TCPSocket.open(@agent_host, @agent_port) do |sock|
88
+ sock.setsockopt(Socket::SOL_SOCKET,Socket::SO_REUSEADDR, true)
89
+ sock.write ZabbixProtocol.dump(key + "\n")
90
+ sock.close_write
91
+ value = ZabbixProtocol.load(sock.read)
92
+ end
93
+
94
+ value
95
+ end
96
+
97
+ def emit_items(value_by_item)
98
+ time = Time.now
99
+
100
+ records = value_by_item.map do |key, value|
101
+ {key => value}
102
+ end
103
+
104
+ if @bulk
105
+ bulk_record = records.inject({}) {|r, i| r.merge(i) }
106
+ router.emit(@tag, time.to_i, bulk_record.merge(extra))
107
+ else
108
+ records.each do |rcrd|
109
+ router.emit(@tag, time.to_i, rcrd.merge(extra))
110
+ end
111
+ end
112
+ end
113
+
114
+ class TimerWatcher < Coolio::TimerWatcher
115
+ def initialize(interval, repeat, log, &callback)
116
+ @callback = callback
117
+ @log = log
118
+ super(interval, repeat)
119
+ end
120
+
121
+ def on_timer
122
+ @callback.call
123
+ rescue => e
124
+ @log.error(e.message)
125
+ @log.error_backtrace(e.backtrace)
126
+ end
127
+ end # TimerWatcher
128
+ end # Fluent::ZabbixAgentInput
@@ -0,0 +1,3 @@
1
+ module FluentPluginZabbixAgent
2
+ VERSION = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,154 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-zabbix-agent
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Genki Sugawara
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-09-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fluentd
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: zabbix_protocol
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: 3.0.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: 3.0.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: test-unit
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: 3.1.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: 3.1.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: timecop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Fluentd input plugin for Zabbix agent.
112
+ email:
113
+ - sugawara@cookpad.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - .rspec
120
+ - .travis.yml
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - bin/console
126
+ - bin/setup
127
+ - fluent-plugin-zabbix-agent.gemspec
128
+ - lib/fluent/plugin/in_zabbix_agent.rb
129
+ - lib/fluent_plugin_zabbix_agent/version.rb
130
+ homepage: https://github.com/winebarrel/fluent-plugin-zabbix-agent
131
+ licenses:
132
+ - MIT
133
+ metadata: {}
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubyforge_project:
150
+ rubygems_version: 2.0.14
151
+ signing_key:
152
+ specification_version: 4
153
+ summary: Fluentd input plugin for Zabbix agent.
154
+ test_files: []