zabbix-ruby-client 0.0.15 → 0.0.16
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 +4 -4
- data/.coveralls.yml +1 -0
- data/.travis.yml +4 -0
- data/CHANGELOG.md +7 -0
- data/README.md +5 -0
- data/lib/zabbix-ruby-client.rb +3 -71
- data/lib/zabbix-ruby-client/cli.rb +20 -4
- data/lib/zabbix-ruby-client/data.rb +5 -3
- data/lib/zabbix-ruby-client/logger.rb +34 -8
- data/lib/zabbix-ruby-client/plugins.rb +12 -7
- data/lib/zabbix-ruby-client/plugins/apache.rb +1 -1
- data/lib/zabbix-ruby-client/plugins/apt.rb +4 -2
- data/lib/zabbix-ruby-client/plugins/cpu.rb +3 -3
- data/lib/zabbix-ruby-client/plugins/disk.rb +3 -2
- data/lib/zabbix-ruby-client/plugins/load.rb +3 -2
- data/lib/zabbix-ruby-client/plugins/memory.rb +4 -2
- data/lib/zabbix-ruby-client/plugins/mysql.rb +4 -2
- data/lib/zabbix-ruby-client/plugins/network.rb +4 -2
- data/lib/zabbix-ruby-client/plugins/nginx.rb +2 -1
- data/lib/zabbix-ruby-client/plugins/redis.rb +3 -2
- data/lib/zabbix-ruby-client/plugins/sysinfo.rb +4 -2
- data/lib/zabbix-ruby-client/plugins/who.rb +4 -2
- data/lib/zabbix-ruby-client/runner.rb +58 -0
- data/lib/zabbix-ruby-client/store.rb +1 -1
- data/lib/zabbix-ruby-client/version.rb +2 -2
- data/spec/files/config.yml +1 -10
- data/spec/files/data/.gitkeep +0 -0
- data/spec/files/logs/.gitkeep +0 -0
- data/spec/files/plugins/sample.rb +11 -0
- data/spec/files/{plugins → system}/apache_status +0 -0
- data/spec/files/{plugins → system}/iostat_disk +0 -0
- data/spec/files/{plugins → system}/mpstat +0 -0
- data/spec/files/{plugins → system}/netstat +0 -0
- data/spec/files/{plugins → system}/vmstat +0 -0
- data/spec/files/task.yml +2 -0
- data/spec/lib/logger_spec.rb +26 -5
- data/spec/lib/plugins/apache_spec.rb +1 -1
- data/spec/lib/plugins/cpu_spec.rb +2 -3
- data/spec/lib/plugins/disk_spec.rb +1 -1
- data/spec/lib/plugins/memory_spec.rb +1 -1
- data/spec/lib/plugins/network_spec.rb +1 -1
- data/spec/lib/plugins_spec.rb +36 -5
- data/spec/lib/runner_spec.rb +37 -0
- data/spec/spec_helper.rb +3 -0
- data/zabbix-ruby-client.gemspec +1 -0
- metadata +39 -14
- data/spec/lib/zabbix-ruby-client_spec.rb +0 -16
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9d21a9e419424ce57875b93ca1a3762d2b91ced6
|
|
4
|
+
data.tar.gz: 3a9009d18b91bcb35314d9c252f74758764fb8b4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: db3e39aafa5b8fd659a403759e96802a4020481a375a5fd6ce22d53ecb494a1e33ec2a9eb25dd564c904e22f8dbf4029fd07e46421db690ff75abb8d794d168f
|
|
7
|
+
data.tar.gz: 1d179f9c66d731f9b17b24554b4c5f37ff4a4b9df4bfa8d3dcde688de331a8c97fcda3da9ca79775e18b76683bbafc7fdfc91c0d7daa14af22f2da4fb226cf44
|
data/.coveralls.yml
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
repo_token: Oej1FGJWwMJdJPP5si37KoXFU3EcLQH9v
|
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
Zabbbix Ruby Client Changelog
|
|
2
2
|
-----------------------------
|
|
3
3
|
|
|
4
|
+
### v0.0.16 - 2013-10-31
|
|
5
|
+
|
|
6
|
+
* _if you have custom plugins_ the class ZabbixRubyClient is now a module just for namespacing, update your code!
|
|
7
|
+
* fix the logger
|
|
8
|
+
* refactoring and more tests
|
|
9
|
+
* adding travis and coverall to stimulate testing, also added gemnasium
|
|
10
|
+
|
|
4
11
|
### v0.0.15 - 2013-10-23
|
|
5
12
|
|
|
6
13
|
* prototype of a way to keep data when sending fails and sending it again at next iteration
|
data/README.md
CHANGED
|
@@ -2,8 +2,13 @@ Zabbix Ruby Client
|
|
|
2
2
|
====================
|
|
3
3
|
|
|
4
4
|
[](http://rubygems.org/gems/zabbix-ruby-client)
|
|
5
|
+
[](https://travis-ci.org/eduvo/zabbix-ruby-client)
|
|
6
|
+
[](https://coveralls.io/r/eduvo/zabbix-ruby-client)
|
|
7
|
+
[](https://gemnasium.com/eduvo/zabbix-ruby-client)
|
|
5
8
|
[](https://codeclimate.com/github/eduvo/zabbix-ruby-client)
|
|
6
9
|
|
|
10
|
+
----
|
|
11
|
+
|
|
7
12
|
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.
|
|
8
13
|
|
|
9
14
|
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.
|
data/lib/zabbix-ruby-client.rb
CHANGED
|
@@ -3,79 +3,11 @@ require "zabbix-ruby-client/logger"
|
|
|
3
3
|
require "zabbix-ruby-client/plugins"
|
|
4
4
|
require "zabbix-ruby-client/store"
|
|
5
5
|
require "zabbix-ruby-client/data"
|
|
6
|
+
require "zabbix-ruby-client/runner"
|
|
6
7
|
require "yaml"
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
module ZabbixRubyClient
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
begin
|
|
12
|
-
@config ||= YAML::load_file(config_file)
|
|
13
|
-
if File.exists? task_file
|
|
14
|
-
@tasks ||= YAML::load_file(task_file)
|
|
15
|
-
else
|
|
16
|
-
@tasks = @config["plugins"]
|
|
17
|
-
end
|
|
18
|
-
rescue Exception => e
|
|
19
|
-
puts "Configuration file cannot be read"
|
|
20
|
-
puts e.message
|
|
21
|
-
return
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
@store = Store.new(
|
|
25
|
-
@config['datadir'],
|
|
26
|
-
@config['zabbix']['host'],
|
|
27
|
-
File.basename(task_file,'.yml'),
|
|
28
|
-
@config['keepdata']
|
|
29
|
-
)
|
|
30
|
-
|
|
31
|
-
@data = Data.new(@config['host'])
|
|
32
|
-
|
|
33
|
-
@config["server"] = File.basename(config_file,'.yml')
|
|
34
|
-
@logsdir = makedir(@config['logsdir'],'logs')
|
|
35
|
-
@plugindirs = [ File.expand_path("../zabbix-ruby-client/plugins", __FILE__) ]
|
|
36
|
-
if @config["plugindirs"]
|
|
37
|
-
@plugindirs = @plugindirs + @config["plugindirs"]
|
|
38
|
-
end
|
|
39
|
-
Plugins.load_dirs @plugindirs
|
|
40
|
-
logger.debug @config.inspect
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def collect
|
|
44
|
-
@tasks.each do |plugin|
|
|
45
|
-
@data.run_plugin(plugin['name'], plugin['args'])
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def show
|
|
50
|
-
@data.merge.each do |line|
|
|
51
|
-
puts line
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def upload
|
|
56
|
-
file = @store.record(@data.merge)
|
|
57
|
-
begin
|
|
58
|
-
res = `#{@config['zabbix']['sender']} -z #{@config['zabbix']['host']} -p #{@config['zabbix']['port']} -T -i #{file}`
|
|
59
|
-
if $?.to_i != 0
|
|
60
|
-
@store.keepdata(file)
|
|
61
|
-
end
|
|
62
|
-
rescue Exception => e
|
|
63
|
-
@store.keepdata(file)
|
|
64
|
-
logger.error "Sending failed."
|
|
65
|
-
logger.error e.message
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def logger
|
|
70
|
-
@logger ||= Logger.get_logger(@logsdir, @config["loglevel"])
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
private
|
|
74
|
-
|
|
75
|
-
def makedir(configdir, defaultdir)
|
|
76
|
-
dir = configdir || defaultdir
|
|
77
|
-
FileUtils.mkdir dir unless Dir.exists? dir
|
|
78
|
-
dir
|
|
79
|
-
end
|
|
11
|
+
PLUGINDIR = File.expand_path("../zabbix-ruby-client/plugins", __FILE__)
|
|
80
12
|
|
|
81
13
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require "thor"
|
|
2
|
-
require "zabbix-ruby-client"
|
|
2
|
+
require "zabbix-ruby-client/runner"
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
module ZabbixRubyClient
|
|
5
5
|
|
|
6
6
|
class Cli < Thor
|
|
7
7
|
include Thor::Actions
|
|
@@ -35,14 +35,30 @@ class ZabbixRubyClient
|
|
|
35
35
|
say "No Gemfile found", :red
|
|
36
36
|
abort
|
|
37
37
|
end
|
|
38
|
-
|
|
38
|
+
config = YAML::load_file(options[:configfile])
|
|
39
|
+
if File.exists? options[:taskfile]
|
|
40
|
+
tasks = YAML::load_file(options[:taskfile])
|
|
41
|
+
else
|
|
42
|
+
tasks = config['plugins']
|
|
43
|
+
end
|
|
44
|
+
config['server'] = File.basename(options[:configfile],'.yml')
|
|
45
|
+
config['taskfile'] = File.basename(options[:taskfile],'.yml')
|
|
46
|
+
zrc = ZabbixRubyClient::Runner.new(config, tasks)
|
|
39
47
|
zrc.collect
|
|
40
48
|
zrc.show
|
|
41
49
|
end
|
|
42
50
|
|
|
43
51
|
desc "upload", "Collects and sends data to the zabbix server"
|
|
44
52
|
def upload
|
|
45
|
-
|
|
53
|
+
config = YAML::load_file(options[:configfile])
|
|
54
|
+
if File.exists? options[:taskfile]
|
|
55
|
+
tasks = YAML::load_file(options[:taskfile])
|
|
56
|
+
else
|
|
57
|
+
tasks = config['plugins']
|
|
58
|
+
end
|
|
59
|
+
config['server'] = File.basename(options[:configfile],'.yml')
|
|
60
|
+
config['taskfile'] = File.basename(options[:taskfile],'.yml')
|
|
61
|
+
zrc = ZabbixRubyClient::Runner.new(config, tasks)
|
|
46
62
|
zrc.collect
|
|
47
63
|
zrc.upload
|
|
48
64
|
end
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
require "zabbix-ruby-client/logger"
|
|
2
|
+
|
|
3
|
+
module ZabbixRubyClient
|
|
2
4
|
class Data
|
|
3
5
|
|
|
4
6
|
def initialize(host)
|
|
@@ -18,8 +20,8 @@ class ZabbixRubyClient
|
|
|
18
20
|
@discover[key] << [ value ]
|
|
19
21
|
end
|
|
20
22
|
rescue Exception => e
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
Log.fatal "Oops"
|
|
24
|
+
Log.fatal e.message
|
|
23
25
|
end
|
|
24
26
|
end
|
|
25
27
|
end
|
|
@@ -1,16 +1,42 @@
|
|
|
1
1
|
require "logger"
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
module
|
|
3
|
+
module ZabbixRubyClient
|
|
4
|
+
module Log
|
|
5
5
|
extend self
|
|
6
6
|
|
|
7
|
-
def
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
def set_logger(logfile, level="info")
|
|
8
|
+
if logfile.is_a?(String) && !Dir.exists?(File.dirname(logfile))
|
|
9
|
+
FileUtils.mkdir_p(File.dirname(logfile))
|
|
10
|
+
end
|
|
11
|
+
@logger = ::Logger.new(logfile)
|
|
12
|
+
@logger.level = get_level_constant(level)
|
|
13
|
+
@logger.formatter = proc do |severity, datetime, progname, msg|
|
|
11
14
|
"[#{datetime.utc}] #{severity}: #{msg}\n"
|
|
12
15
|
end
|
|
13
|
-
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def logger
|
|
19
|
+
@logger ||= ::Logger.new(STDOUT)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def debug(msg)
|
|
23
|
+
logger.debug(msg)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def info(msg)
|
|
27
|
+
logger.info(msg)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def warn(msg)
|
|
31
|
+
logger.warn(msg)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def error(msg)
|
|
35
|
+
logger.error(msg)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def fatal(msg)
|
|
39
|
+
logger.fatal(msg)
|
|
14
40
|
end
|
|
15
41
|
|
|
16
42
|
def get_level_constant(level)
|
|
@@ -26,4 +52,4 @@ class ZabbixRubyClient
|
|
|
26
52
|
end
|
|
27
53
|
|
|
28
54
|
end
|
|
29
|
-
end
|
|
55
|
+
end
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
module ZabbixRubyClient
|
|
2
2
|
module Plugins
|
|
3
3
|
extend self
|
|
4
4
|
|
|
5
|
-
def
|
|
5
|
+
def scan_dirs(dirs)
|
|
6
6
|
@available = {}
|
|
7
7
|
@loaded = {}
|
|
8
8
|
dirs.each do |d|
|
|
@@ -14,14 +14,14 @@ class ZabbixRubyClient
|
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
def register(plugin, klass)
|
|
18
|
-
@loaded[plugin] = klass
|
|
19
|
-
end
|
|
20
|
-
|
|
21
17
|
def loaded
|
|
22
18
|
@loaded ||= {}
|
|
23
19
|
end
|
|
24
20
|
|
|
21
|
+
def register(plugin, klass)
|
|
22
|
+
@loaded[plugin] = klass
|
|
23
|
+
end
|
|
24
|
+
|
|
25
25
|
def load(plugin)
|
|
26
26
|
if @loaded[plugin]
|
|
27
27
|
true
|
|
@@ -34,5 +34,10 @@ class ZabbixRubyClient
|
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
+
def reset
|
|
38
|
+
@loaded = {}
|
|
39
|
+
@available = {}
|
|
40
|
+
end
|
|
41
|
+
|
|
37
42
|
end
|
|
38
|
-
end
|
|
43
|
+
end
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
require "zabbix-ruby-client/logger"
|
|
2
|
+
|
|
3
|
+
module ZabbixRubyClient
|
|
2
4
|
module Plugins
|
|
3
5
|
module Apt
|
|
4
6
|
extend self
|
|
@@ -9,7 +11,7 @@ class ZabbixRubyClient
|
|
|
9
11
|
if $?.to_i == 0
|
|
10
12
|
security, pending = aptcheck.split(/;/).map(&:to_i)
|
|
11
13
|
else
|
|
12
|
-
|
|
14
|
+
Log.warn "Are you running on ubuntu ?"
|
|
13
15
|
return []
|
|
14
16
|
end
|
|
15
17
|
time = Time.now.to_i
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
# for more info check
|
|
2
2
|
# http://www.linuxhowtos.org/System/procstat.htm
|
|
3
3
|
# http://juliano.info/en/Blog:Memory_Leak/Understanding_the_Linux_load_average
|
|
4
|
+
require "zabbix-ruby-client/logger"
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
module ZabbixRubyClient
|
|
6
7
|
module Plugins
|
|
7
8
|
module Cpu
|
|
8
9
|
extend self
|
|
9
10
|
|
|
10
11
|
def collect(*args)
|
|
11
12
|
host = args[0]
|
|
12
|
-
#cpuinfo = `mpstat | grep " all "`
|
|
13
13
|
cpuinfo = `cat /proc/stat | grep "^cpu"`
|
|
14
14
|
if $?.to_i == 0
|
|
15
15
|
_, user, nice, sys, idle, wait, irq, soft, guest, steal = cpuinfo.split(/\s+/).map(&:to_i)
|
|
16
16
|
else
|
|
17
|
-
|
|
17
|
+
Log.warn "Oh you don't have a /proc ?"
|
|
18
18
|
return []
|
|
19
19
|
end
|
|
20
20
|
used = user + nice + sys
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
# some doc on
|
|
2
2
|
# http://www.xaprb.com/blog/2010/01/09/how-linux-iostat-computes-its-results/
|
|
3
3
|
# http://www.mjmwired.net/kernel/Documentation/iostats.txt
|
|
4
|
+
require "zabbix-ruby-client/logger"
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
module ZabbixRubyClient
|
|
6
7
|
module Plugins
|
|
7
8
|
module Disk
|
|
8
9
|
extend self
|
|
@@ -15,7 +16,7 @@ class ZabbixRubyClient
|
|
|
15
16
|
if $?.to_i == 0
|
|
16
17
|
_, size, used, available, percent_used, mount = diskspace.split(/\s+/)
|
|
17
18
|
else
|
|
18
|
-
|
|
19
|
+
Log.error "df is not working... ouchie."
|
|
19
20
|
return []
|
|
20
21
|
end
|
|
21
22
|
time = Time.now.to_i
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# for more info check
|
|
2
2
|
# http://juliano.info/en/Blog:Memory_Leak/Understanding_the_Linux_load_average
|
|
3
|
+
require "zabbix-ruby-client/logger"
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
module ZabbixRubyClient
|
|
5
6
|
module Plugins
|
|
6
7
|
module Load
|
|
7
8
|
extend self
|
|
@@ -13,7 +14,7 @@ class ZabbixRubyClient
|
|
|
13
14
|
if $?.to_i == 0
|
|
14
15
|
one, five, fifteen, procs_t = cpuinfo.split(/\s+/)
|
|
15
16
|
else
|
|
16
|
-
|
|
17
|
+
Log.warn "Oh you don't have a /proc ?"
|
|
17
18
|
return []
|
|
18
19
|
end
|
|
19
20
|
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
require "zabbix-ruby-client/logger"
|
|
2
|
+
|
|
3
|
+
module ZabbixRubyClient
|
|
2
4
|
module Plugins
|
|
3
5
|
module Memory
|
|
4
6
|
extend self
|
|
@@ -9,7 +11,7 @@ class ZabbixRubyClient
|
|
|
9
11
|
if $?.to_i == 0
|
|
10
12
|
info = splitinfo(meminfo)
|
|
11
13
|
else
|
|
12
|
-
|
|
14
|
+
Log.warn "Please install sysstat."
|
|
13
15
|
return []
|
|
14
16
|
end
|
|
15
17
|
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
require "zabbix-ruby-client/logger"
|
|
2
|
+
|
|
3
|
+
module ZabbixRubyClient
|
|
2
4
|
module Plugins
|
|
3
5
|
module Mysql
|
|
4
6
|
extend self
|
|
@@ -10,7 +12,7 @@ class ZabbixRubyClient
|
|
|
10
12
|
if $?.to_i == 0
|
|
11
13
|
status = get_status(mysqlstatus)
|
|
12
14
|
else
|
|
13
|
-
|
|
15
|
+
Log.warn "The connection failed."
|
|
14
16
|
return []
|
|
15
17
|
end
|
|
16
18
|
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
require "zabbix-ruby-client/logger"
|
|
2
|
+
|
|
3
|
+
module ZabbixRubyClient
|
|
2
4
|
module Plugins
|
|
3
5
|
module Network
|
|
4
6
|
extend self
|
|
@@ -10,7 +12,7 @@ class ZabbixRubyClient
|
|
|
10
12
|
if $?.to_i == 0
|
|
11
13
|
_, _, rx_ok, rx_packets, rx_err, rx_drop, _, _, _, _, tx_ok, tx_packets, tx_err, tx_drop, _, _, _, _ = netinfo.split(/\s+/)
|
|
12
14
|
else
|
|
13
|
-
|
|
15
|
+
Log.warn "proc not found."
|
|
14
16
|
return []
|
|
15
17
|
end
|
|
16
18
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# this is a simple version for standalone redis server
|
|
2
|
+
require "zabbix-ruby-client/logger"
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
module ZabbixRubyClient
|
|
4
5
|
module Plugins
|
|
5
6
|
module Redis
|
|
6
7
|
extend self
|
|
@@ -13,7 +14,7 @@ class ZabbixRubyClient
|
|
|
13
14
|
if $?.to_i == 0
|
|
14
15
|
info = get_info(redisinfo)
|
|
15
16
|
else
|
|
16
|
-
|
|
17
|
+
Log.warn "Redis connection failed."
|
|
17
18
|
return []
|
|
18
19
|
end
|
|
19
20
|
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
require "zabbix-ruby-client/logger"
|
|
2
|
+
|
|
3
|
+
module ZabbixRubyClient
|
|
2
4
|
module Plugins
|
|
3
5
|
module Sysinfo
|
|
4
6
|
extend self
|
|
@@ -10,7 +12,7 @@ class ZabbixRubyClient
|
|
|
10
12
|
arch, hostname, kernel, kernel_version, machine, proc,
|
|
11
13
|
_, _, _, _, _, _, _, platform, os = uname.split(/ /)
|
|
12
14
|
else
|
|
13
|
-
|
|
15
|
+
Log.warn "Are you running on ubuntu ?"
|
|
14
16
|
return []
|
|
15
17
|
end
|
|
16
18
|
time = Time.now.to_i
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
require "zabbix-ruby-client/logger"
|
|
2
|
+
|
|
3
|
+
module ZabbixRubyClient
|
|
2
4
|
module Plugins
|
|
3
5
|
module Who
|
|
4
6
|
extend self
|
|
@@ -7,7 +9,7 @@ class ZabbixRubyClient
|
|
|
7
9
|
host = args[0]
|
|
8
10
|
who = get_who
|
|
9
11
|
if $?.to_i != 0
|
|
10
|
-
|
|
12
|
+
Log.warn "Are you running on ubuntu ?"
|
|
11
13
|
return []
|
|
12
14
|
end
|
|
13
15
|
time = Time.now.to_i
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
module ZabbixRubyClient
|
|
2
|
+
|
|
3
|
+
class Runner
|
|
4
|
+
|
|
5
|
+
def initialize(config, tasks)
|
|
6
|
+
@config = config
|
|
7
|
+
@tasks = tasks
|
|
8
|
+
|
|
9
|
+
@store = ZabbixRubyClient::Store.new(
|
|
10
|
+
@config['datadir'],
|
|
11
|
+
@config['zabbix']['host'],
|
|
12
|
+
@config['taskfile'],
|
|
13
|
+
@config['keepdata']
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
@data = ZabbixRubyClient::Data.new(@config['host'])
|
|
17
|
+
@logsdir = makedir(@config['logsdir'], 'logs')
|
|
18
|
+
ZabbixRubyClient::Plugins.scan_dirs([ PLUGINDIR ] + @config['plugindirs'])
|
|
19
|
+
ZabbixRubyClient::Log.set_logger(File.join(@logsdir, 'zrc.log'), 'info')
|
|
20
|
+
ZabbixRubyClient::Log.debug @config.inspect
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def collect
|
|
24
|
+
@tasks.each do |plugin|
|
|
25
|
+
@data.run_plugin(plugin['name'], plugin['args'])
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def show
|
|
30
|
+
@data.merge.each do |line|
|
|
31
|
+
puts line
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def upload
|
|
36
|
+
file = @store.record(@data.merge)
|
|
37
|
+
begin
|
|
38
|
+
res = `#{@config['zabbix']['sender']} -z #{@config['zabbix']['host']} -p #{@config['zabbix']['port']} -T -i #{file}`
|
|
39
|
+
if $?.to_i != 0
|
|
40
|
+
@store.keepdata(file)
|
|
41
|
+
end
|
|
42
|
+
rescue Exception => e
|
|
43
|
+
@store.keepdata(file)
|
|
44
|
+
logger.error "Sending failed."
|
|
45
|
+
logger.error e.message
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
private
|
|
50
|
+
|
|
51
|
+
def makedir(configdir, defaultdir)
|
|
52
|
+
dir = configdir || defaultdir
|
|
53
|
+
FileUtils.mkdir dir unless Dir.exists? dir
|
|
54
|
+
dir
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
VERSION ||= "0.0.
|
|
1
|
+
module ZabbixRubyClient
|
|
2
|
+
VERSION ||= "0.0.16"
|
|
3
3
|
end
|
data/spec/files/config.yml
CHANGED
|
@@ -4,18 +4,9 @@ logsdir: logs
|
|
|
4
4
|
loglevel: info
|
|
5
5
|
datadir: data
|
|
6
6
|
keepdata: no # or yes
|
|
7
|
-
plugindirs:
|
|
7
|
+
plugindirs:
|
|
8
8
|
- plugins
|
|
9
9
|
zabbix:
|
|
10
10
|
host: zabbix.example.com
|
|
11
11
|
port: 10051
|
|
12
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
data/spec/files/task.yml
ADDED
data/spec/lib/logger_spec.rb
CHANGED
|
@@ -3,10 +3,31 @@
|
|
|
3
3
|
require 'spec_helper'
|
|
4
4
|
require "zabbix-ruby-client/logger"
|
|
5
5
|
|
|
6
|
-
describe ZabbixRubyClient::
|
|
6
|
+
describe ZabbixRubyClient::Log do
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
before :all do
|
|
9
|
+
@logfile = File.expand_path("../../files/logs/testlog", __FILE__)
|
|
10
|
+
end
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
after :each do
|
|
13
|
+
File.unlink(@logfile) if File.exists?(@logfile)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "set_logger prepares the logger" do
|
|
17
|
+
ZabbixRubyClient::Log.set_logger(@logfile, 'info')
|
|
18
|
+
expect(ZabbixRubyClient::Log.instance_variable_get(:@logger)).to be_instance_of Logger
|
|
19
|
+
expect(ZabbixRubyClient::Log.logger.level).to be Logger::INFO
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "logged message are nicely formatted" do
|
|
23
|
+
ZabbixRubyClient::Log.set_logger(@logfile, 'debug')
|
|
24
|
+
ZabbixRubyClient::Log.logger.debug("ha")
|
|
25
|
+
expect(File.read(@logfile)).to match /\] DEBUG: ha\n/
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "loglevel is properly interpreted from argument" do
|
|
29
|
+
ZabbixRubyClient::Log.set_logger(@logfile, 'debug')
|
|
30
|
+
expect(ZabbixRubyClient::Log.instance_variable_get(:@logger).level).to be Logger::DEBUG
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require 'spec_helper'
|
|
4
4
|
require "zabbix-ruby-client/plugins"
|
|
5
|
-
ZabbixRubyClient::Plugins.
|
|
5
|
+
ZabbixRubyClient::Plugins.scan_dirs ["zabbix-ruby-client/plugins"]
|
|
6
6
|
require "zabbix-ruby-client/plugins/apache"
|
|
7
7
|
|
|
8
8
|
describe ZabbixRubyClient::Plugins::Apache do
|
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
require 'spec_helper'
|
|
4
4
|
require "zabbix-ruby-client/plugins"
|
|
5
|
-
ZabbixRubyClient::Plugins.load_dirs ["zabbix-ruby-client/plugins"]
|
|
6
5
|
require "zabbix-ruby-client/plugins/cpu"
|
|
7
6
|
|
|
8
7
|
describe ZabbixRubyClient::Plugins::Cpu do
|
|
9
|
-
|
|
8
|
+
|
|
10
9
|
pending "populate a hash with extracted data"
|
|
11
10
|
|
|
12
|
-
end
|
|
11
|
+
end
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require 'spec_helper'
|
|
4
4
|
require "zabbix-ruby-client/plugins"
|
|
5
|
-
ZabbixRubyClient::Plugins.
|
|
5
|
+
ZabbixRubyClient::Plugins.scan_dirs ["zabbix-ruby-client/plugins"]
|
|
6
6
|
require "zabbix-ruby-client/plugins/disk"
|
|
7
7
|
|
|
8
8
|
describe ZabbixRubyClient::Plugins::Disk do
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require 'spec_helper'
|
|
4
4
|
require "zabbix-ruby-client/plugins"
|
|
5
|
-
ZabbixRubyClient::Plugins.
|
|
5
|
+
ZabbixRubyClient::Plugins.scan_dirs ["zabbix-ruby-client/plugins"]
|
|
6
6
|
require "zabbix-ruby-client/plugins/memory"
|
|
7
7
|
|
|
8
8
|
describe ZabbixRubyClient::Plugins::Memory do
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require 'spec_helper'
|
|
4
4
|
require "zabbix-ruby-client/plugins"
|
|
5
|
-
ZabbixRubyClient::Plugins.
|
|
5
|
+
ZabbixRubyClient::Plugins.scan_dirs ["zabbix-ruby-client/plugins"]
|
|
6
6
|
require "zabbix-ruby-client/plugins/network"
|
|
7
7
|
|
|
8
8
|
describe ZabbixRubyClient::Plugins::Network do
|
data/spec/lib/plugins_spec.rb
CHANGED
|
@@ -4,9 +4,40 @@ require 'spec_helper'
|
|
|
4
4
|
require "zabbix-ruby-client/plugins"
|
|
5
5
|
|
|
6
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
7
|
|
|
12
|
-
|
|
8
|
+
before :all do
|
|
9
|
+
@plugindir = File.expand_path("../../files/plugins", __FILE__)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
before :each do
|
|
13
|
+
ZabbixRubyClient::Plugins.scan_dirs([@plugindir])
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
after :each do
|
|
17
|
+
ZabbixRubyClient::Plugins.reset
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "loading dirs works" do
|
|
21
|
+
result = {"sample" => File.join(@plugindir, "sample.rb") }
|
|
22
|
+
expect(ZabbixRubyClient::Plugins.instance_variable_get(:@available)).to eq result
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "registering a new plugin loads it" do
|
|
26
|
+
ZabbixRubyClient::Plugins.register("sample",Object)
|
|
27
|
+
result = { "sample" => Object }
|
|
28
|
+
expect(ZabbixRubyClient::Plugins.instance_variable_get(:@loaded)).to eq result
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "loading a plugin adds plugin in loaded list" do
|
|
32
|
+
ZabbixRubyClient::Plugins.load("sample")
|
|
33
|
+
expect(Sample).to be_kind_of Module
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "do not load a plugin already loaded" do
|
|
37
|
+
ZabbixRubyClient::Plugins.load("sample")
|
|
38
|
+
ZabbixRubyClient::Plugins.load("sample")
|
|
39
|
+
result = { "sample" => Sample }
|
|
40
|
+
expect(ZabbixRubyClient::Plugins.instance_variable_get(:@loaded)).to eq result
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
require "zabbix-ruby-client"
|
|
5
|
+
|
|
6
|
+
describe ZabbixRubyClient::Runner do
|
|
7
|
+
|
|
8
|
+
before :each do
|
|
9
|
+
@basedir = File.expand_path("../../files", __FILE__)
|
|
10
|
+
Dir.chdir @basedir
|
|
11
|
+
config_file = File.join(@basedir, "config.yml")
|
|
12
|
+
@config = YAML::load_file(config_file)
|
|
13
|
+
task_file = File.join(@basedir, "task.yml")
|
|
14
|
+
@tasks = YAML::load_file(task_file)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
after :each do
|
|
18
|
+
logfile = File.join("logs", "zrc.log")
|
|
19
|
+
File.unlink(logfile) if File.exists?(logfile)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "initialize the client object" do
|
|
23
|
+
@zrc = ZabbixRubyClient::Runner.new(@config, @tasks)
|
|
24
|
+
expect(@zrc.instance_variable_get(:@config)['host']).to eq 'localhost'
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "creates dirs if needed" do
|
|
28
|
+
@zrc = ZabbixRubyClient::Runner.new(@config, @tasks)
|
|
29
|
+
expect(Dir.exists? "logs").to be_true
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
pending "loads list of plugins"
|
|
33
|
+
pending "initialize datafile according to config"
|
|
34
|
+
pending "stores data in datafile"
|
|
35
|
+
pending "issues the upload command according to config"
|
|
36
|
+
|
|
37
|
+
end
|
data/spec/spec_helper.rb
CHANGED
data/zabbix-ruby-client.gemspec
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: zabbix-ruby-client
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.16
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- mose
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2013-10-
|
|
11
|
+
date: 2013-10-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: thor
|
|
@@ -66,6 +66,20 @@ dependencies:
|
|
|
66
66
|
- - '>='
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
68
|
version: '0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: coveralls
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - '>='
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - '>='
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
69
83
|
description: A zabbix alternative to zabbix-agent using zabbix-sender.
|
|
70
84
|
email:
|
|
71
85
|
- mose@mose.com
|
|
@@ -74,7 +88,9 @@ executables:
|
|
|
74
88
|
extensions: []
|
|
75
89
|
extra_rdoc_files: []
|
|
76
90
|
files:
|
|
91
|
+
- .coveralls.yml
|
|
77
92
|
- .gitignore
|
|
93
|
+
- .travis.yml
|
|
78
94
|
- CHANGELOG.md
|
|
79
95
|
- Gemfile
|
|
80
96
|
- LICENSE.txt
|
|
@@ -98,14 +114,19 @@ files:
|
|
|
98
114
|
- lib/zabbix-ruby-client/plugins/redis.rb
|
|
99
115
|
- lib/zabbix-ruby-client/plugins/sysinfo.rb
|
|
100
116
|
- lib/zabbix-ruby-client/plugins/who.rb
|
|
117
|
+
- lib/zabbix-ruby-client/runner.rb
|
|
101
118
|
- lib/zabbix-ruby-client/store.rb
|
|
102
119
|
- lib/zabbix-ruby-client/version.rb
|
|
103
120
|
- spec/files/config.yml
|
|
104
|
-
- spec/files/
|
|
105
|
-
- spec/files/
|
|
106
|
-
- spec/files/plugins/
|
|
107
|
-
- spec/files/
|
|
108
|
-
- spec/files/
|
|
121
|
+
- spec/files/data/.gitkeep
|
|
122
|
+
- spec/files/logs/.gitkeep
|
|
123
|
+
- spec/files/plugins/sample.rb
|
|
124
|
+
- spec/files/system/apache_status
|
|
125
|
+
- spec/files/system/iostat_disk
|
|
126
|
+
- spec/files/system/mpstat
|
|
127
|
+
- spec/files/system/netstat
|
|
128
|
+
- spec/files/system/vmstat
|
|
129
|
+
- spec/files/task.yml
|
|
109
130
|
- spec/lib/cli_spec.rb
|
|
110
131
|
- spec/lib/data_spec.rb
|
|
111
132
|
- spec/lib/logger_spec.rb
|
|
@@ -115,8 +136,8 @@ files:
|
|
|
115
136
|
- spec/lib/plugins/memory_spec.rb
|
|
116
137
|
- spec/lib/plugins/network_spec.rb
|
|
117
138
|
- spec/lib/plugins_spec.rb
|
|
139
|
+
- spec/lib/runner_spec.rb
|
|
118
140
|
- spec/lib/store_spec.rb
|
|
119
|
-
- spec/lib/zabbix-ruby-client_spec.rb
|
|
120
141
|
- spec/spec_helper.rb
|
|
121
142
|
- templates/client/Gemfile
|
|
122
143
|
- templates/client/config.yml
|
|
@@ -165,11 +186,15 @@ summary: This tool is intended to use zabbix sender to propagate monitoring data
|
|
|
165
186
|
Zabbix server.
|
|
166
187
|
test_files:
|
|
167
188
|
- spec/files/config.yml
|
|
168
|
-
- spec/files/
|
|
169
|
-
- spec/files/
|
|
170
|
-
- spec/files/plugins/
|
|
171
|
-
- spec/files/
|
|
172
|
-
- spec/files/
|
|
189
|
+
- spec/files/data/.gitkeep
|
|
190
|
+
- spec/files/logs/.gitkeep
|
|
191
|
+
- spec/files/plugins/sample.rb
|
|
192
|
+
- spec/files/system/apache_status
|
|
193
|
+
- spec/files/system/iostat_disk
|
|
194
|
+
- spec/files/system/mpstat
|
|
195
|
+
- spec/files/system/netstat
|
|
196
|
+
- spec/files/system/vmstat
|
|
197
|
+
- spec/files/task.yml
|
|
173
198
|
- spec/lib/cli_spec.rb
|
|
174
199
|
- spec/lib/data_spec.rb
|
|
175
200
|
- spec/lib/logger_spec.rb
|
|
@@ -179,6 +204,6 @@ test_files:
|
|
|
179
204
|
- spec/lib/plugins/memory_spec.rb
|
|
180
205
|
- spec/lib/plugins/network_spec.rb
|
|
181
206
|
- spec/lib/plugins_spec.rb
|
|
207
|
+
- spec/lib/runner_spec.rb
|
|
182
208
|
- spec/lib/store_spec.rb
|
|
183
|
-
- spec/lib/zabbix-ruby-client_spec.rb
|
|
184
209
|
- spec/spec_helper.rb
|
|
@@ -1,16 +0,0 @@
|
|
|
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
|