zabbix-ruby-client 0.0.4
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.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +83 -0
- data/Rakefile +20 -0
- data/bin/zrc +7 -0
- data/lib/zabbix-ruby-client/cli.rb +47 -0
- data/lib/zabbix-ruby-client/logger.rb +29 -0
- data/lib/zabbix-ruby-client/plugins/apache.rb +76 -0
- data/lib/zabbix-ruby-client/plugins/cpu.rb +33 -0
- data/lib/zabbix-ruby-client/plugins/disk.rb +38 -0
- data/lib/zabbix-ruby-client/plugins/memory.rb +41 -0
- data/lib/zabbix-ruby-client/plugins/network.rb +34 -0
- data/lib/zabbix-ruby-client/plugins.rb +38 -0
- data/lib/zabbix-ruby-client/version.rb +3 -0
- data/lib/zabbix-ruby-client.rb +96 -0
- data/spec/files/config.yml +21 -0
- data/spec/files/plugins/apache_status +9 -0
- data/spec/files/plugins/iostat_disk +1 -0
- data/spec/files/plugins/mpstat +1 -0
- data/spec/files/plugins/netstat +1 -0
- data/spec/files/plugins/vmstat +10 -0
- data/spec/lib/cli_spec.rb +13 -0
- data/spec/lib/logger_spec.rb +12 -0
- data/spec/lib/plugins/apache_spec.rb +14 -0
- data/spec/lib/plugins/cpu_spec.rb +12 -0
- data/spec/lib/plugins/disk_spec.rb +12 -0
- data/spec/lib/plugins/memory_spec.rb +13 -0
- data/spec/lib/plugins/network_spec.rb +12 -0
- data/spec/lib/plugins_spec.rb +12 -0
- data/spec/lib/zabbix-ruby-client_spec.rb +16 -0
- data/spec/spec_helper.rb +10 -0
- data/templates/client/Gemfile +3 -0
- data/templates/client/config.yml +21 -0
- data/zabbix-ruby-client.gemspec +26 -0
- metadata +153 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ae8f13fc1c1b84c142d4432d77488bca0a1dc636
|
4
|
+
data.tar.gz: 072c530a783ffecfa4e5ca9d1c136d0cb25f501a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 316f2d46459245faf628b6a22390818e7e0da8e2517e98d0ac34bd6e095a10579dde14dda1765e493272ef3ba5b9f0ea1b1b17b6f48b5483b333236361c266a6
|
7
|
+
data.tar.gz: 6d0a78c36ce93d537e58372df8ae25f921252d002f62e87ce592560bd5e801936c2c95a1b8e62ed02af8dfd0456ac172b1f43556cdbeb0ecb9782d5fc5475884
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Faria Systems, mose
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
Zabbix Ruby Client
|
2
|
+
====================
|
3
|
+
|
4
|
+
[](https://codeclimate.com/github/eduvo/zabbix-ruby-client)
|
5
|
+
|
6
|
+
This tool is designed to make easy to install zabbix reporter on monitored servers using zabbix-sender rather than zabbix-agent. It targets on monitoring mainly linux servers and is built on a plugin system so that you can decide what is going to be reported.
|
7
|
+
|
8
|
+
The development is still in progress but it produces results and works in my case. Use at your own risk and read the code first. It is developed under ruby 2 but should work on 1.9.3 as well.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Install it yourself as:
|
13
|
+
|
14
|
+
gem install zabbix-ruby-client
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
zrc init [name]
|
19
|
+
# will create a directory [name] (default: zabbix-ruby-client) for
|
20
|
+
# storing configuration and temporary files
|
21
|
+
|
22
|
+
cd [name]
|
23
|
+
bundle
|
24
|
+
# makes the zabbix-ruby-client [name] ready to run
|
25
|
+
# then edit config.yml according to your needs
|
26
|
+
|
27
|
+
zrc
|
28
|
+
# to list available commands
|
29
|
+
|
30
|
+
And when ready just install a cron task according to your environment
|
31
|
+
|
32
|
+
echo '* * * * * /bin/bash -lc "cd /path/to/zrc && bundle exec zrc go"' | crontab
|
33
|
+
# or
|
34
|
+
echo '* * * * * /bin/zsh -c ". $HOME/.rvm/scripts/rvm && cd /path/to/zrc && bundle exec zrc go"' | crontab
|
35
|
+
# or
|
36
|
+
echo '* * * * * /bin/zsh -c "export RBENV_ROOT=/usr/local/var/rbenv && eval \"$(rbenv init - zsh)\" && cd /path/to/zrc && bundle exec zrc go"' | crontab
|
37
|
+
|
38
|
+
## plugins
|
39
|
+
|
40
|
+
There are a set of standart plugins included in the package, aimed at linux systems.
|
41
|
+
|
42
|
+
* cpu (requires mpstat, apt-get install sysstat)
|
43
|
+
* memory (requires iostat, apt-get install sysstat)
|
44
|
+
* disk (requires iostat, apt-get install sysstat)
|
45
|
+
* network (requires netstat, apt-get install netstat)
|
46
|
+
* apache (depends on mod_status with status_extended on)
|
47
|
+
|
48
|
+
You can add extra plugin directories in the configuration file.
|
49
|
+
|
50
|
+
## Todo
|
51
|
+
|
52
|
+
* write tests
|
53
|
+
* add more plugins
|
54
|
+
* memcache
|
55
|
+
* redis
|
56
|
+
* mysql master/slave
|
57
|
+
* monit
|
58
|
+
* passenger
|
59
|
+
* nginx
|
60
|
+
* logged users
|
61
|
+
* denyhosts
|
62
|
+
* postfix
|
63
|
+
* sendgrid
|
64
|
+
* airbrake
|
65
|
+
* disk occupation
|
66
|
+
* try to work out a way to create host/graphs/alerts from the client using Zabbix API
|
67
|
+
* verify compatibility with ruby 1.9
|
68
|
+
|
69
|
+
## Contributing
|
70
|
+
|
71
|
+
1. Fork it
|
72
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
73
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
74
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
75
|
+
5. Create new Pull Request
|
76
|
+
|
77
|
+
## Contributors
|
78
|
+
|
79
|
+
* [@mose](https://github.com/mose) - author
|
80
|
+
|
81
|
+
## License
|
82
|
+
|
83
|
+
Copyright 2013 [Faria Systems](http://faria.co) - MIT license - created by mose at mose.com
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
require 'bundler/setup'
|
8
|
+
require "bundler/gem_tasks"
|
9
|
+
require "rake/testtask"
|
10
|
+
require "rspec/core/rake_task" # RSpec 2.0
|
11
|
+
|
12
|
+
desc "launch rspec tests"
|
13
|
+
task :spec do
|
14
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
15
|
+
t.rspec_opts = ["-c", "-f progress", "-r ./spec/spec_helper.rb"]
|
16
|
+
t.pattern = 'spec/lib/**/*_spec.rb'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
task :default => :spec
|
data/bin/zrc
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require "thor"
|
2
|
+
require "zabbix-ruby-client"
|
3
|
+
|
4
|
+
class ZabbixRubyClient
|
5
|
+
|
6
|
+
class Cli < Thor
|
7
|
+
include Thor::Actions
|
8
|
+
|
9
|
+
def self.source_root
|
10
|
+
File.expand_path("../../../templates", __FILE__)
|
11
|
+
end
|
12
|
+
|
13
|
+
default_task :help
|
14
|
+
class_option :configfile,
|
15
|
+
aliases: "-c",
|
16
|
+
banner: "PATH",
|
17
|
+
default: File.expand_path("config.yml", Dir.pwd),
|
18
|
+
desc: "Path to the configuration file to use"
|
19
|
+
|
20
|
+
desc "init", "Initialize a new zabbix ruby client"
|
21
|
+
def init(name = "zabbix-ruby-client")
|
22
|
+
directory "client", name
|
23
|
+
end
|
24
|
+
|
25
|
+
desc "show", "Displays in console what are the collected data ready to be sent"
|
26
|
+
def show
|
27
|
+
begin
|
28
|
+
Bundler.require
|
29
|
+
rescue Bundler::GemfileNotFound
|
30
|
+
say "No Gemfile found", :red
|
31
|
+
abort
|
32
|
+
end
|
33
|
+
zrc = ZabbixRubyClient.new(options[:configfile])
|
34
|
+
zrc.collect
|
35
|
+
zrc.show
|
36
|
+
end
|
37
|
+
|
38
|
+
desc "upload", "Collects and sends data to the zabbix server"
|
39
|
+
def upload
|
40
|
+
zrc = ZabbixRubyClient.new(options[:configfile])
|
41
|
+
zrc.collect
|
42
|
+
zrc.upload
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "logger"
|
2
|
+
|
3
|
+
class ZabbixRubyClient
|
4
|
+
module Logger
|
5
|
+
extend self
|
6
|
+
|
7
|
+
def get_logger(dir, level)
|
8
|
+
logger = ::Logger.new(File.join(dir,"zrc.log"))
|
9
|
+
logger.level = get_level_constant(level)
|
10
|
+
logger.formatter = proc do |severity, datetime, progname, msg|
|
11
|
+
"[#{datetime.utc}] #{severity}: #{msg}\n"
|
12
|
+
end
|
13
|
+
logger
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_level_constant(level)
|
17
|
+
if level
|
18
|
+
begin
|
19
|
+
::Logger.const_get(level.to_s.upcase)
|
20
|
+
rescue NameError
|
21
|
+
return ::Logger::INFO
|
22
|
+
end
|
23
|
+
else
|
24
|
+
::Logger::INFO
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require "open-uri"
|
2
|
+
|
3
|
+
class ZabbixRubyClient
|
4
|
+
module Plugins
|
5
|
+
module Apache
|
6
|
+
extend self
|
7
|
+
|
8
|
+
def collect(*args)
|
9
|
+
host = args[0]
|
10
|
+
ret = get_status
|
11
|
+
ret['Score'] = get_scores(ret["Scoreboard"])
|
12
|
+
ret.delete "Scoreboard"
|
13
|
+
|
14
|
+
back = []
|
15
|
+
back << "#{host} apache[TotalAccesses] #{ret["Total Accesses"]}"
|
16
|
+
back << "#{host} apache[TotalKBytes] #{ret["Total kBytes"]}"
|
17
|
+
back << "#{host} apache[CPULoad] #{ret["CPULoad"].to_f}"
|
18
|
+
back << "#{host} apache[Uptime] #{ret["Uptime"]}"
|
19
|
+
back << "#{host} apache[ReqPerSec] #{ret["ReqPerSec"].to_f}"
|
20
|
+
back << "#{host} apache[BytesPerSec] #{ret["BytesPerSec"]}"
|
21
|
+
back << "#{host} apache[BytesPerReq] #{ret["BytesPerReq"]}"
|
22
|
+
back << "#{host} apache[BusyWorkers] #{ret["BusyWorkers"]}"
|
23
|
+
back << "#{host} apache[IdleWorkers] #{ret["IdleWorkers"]}"
|
24
|
+
back << "#{host} apache[c_idle] #{ret["Score"]["."]}"
|
25
|
+
back << "#{host} apache[c_waiting] #{ret["Score"]["_"]}"
|
26
|
+
back << "#{host} apache[c_closing] #{ret["Score"]["C"]}"
|
27
|
+
back << "#{host} apache[c_dns] #{ret["Score"]["D"]}"
|
28
|
+
back << "#{host} apache[c_finish] #{ret["Score"]["G"]}"
|
29
|
+
back << "#{host} apache[c_cleanup] #{ret["Score"]["I"]}"
|
30
|
+
back << "#{host} apache[c_keep] #{ret["Score"]["K"]}"
|
31
|
+
back << "#{host} apache[c_log] #{ret["Score"]["L"]}"
|
32
|
+
back << "#{host} apache[c_read] #{ret["Score"]["R"]}"
|
33
|
+
back << "#{host} apache[c_send] #{ret["Score"]["W"]}"
|
34
|
+
back << "#{host} apache[c_start] #{ret["Score"]["S"]}"
|
35
|
+
|
36
|
+
return back
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def get_scores(board)
|
42
|
+
back = {
|
43
|
+
"_" => 0,
|
44
|
+
"S" => 0,
|
45
|
+
"R" => 0,
|
46
|
+
"W" => 0,
|
47
|
+
"K" => 0,
|
48
|
+
"D" => 0,
|
49
|
+
"C" => 0,
|
50
|
+
"L" => 0,
|
51
|
+
"G" => 0,
|
52
|
+
"I" => 0,
|
53
|
+
"." => 0
|
54
|
+
}
|
55
|
+
board.split("").each do |x|
|
56
|
+
back[x] += 1
|
57
|
+
end
|
58
|
+
return back
|
59
|
+
end
|
60
|
+
|
61
|
+
def get_status
|
62
|
+
ret = {}
|
63
|
+
open "http://127.0.0.1:80/server-status?auto" do |f|
|
64
|
+
f.each_line do |l|
|
65
|
+
k, v = l.split ":"
|
66
|
+
ret[k] = v.strip
|
67
|
+
end
|
68
|
+
end
|
69
|
+
ret
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
ZabbixRubyClient::Plugins.register('apache', ZabbixRubyClient::Plugins::Apache)
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class ZabbixRubyClient
|
2
|
+
module Plugins
|
3
|
+
module Cpu
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def collect(*args)
|
7
|
+
host = args[0]
|
8
|
+
cpuinfo = `mpstat | grep " all "`
|
9
|
+
if $?.to_i == 0
|
10
|
+
_, _, _, user, nice, sys, wait, irq, soft, steal, guest, idle = cpuinfo.split(/\s+/)
|
11
|
+
else
|
12
|
+
logger.warn "Please install sysstat."
|
13
|
+
return []
|
14
|
+
end
|
15
|
+
back = []
|
16
|
+
back << "#{host} cpu[user] #{user}"
|
17
|
+
back << "#{host} cpu[nice] #{nice}"
|
18
|
+
back << "#{host} cpu[system] #{sys}"
|
19
|
+
back << "#{host} cpu[iowait] #{wait}"
|
20
|
+
back << "#{host} cpu[irq] #{irq}"
|
21
|
+
back << "#{host} cpu[soft] #{soft}"
|
22
|
+
back << "#{host} cpu[steal] #{steal}"
|
23
|
+
back << "#{host} cpu[guest] #{guest}"
|
24
|
+
back << "#{host} cpu[idle] #{idle}"
|
25
|
+
return back
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
ZabbixRubyClient::Plugins.register('cpu', ZabbixRubyClient::Plugins::Cpu)
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class ZabbixRubyClient
|
2
|
+
module Plugins
|
3
|
+
module Disk
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def collect(*args)
|
7
|
+
host = args[0]
|
8
|
+
dev = args[1]
|
9
|
+
diskinfo = `iostat -dx #{dev} | grep "^#{dev}"`
|
10
|
+
if $?.to_i == 0
|
11
|
+
_, rrqm, wrqm, r, w, rkb, wkb, avgrq, avgqu, await, rawait, wawait, svctm, util = diskinfo.split(/\s+/)
|
12
|
+
else
|
13
|
+
logger.warn "Please install sysstat."
|
14
|
+
return []
|
15
|
+
end
|
16
|
+
back = []
|
17
|
+
back << "#{host} disk[#{dev},read_req_per_sec] #{rrqm}"
|
18
|
+
back << "#{host} disk[#{dev},write_req_per_sec] #{wrqm}"
|
19
|
+
back << "#{host} disk[#{dev},read_per_sec] #{r}"
|
20
|
+
back << "#{host} disk[#{dev},write_per_sec] #{w}"
|
21
|
+
back << "#{host} disk[#{dev},read_sector_per_sec] #{rkb}"
|
22
|
+
back << "#{host} disk[#{dev},write_sector_per_sec] #{wkb}"
|
23
|
+
back << "#{host} disk[#{dev},avg_sector_size] #{avgrq}"
|
24
|
+
back << "#{host} disk[#{dev},avg_queue_length] #{avgqu}"
|
25
|
+
back << "#{host} disk[#{dev},time_waiting] #{await}"
|
26
|
+
back << "#{host} disk[#{dev},time_waiting_read] #{rawait}"
|
27
|
+
back << "#{host} disk[#{dev},time_waiting_write] #{wawait}"
|
28
|
+
back << "#{host} disk[#{dev},service_time] #{svctm}"
|
29
|
+
back << "#{host} disk[#{dev},percent_util] #{util}"
|
30
|
+
return back
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
ZabbixRubyClient::Plugins.register('disk', ZabbixRubyClient::Plugins::Disk)
|
@@ -0,0 +1,41 @@
|
|
1
|
+
class ZabbixRubyClient
|
2
|
+
module Plugins
|
3
|
+
module Memory
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def collect(*args)
|
7
|
+
host = args[0]
|
8
|
+
meminfo = `vmstat -s | head -10`
|
9
|
+
if $?.to_i == 0
|
10
|
+
info = splitinfo(meminfo)
|
11
|
+
else
|
12
|
+
logger.warn "Please install sysstat."
|
13
|
+
return []
|
14
|
+
end
|
15
|
+
back = []
|
16
|
+
back << "#{host} memory[total] #{info["totalmemory"]}"
|
17
|
+
back << "#{host} memory[used] #{info["usedmemory"]}"
|
18
|
+
back << "#{host} memory[active] #{info["activememory"]}"
|
19
|
+
back << "#{host} memory[inactive] #{info["inactivememory"]}"
|
20
|
+
back << "#{host} memory[free] #{info["freememory"]}"
|
21
|
+
back << "#{host} memory[buffer] #{info["buffermemory"]}"
|
22
|
+
back << "#{host} memory[swap_cache] #{info["swapcache"]}"
|
23
|
+
back << "#{host} memory[swap_total] #{info["totalswap"]}"
|
24
|
+
back << "#{host} memory[swap_used] #{info["usedswap"]}"
|
25
|
+
back << "#{host} memory[swap_free] #{info["freeswap"]}"
|
26
|
+
return back
|
27
|
+
end
|
28
|
+
|
29
|
+
def splitinfo(info)
|
30
|
+
info.split(/\n/).map(&:strip).reduce({}) do |a,line|
|
31
|
+
kb, _, label1, label2 = line.split(" ")
|
32
|
+
a[label1+label2] = kb
|
33
|
+
a
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
ZabbixRubyClient::Plugins.register('memory', ZabbixRubyClient::Plugins::Memory)
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class ZabbixRubyClient
|
2
|
+
module Plugins
|
3
|
+
module Network
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def collect(*args)
|
7
|
+
host = args[0]
|
8
|
+
interface = args[1]
|
9
|
+
netinfo = `netstat -i | grep "^#{interface} "`
|
10
|
+
if $?.to_i == 0
|
11
|
+
_, mtu, rx_ok, rx_err, rx_drop, rx_over, tx_ok, tx_err, tx_drop, tx_over, flags = netinfo.split(/\s+/)
|
12
|
+
else
|
13
|
+
logger.warn "Please install netstat."
|
14
|
+
return []
|
15
|
+
end
|
16
|
+
back = []
|
17
|
+
back << "#{host} net[#{interface},mtu] #{mtu}"
|
18
|
+
back << "#{host} net[#{interface},rx_ok] #{rx_ok}"
|
19
|
+
back << "#{host} net[#{interface},rx_err] #{rx_err}"
|
20
|
+
back << "#{host} net[#{interface},rx_drop] #{rx_drop}"
|
21
|
+
back << "#{host} net[#{interface},rx_over] #{rx_over}"
|
22
|
+
back << "#{host} net[#{interface},tx_ok] #{tx_ok}"
|
23
|
+
back << "#{host} net[#{interface},tx_err] #{tx_err}"
|
24
|
+
back << "#{host} net[#{interface},tx_drop] #{tx_drop}"
|
25
|
+
back << "#{host} net[#{interface},tx_over] #{tx_over}"
|
26
|
+
return back
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
ZabbixRubyClient::Plugins.register('network', ZabbixRubyClient::Plugins::Network)
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class ZabbixRubyClient
|
2
|
+
module Plugins
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def load_dirs(dirs)
|
6
|
+
@available = {}
|
7
|
+
@loaded = {}
|
8
|
+
dirs.each do |d|
|
9
|
+
Dir.glob(File.join(d,"*.rb")).reduce(@available) { |a,x|
|
10
|
+
name = File.basename(x,".rb")
|
11
|
+
a[name] = x
|
12
|
+
a
|
13
|
+
}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def register(plugin, klass)
|
18
|
+
@loaded[plugin] = klass
|
19
|
+
end
|
20
|
+
|
21
|
+
def loaded
|
22
|
+
@loaded ||= {}
|
23
|
+
end
|
24
|
+
|
25
|
+
def load(plugin)
|
26
|
+
if @loaded[plugin]
|
27
|
+
true
|
28
|
+
else
|
29
|
+
if @available[plugin]
|
30
|
+
ZabbixRubyClient.send :load, @available[plugin]
|
31
|
+
else
|
32
|
+
nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require "zabbix-ruby-client/version"
|
2
|
+
require "zabbix-ruby-client/logger"
|
3
|
+
require "zabbix-ruby-client/plugins"
|
4
|
+
require "yaml"
|
5
|
+
|
6
|
+
class ZabbixRubyClient
|
7
|
+
|
8
|
+
def initialize(config_file)
|
9
|
+
begin
|
10
|
+
@config ||= YAML::load_file(config_file)
|
11
|
+
rescue Exception => e
|
12
|
+
puts "Configuration file cannot be read"
|
13
|
+
puts e.message
|
14
|
+
return
|
15
|
+
end
|
16
|
+
@logsdir = makedir(@config['logsdir'],'logs')
|
17
|
+
@datadir = makedir(@config['datadir'],'data')
|
18
|
+
@plugindirs = [ File.expand_path("../zabbix-ruby-client/plugins", __FILE__) ]
|
19
|
+
if @config["plugindirs"]
|
20
|
+
@plugindirs = @plugindirs + @config["plugindirs"]
|
21
|
+
end
|
22
|
+
Plugins.load_dirs @plugindirs
|
23
|
+
logger.debug @config.inspect
|
24
|
+
end
|
25
|
+
|
26
|
+
def data
|
27
|
+
@data ||= []
|
28
|
+
end
|
29
|
+
|
30
|
+
def datafile
|
31
|
+
now = Time.now
|
32
|
+
@datafile ||= if @config['keepdata']
|
33
|
+
unless Dir.exists? File.join(@datadir,Time.now.strftime("%Y-%m-%d"))
|
34
|
+
FileUtils.mkdir File.join(@datadir,Time.now.strftime("%Y-%m-%d"))
|
35
|
+
end
|
36
|
+
File.join(@datadir,Time.now.strftime("%Y-%m-%d"),"data_"+Time.now.strftime("%H%M%S"))
|
37
|
+
else
|
38
|
+
File.join(@datadir,"data")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def run_plugin(plugin, args = nil)
|
43
|
+
Plugins.load(plugin) || logger.error( "Plugin #{plugin} not found.")
|
44
|
+
if Plugins.loaded[plugin]
|
45
|
+
begin
|
46
|
+
@data = data + Plugins.loaded[plugin].send(:collect, @config['host'], args)
|
47
|
+
rescue Exception => e
|
48
|
+
logger.fatal "Oops"
|
49
|
+
logger.fatal e.message
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def collect
|
55
|
+
@config['plugins'].each do |plugin|
|
56
|
+
run_plugin(plugin['name'], plugin['args'])
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def show
|
61
|
+
data.each do |line|
|
62
|
+
puts line
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def store
|
67
|
+
File.open(datafile, "w") do |f|
|
68
|
+
data.each do |d|
|
69
|
+
f.puts d
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def upload
|
75
|
+
store
|
76
|
+
begin
|
77
|
+
res = `#{@config['zabbix']['sender']} -z #{@config['zabbix']['host']} -i #{datafile}`
|
78
|
+
rescue Exception => e
|
79
|
+
logger.error "Sending failed."
|
80
|
+
logger.error e.message
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def makedir(configdir, defaultdir)
|
87
|
+
dir = configdir || defaultdir
|
88
|
+
FileUtils.mkdir dir unless Dir.exists? dir
|
89
|
+
dir
|
90
|
+
end
|
91
|
+
|
92
|
+
def logger
|
93
|
+
@logger ||= Logger.get_logger(@logsdir, @config["loglevel"])
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
---
|
2
|
+
host: localhost
|
3
|
+
logsdir: logs
|
4
|
+
loglevel: info
|
5
|
+
datadir: data
|
6
|
+
keepdata: no # or yes
|
7
|
+
plugindirs:
|
8
|
+
- plugins
|
9
|
+
zabbix:
|
10
|
+
host: zabbix.example.com
|
11
|
+
port: 10051
|
12
|
+
sender: /usr/bin/zabbix_sender
|
13
|
+
plugins:
|
14
|
+
- name: memory
|
15
|
+
- name: cpu
|
16
|
+
- name: network
|
17
|
+
args: eth0
|
18
|
+
- name: disk
|
19
|
+
args: sda1
|
20
|
+
- name: network
|
21
|
+
args: eth0
|
@@ -0,0 +1,9 @@
|
|
1
|
+
Total Accesses: 12
|
2
|
+
Total kBytes: 6
|
3
|
+
Uptime: 602766
|
4
|
+
ReqPerSec: 1.99082e-5
|
5
|
+
BytesPerSec: .010193
|
6
|
+
BytesPerReq: 512
|
7
|
+
BusyWorkers: 1
|
8
|
+
IdleWorkers: 9
|
9
|
+
Scoreboard: _____W____......................................................................................................................................................................................................................................................
|
@@ -0,0 +1 @@
|
|
1
|
+
sda 2.42 4.16 2.26 5.96 34.45 63.80 23.89 0.08 9.43 4.63 11.25 3.45 2.83
|
@@ -0,0 +1 @@
|
|
1
|
+
11:57:33 AM all 49.91 0.03 2.68 0.55 0.00 0.10 0.00 0.00 46.73
|
@@ -0,0 +1 @@
|
|
1
|
+
eth0 1500 0 10855972 0 0 0 8231649 0 0 0 BMRU
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require "zabbix-ruby-client/cli"
|
5
|
+
|
6
|
+
describe ZabbixRubyClient::Cli do
|
7
|
+
|
8
|
+
pending "init creates a working directory"
|
9
|
+
pending "show displays the list of data collected"
|
10
|
+
pending "upload collects and uploads the data from system"
|
11
|
+
pending "when a custom config file is specified it's taken in account"
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require "zabbix-ruby-client/logger"
|
5
|
+
|
6
|
+
describe ZabbixRubyClient::Logger do
|
7
|
+
|
8
|
+
pending "get_logger returns a valid Logger instance"
|
9
|
+
pending "logged message are nicely formatted"
|
10
|
+
pending "loglevel is properly interpreted from argument"
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require "zabbix-ruby-client/plugins"
|
5
|
+
ZabbixRubyClient::Plugins.load_dirs ["zabbix-ruby-client/plugins"]
|
6
|
+
require "zabbix-ruby-client/plugins/apache"
|
7
|
+
|
8
|
+
describe ZabbixRubyClient::Plugins::Apache do
|
9
|
+
|
10
|
+
pending "gets the status page from localhost"
|
11
|
+
pending "populate a hash with extracted data"
|
12
|
+
pending "populate scores from scoreboard data"
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require "zabbix-ruby-client/plugins"
|
5
|
+
ZabbixRubyClient::Plugins.load_dirs ["zabbix-ruby-client/plugins"]
|
6
|
+
require "zabbix-ruby-client/plugins/cpu"
|
7
|
+
|
8
|
+
describe ZabbixRubyClient::Plugins::Cpu do
|
9
|
+
|
10
|
+
pending "populate a hash with extracted data"
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require "zabbix-ruby-client/plugins"
|
5
|
+
ZabbixRubyClient::Plugins.load_dirs ["zabbix-ruby-client/plugins"]
|
6
|
+
require "zabbix-ruby-client/plugins/disk"
|
7
|
+
|
8
|
+
describe ZabbixRubyClient::Plugins::Disk do
|
9
|
+
|
10
|
+
pending "populate a hash with extracted data"
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require "zabbix-ruby-client/plugins"
|
5
|
+
ZabbixRubyClient::Plugins.load_dirs ["zabbix-ruby-client/plugins"]
|
6
|
+
require "zabbix-ruby-client/plugins/memory"
|
7
|
+
|
8
|
+
describe ZabbixRubyClient::Plugins::Memory do
|
9
|
+
|
10
|
+
pending "populate a hash with extracted data"
|
11
|
+
pending "splits info to prepare collection"
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require "zabbix-ruby-client/plugins"
|
5
|
+
ZabbixRubyClient::Plugins.load_dirs ["zabbix-ruby-client/plugins"]
|
6
|
+
require "zabbix-ruby-client/plugins/network"
|
7
|
+
|
8
|
+
describe ZabbixRubyClient::Plugins::Network do
|
9
|
+
|
10
|
+
pending "populate a hash with extracted data"
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require "zabbix-ruby-client/plugins"
|
5
|
+
|
6
|
+
describe ZabbixRubyClient::Plugins do
|
7
|
+
|
8
|
+
pending "loading dirs works"
|
9
|
+
pending "registering a new plugin loads it"
|
10
|
+
pending "loading a plugin adds plugin in loaded list"
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require "zabbix-ruby-client"
|
5
|
+
|
6
|
+
describe ZabbixRubyClient do
|
7
|
+
|
8
|
+
pending "initialize the client object"
|
9
|
+
pending "creates dirs if needed"
|
10
|
+
pending "loads list of plugins"
|
11
|
+
pending "initialize datafile according to config"
|
12
|
+
pending "stores data in datafile"
|
13
|
+
pending "runs list of plugins according to config"
|
14
|
+
pending "issues the upload command according to config"
|
15
|
+
|
16
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
---
|
2
|
+
host: localhost
|
3
|
+
logsdir: logs
|
4
|
+
loglevel: info
|
5
|
+
datadir: data
|
6
|
+
keepdata: no # or yes
|
7
|
+
plugindirs:
|
8
|
+
- plugins
|
9
|
+
zabbix:
|
10
|
+
host: zabbix.example.com
|
11
|
+
port: 10051
|
12
|
+
sender: /usr/bin/zabbix_sender
|
13
|
+
plugins:
|
14
|
+
- name: memory
|
15
|
+
- name: cpu
|
16
|
+
- name: network
|
17
|
+
args: eth0
|
18
|
+
- name: disk
|
19
|
+
args: sda1
|
20
|
+
- name: network
|
21
|
+
args: eth0
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'zabbix-ruby-client/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "zabbix-ruby-client"
|
8
|
+
spec.version = ZabbixRubyClient::VERSION
|
9
|
+
spec.authors = ["mose"]
|
10
|
+
spec.email = ["mose@mose.com"]
|
11
|
+
spec.description = %q{A zabbix alternative to zabbix-agent using zabbix-sender.}
|
12
|
+
spec.summary = %q{This tool is intended to use zabbix sender to propagate monitoring data for Zabbix server.}
|
13
|
+
spec.homepage = "https://github.com/eduvo/zabbix-ruby-client"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^spec/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "thor"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zabbix-ruby-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- mose
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
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: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
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: rspec
|
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
|
+
description: A zabbix alternative to zabbix-agent using zabbix-sender.
|
70
|
+
email:
|
71
|
+
- mose@mose.com
|
72
|
+
executables:
|
73
|
+
- zrc
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- .gitignore
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/zrc
|
83
|
+
- lib/zabbix-ruby-client.rb
|
84
|
+
- lib/zabbix-ruby-client/cli.rb
|
85
|
+
- lib/zabbix-ruby-client/logger.rb
|
86
|
+
- lib/zabbix-ruby-client/plugins.rb
|
87
|
+
- lib/zabbix-ruby-client/plugins/apache.rb
|
88
|
+
- lib/zabbix-ruby-client/plugins/cpu.rb
|
89
|
+
- lib/zabbix-ruby-client/plugins/disk.rb
|
90
|
+
- lib/zabbix-ruby-client/plugins/memory.rb
|
91
|
+
- lib/zabbix-ruby-client/plugins/network.rb
|
92
|
+
- lib/zabbix-ruby-client/version.rb
|
93
|
+
- spec/files/config.yml
|
94
|
+
- spec/files/plugins/apache_status
|
95
|
+
- spec/files/plugins/iostat_disk
|
96
|
+
- spec/files/plugins/mpstat
|
97
|
+
- spec/files/plugins/netstat
|
98
|
+
- spec/files/plugins/vmstat
|
99
|
+
- spec/lib/cli_spec.rb
|
100
|
+
- spec/lib/logger_spec.rb
|
101
|
+
- spec/lib/plugins/apache_spec.rb
|
102
|
+
- spec/lib/plugins/cpu_spec.rb
|
103
|
+
- spec/lib/plugins/disk_spec.rb
|
104
|
+
- spec/lib/plugins/memory_spec.rb
|
105
|
+
- spec/lib/plugins/network_spec.rb
|
106
|
+
- spec/lib/plugins_spec.rb
|
107
|
+
- spec/lib/zabbix-ruby-client_spec.rb
|
108
|
+
- spec/spec_helper.rb
|
109
|
+
- templates/client/Gemfile
|
110
|
+
- templates/client/config.yml
|
111
|
+
- zabbix-ruby-client.gemspec
|
112
|
+
homepage: https://github.com/eduvo/zabbix-ruby-client
|
113
|
+
licenses:
|
114
|
+
- MIT
|
115
|
+
metadata: {}
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - '>='
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
requirements: []
|
131
|
+
rubyforge_project:
|
132
|
+
rubygems_version: 2.0.3
|
133
|
+
signing_key:
|
134
|
+
specification_version: 4
|
135
|
+
summary: This tool is intended to use zabbix sender to propagate monitoring data for
|
136
|
+
Zabbix server.
|
137
|
+
test_files:
|
138
|
+
- spec/files/config.yml
|
139
|
+
- spec/files/plugins/apache_status
|
140
|
+
- spec/files/plugins/iostat_disk
|
141
|
+
- spec/files/plugins/mpstat
|
142
|
+
- spec/files/plugins/netstat
|
143
|
+
- spec/files/plugins/vmstat
|
144
|
+
- spec/lib/cli_spec.rb
|
145
|
+
- spec/lib/logger_spec.rb
|
146
|
+
- spec/lib/plugins/apache_spec.rb
|
147
|
+
- spec/lib/plugins/cpu_spec.rb
|
148
|
+
- spec/lib/plugins/disk_spec.rb
|
149
|
+
- spec/lib/plugins/memory_spec.rb
|
150
|
+
- spec/lib/plugins/network_spec.rb
|
151
|
+
- spec/lib/plugins_spec.rb
|
152
|
+
- spec/lib/zabbix-ruby-client_spec.rb
|
153
|
+
- spec/spec_helper.rb
|