zabbix-ruby-client 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.ruby-version +1 -1
  4. data/.travis.yml +2 -1
  5. data/CHANGELOG.md +6 -0
  6. data/Gemfile +4 -0
  7. data/README.md +19 -15
  8. data/bin/zrc +0 -1
  9. data/lib/zabbix-ruby-client.rb +1 -1
  10. data/lib/zabbix-ruby-client/plugin_base.rb +23 -0
  11. data/lib/zabbix-ruby-client/plugins/apache.rb +1 -1
  12. data/lib/zabbix-ruby-client/plugins/apt.rb +9 -7
  13. data/lib/zabbix-ruby-client/plugins/cpu.rb +51 -16
  14. data/lib/zabbix-ruby-client/plugins/disk.rb +25 -5
  15. data/lib/zabbix-ruby-client/plugins/load.rb +17 -6
  16. data/lib/zabbix-ruby-client/plugins/memory.rb +33 -11
  17. data/lib/zabbix-ruby-client/plugins/mysql.rb +1 -1
  18. data/lib/zabbix-ruby-client/plugins/mysqlcommand.rb +1 -1
  19. data/lib/zabbix-ruby-client/plugins/network.rb +42 -12
  20. data/lib/zabbix-ruby-client/plugins/nginx.rb +0 -1
  21. data/lib/zabbix-ruby-client/plugins/ovpn.rb +0 -1
  22. data/lib/zabbix-ruby-client/plugins/postgres.rb +1 -1
  23. data/lib/zabbix-ruby-client/plugins/rabbitmq.rb +1 -5
  24. data/lib/zabbix-ruby-client/plugins/redis.rb +1 -1
  25. data/lib/zabbix-ruby-client/plugins/sysinfo.rb +7 -4
  26. data/lib/zabbix-ruby-client/plugins/who.rb +1 -1
  27. data/lib/zabbix-ruby-client/runner.rb +2 -1
  28. data/lib/zabbix-ruby-client/version.rb +1 -1
  29. data/spec/lib/plugins/apache_spec.rb +1 -0
  30. data/spec/lib/plugins/apt_spec.rb +1 -0
  31. data/spec/lib/plugins/disk_spec.rb +2 -1
  32. data/spec/lib/plugins/load_spec.rb +1 -0
  33. data/spec/lib/plugins/memory_spec.rb +1 -0
  34. data/spec/lib/plugins/network_spec.rb +12 -19
  35. data/zabbix-ruby-client.gemspec +5 -5
  36. metadata +17 -18
  37. data/Gemfile.lock +0 -63
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f6ca5d569fa5a14fcd429f4a4715dbf40dd59c0a
4
- data.tar.gz: e923105d8540ebea6479448c03d434c6075fa7b7
3
+ metadata.gz: ae11e177a0af9d4fd221a5307c23d1eb5814970e
4
+ data.tar.gz: 1a00c8fe85a8bf88c1365e81b24665c7a89fcf0e
5
5
  SHA512:
6
- metadata.gz: f596cc9dee5ab9ccf630e82c77b7644dc247bea00a42ed3db8d0b680fba98dd01b573cda616a3217d444770ef31d462a8567bd22fe41576663cdab4f98f10698
7
- data.tar.gz: 4849799d77077d96ff27385ceaaa1fd867106c7786f4057e5ac989af09945b97af881aeee74f1ddd1d13c0320b28bdff53fbf492985ce83693abf0da4ac61fd4
6
+ metadata.gz: 577d25f30dde3a56348b3e4dd5f14afbdd44d45d96f3ce600f583d5033c58b6b5382403ae62988f9b5493fbd07ac648e97fb549111a1dd1af874daee90b0c497
7
+ data.tar.gz: 929b686a26cfd82ea258c36dbeeaada49369d93d041a9617bc92526f8f4d1dcf61dd3a21193c2b8e76a057d66e21d3be57c64e3a8f7bdc67eca4396b05ce6c38
data/.gitignore CHANGED
@@ -11,6 +11,7 @@ spec/reports
11
11
  test/tmp
12
12
  test/version_tmp
13
13
  tmp
14
+ Gemfile.lock
14
15
  .settings
15
16
  vendor/ruby
16
17
  zrc-*
@@ -1 +1 @@
1
- 2.1
1
+ 2.3
@@ -1,5 +1,6 @@
1
1
  language: ruby
2
2
  cache: bundler
3
+ sudo: false
3
4
  rvm:
4
5
  - 1.9.3
5
- - 2.1.1
6
+ - 2.3.0
@@ -1,6 +1,12 @@
1
1
  Zabbbix Ruby Client Changelog
2
2
  -----------------------------
3
3
 
4
+ ### v0.1.3 - 2016-07-06
5
+ - update dependencies
6
+ - prepare an OS detection system for plugins (to support FreeBSD)
7
+ - fix a compatibility issue with zabbix sender 3.x
8
+ - experimental support for FreeBSD
9
+
4
10
  ### v0.1.2 - 2015-01-26
5
11
  - compat with zabbix_sender 2.4 (temporary fix, requires more investigation)
6
12
  - fix cpu and apache zabbix templates for zabbix 2.4
data/Gemfile CHANGED
@@ -2,3 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in zabbix-ruby-client.gemspec
4
4
  gemspec
5
+
6
+ group :test do
7
+ gem 'rake'
8
+ end
data/README.md CHANGED
@@ -12,7 +12,7 @@ Zabbix Ruby Client
12
12
 
13
13
  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.
14
14
 
15
- The development is still in progress but it produces results and works in production for Faria since fall 2013. Use at your own risk and read the code first. It works with ruby 1.9.3 to 2.1.2.
15
+ The development is still in progress but it produces results and works in production for Faria since fall 2013. Use at your own risk and read the code first. It works with ruby 1.9.3 to 2.3.
16
16
 
17
17
  Check the [Changelog](CHANGELOG.md) for recent changes.
18
18
 
@@ -86,29 +86,29 @@ Here is an example setup using the files generated by the init:
86
86
 
87
87
  There are a set of standart plugins included in the package, aimed at linux systems.
88
88
 
89
- * **debian/ubuntu** system stats ([system_tpl](master/zabbix-templates/system_tpl.xml) includes the following)
90
- * **load** (uses /proc/loadavg) [load_tpl](master/zabbix-templates/load_tpl.xml)
91
- * **cpu** (uses /proc/stat) [cpu_tpl](master/zabbix-templates/cpu_tpl.xml)
92
- * **memory** (uses /proc/meminfo) [memory_tpl](master/zabbix-templates/memory_tpl.xml)
93
- * **disk** (uses /proc/diskstats) [disk_tpl](master/zabbix-templates/disk_tpl.xml)
94
- * args [ "md-0", "/", "vgebs" ] = group identifier, mountpoint, groupname where identifier is what is found in /proc/diskstats, and groupname is something found in df command. The mount point will be used as label.
95
- * **network** (uses /proc/net/dev) [network_tpl](master/zabbix-templates/network_tpl.xml)
89
+ * **debian/ubuntu** system stats ([system_tpl](zabbix-templates/system_tpl.xml) includes the following)
90
+ * **load** (uses /proc/loadavg) [load_tpl](zabbix-templates/load_tpl.xml)
91
+ * **cpu** (uses /proc/stat or iostat -c) [cpu_tpl](zabbix-templates/cpu_tpl.xml)
92
+ * **memory** (uses /proc/meminfo) [memory_tpl](zabbix-templates/memory_tpl.xml)
93
+ * **disk** (uses /proc/diskstats) [disk_tpl](zabbix-templates/disk_tpl.xml)
94
+ * args [ "md-0", "/", "vgebs" ] = group identifier, mountpoint, groupname where identifier is what is found in /proc/diskstats (or iostat for FreeBSD), and groupname is something found in df command. The mount point will be used as label.
95
+ * **network** (uses /proc/net/dev) [network_tpl](zabbix-templates/network_tpl.xml)
96
96
  * args [ eth0 ] is just the interface identifier
97
97
  * **apt** (uses ubuntu /usr/lib/update-notifier/apt-check) this one will populate the 'tag' field in host info, and is supposed to run every few hours or at least not every minute [apt_tpl](master/zabbix-templates/apt_tpl.xml)
98
98
  * for debian, `apt-get install update-notifier-common`
99
99
  * **sysinfo** (uses uname -a) is populating the host info in the inventory, and should be ran at setup and/or monthly [sysinfo_tpl](master/zabbix-templates/sysinfo_tpl.xml)
100
- * **apache** (depends on mod_status with status_extended on) [apache_tpl](master/zabbix-templates/apache_tpl.xml)
101
- * **mysql** (uses mysqladmin extended-status) [mysql_tpl](master/zabbix-templates/mysql_tpl.xml)
100
+ * **apache** (depends on mod_status with status_extended on) [apache_tpl](zabbix-templates/apache_tpl.xml)
101
+ * **mysql** (uses mysqladmin extended-status) [mysql_tpl](zabbix-templates/mysql_tpl.xml)
102
102
  * **postgres** (uses psql and pg_stat_database) [postgres_tpl](master/zabbix-templates/postgres_tpl.xml)
103
103
  * best is to use a .pgpass file see http://www.postgresql.org/docs/9.0/interactive/libpq-pgpass.html
104
- * **nginx** (requires httpStubStatus nginx module) [nginx_tpl](master/zabbix-templates/nginx_tpl.xml)
105
- * **redis** (uses redis-cli info) [redis_tpl](master/zabbix-templates/redis_tpl.xml)
104
+ * **nginx** (requires httpStubStatus nginx module) [nginx_tpl](zabbix-templates/nginx_tpl.xml)
105
+ * **redis** (uses redis-cli info) [redis_tpl](zabbix-templates/redis_tpl.xml)
106
106
  * args [ "/path/to/redis-cli", "options to connect" ]
107
- * **openvpn** (uses /etc/openvpn/openvpn-status.log) [openvpn_tpl](master/zabbix-templates/openvpn_tpl.xml)
107
+ * **openvpn** (uses /etc/openvpn/openvpn-status.log) [openvpn_tpl](zabbix-templates/openvpn_tpl.xml)
108
108
  * args [ "/etc/openvpn/openvpn-status.log" ]
109
- * **cisco** (type ASA 5510) [cisco_tpl](master/zabbix-templates/cisco_tpl.xml)
109
+ * **cisco** (type ASA 5510) [cisco_tpl](zabbix-templates/cisco_tpl.xml)
110
110
  * uses a snmp setup
111
- * **RabbitMQ** (uses [rabbitmqadmin](http://www.rabbitmq.com/management-cli.html)) [rabbitmq_tpl](master/zabbix-templates/rabbitmq_tpl.xml)
111
+ * **RabbitMQ** (uses [rabbitmqadmin](http://www.rabbitmq.com/management-cli.html)) [rabbitmq_tpl](zabbix-templates/rabbitmq_tpl.xml)
112
112
  * args [ "/path/to/rabbitmqadmin", "login", "password" ]
113
113
  * **mysqlcommand** (uses arbitrary mysql commands to create custom items)
114
114
  * args [ "app_name", "dbname", "command_args", "command1_name", "command1_sql", "command2_name", "command2_sql" ]
@@ -192,7 +192,11 @@ After launching manual tunnels and ensuring their survival with monit I tried `a
192
192
  I first created on both sides an autossh user with no console and no password:
193
193
 
194
194
  ```
195
+ # on a linux system
195
196
  sudo useradd -m -r -s /bin/false -d /usr/local/zabtunnel zabtunnel
197
+
198
+ # or fopr FreeBSD
199
+ sudo pw adduser zabtunnel -g guest -d /usr/local/zabtunnel -s /nonexistent -c "Zabbix Tunnel user"
196
200
  ```
197
201
 
198
202
  On the zabbix server I created a key that I transfered to the clients in `/usr/local/zabtunnel/.ssh/authorized_keys`
data/bin/zrc CHANGED
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "zabbix-ruby-client/version"
4
3
  require "zabbix-ruby-client/cli"
5
4
 
6
5
  ZabbixRubyClient::Cli.start
@@ -1,6 +1,6 @@
1
- require "zabbix-ruby-client/version"
2
1
  require "zabbix-ruby-client/logger"
3
2
  require "zabbix-ruby-client/plugins"
3
+ require "zabbix-ruby-client/plugin_base"
4
4
  require "zabbix-ruby-client/store"
5
5
  require "zabbix-ruby-client/data"
6
6
  require "zabbix-ruby-client/runner"
@@ -1,3 +1,4 @@
1
+ require 'rbconfig'
1
2
  require "zabbix-ruby-client/logger"
2
3
 
3
4
  module ZabbixRubyClient
@@ -10,6 +11,28 @@ module ZabbixRubyClient
10
11
  def perform(command)
11
12
  end
12
13
 
14
+ def time
15
+ @_now ||= Time.now.to_i
16
+ end
17
+
18
+ def os
19
+ @_os ||= (
20
+ host_os = RbConfig::CONFIG['host_os']
21
+ case host_os
22
+ when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
23
+ :windows
24
+ when /darwin|mac os/
25
+ :macosx
26
+ when /linux/
27
+ :linux
28
+ when /solaris|bsd/
29
+ :unix
30
+ else
31
+ raise Error::WebDriverError, "unknown os: #{host_os.inspect}"
32
+ end
33
+ )
34
+ end
35
+
13
36
  def getline(file, pattern=false)
14
37
  if File.readable? file
15
38
  File.open(file,'r') do |f|
@@ -4,6 +4,7 @@ module ZabbixRubyClient
4
4
  module Plugins
5
5
  module Apache
6
6
  extend self
7
+ extend ZabbixRubyClient::PluginBase
7
8
 
8
9
  def collect(*args)
9
10
  host = args[0]
@@ -11,7 +12,6 @@ module ZabbixRubyClient
11
12
  ret['Score'] = get_scores(ret["Scoreboard"])
12
13
  ret.delete "Scoreboard"
13
14
 
14
- time = Time.now.to_i
15
15
  back = []
16
16
  back << "#{host} apache[TotalAccesses] #{time} #{ret["Total Accesses"]}"
17
17
  back << "#{host} apache[TotalKBytes] #{time} #{ret["Total kBytes"]}"
@@ -4,12 +4,12 @@ module ZabbixRubyClient
4
4
  module Plugins
5
5
  module Apt
6
6
  extend self
7
+ extend ZabbixRubyClient::PluginBase
7
8
 
8
9
  def collect(*args)
9
10
  host = args[0]
10
11
  info = get_info
11
12
  if info
12
- time = Time.now.to_i
13
13
  back = []
14
14
  back << "#{host} apt[security] #{time} #{info[0]}"
15
15
  back << "#{host} apt[pending] #{time} #{info[1]}"
@@ -23,12 +23,14 @@ module ZabbixRubyClient
23
23
  private
24
24
 
25
25
  def get_info
26
- info = aptinfo
27
- if info
28
- back = info.split(/;/).map(&:to_i)
29
- back
30
- else
31
- false
26
+ if os == :linux
27
+ info = aptinfo
28
+ if info
29
+ back = info.split(/;/).map(&:to_i)
30
+ back
31
+ else
32
+ false
33
+ end
32
34
  end
33
35
  end
34
36
 
@@ -14,7 +14,6 @@ module ZabbixRubyClient
14
14
  info = get_info
15
15
  back = []
16
16
  if info
17
- time = Time.now.to_i
18
17
  info.each do |k,v|
19
18
  back << "#{host} cpu[#{k}] #{time} #{v}"
20
19
  end
@@ -26,22 +25,58 @@ module ZabbixRubyClient
26
25
 
27
26
  def get_info
28
27
  ret = {}
29
- info = getline("/proc/stat", "^cpu ")
30
- if info
31
- back = info.split(/\s+/).map(&:to_i)
32
- ret["user"] = back[1]
33
- ret["nice"] = back[2]
34
- ret["system"] = back[3]
35
- ret["idle"] = back[4]
36
- ret["iowait"] = back[5]
37
- ret["irq"] = back[6]
38
- ret["soft"] = back[7]
39
- ret["steal"] = back[8] || 0
40
- ret["guest"] = back[9] || 0
41
- ret["used"] = back[1...4].reduce(&:+)
42
- ret["total"] = back[1...9].reduce(&:+)
43
- ret
28
+ case os
29
+ when :linux
30
+ info = getline("/proc/stat", "^cpu ")
31
+ if info
32
+ back = info.split(/\s+/).map(&:to_i)
33
+ ret["user"] = back[1]
34
+ ret["nice"] = back[2]
35
+ ret["system"] = back[3]
36
+ ret["idle"] = back[4]
37
+ ret["iowait"] = back[5]
38
+ ret["irq"] = back[6]
39
+ ret["soft"] = back[7]
40
+ ret["steal"] = back[8] || 0
41
+ ret["guest"] = back[9] || 0
42
+ ret["used"] = back[1...4].reduce(&:+)
43
+ ret["total"] = back[1...9].reduce(&:+)
44
+ ret
45
+ else
46
+ false
47
+ end
48
+ when :unix
49
+ info = iostat
50
+ if info
51
+ back = info.split(/\s+/).map(&:to_i)
52
+ ret["user"] = back[12]
53
+ ret["nice"] = back[13]
54
+ ret["system"] = back[14]
55
+ ret["idle"] = back[16]
56
+ ret["iowait"] = back[15]
57
+ ret["irq"] = 0
58
+ ret["soft"] = 0
59
+ ret["steal"] = 0
60
+ ret["guest"] = 0
61
+ ret["used"] = back[12..14].reduce(&:+)
62
+ ret["total"] = back[12..16].reduce(&:+)
63
+ ret
64
+ else
65
+ false
66
+ end
67
+ else
68
+ false
69
+ end
70
+ end
71
+
72
+ def iostat
73
+ output = `/usr/sbin/iostat -C | tail -n 1`
74
+ if $?.to_i == 0
75
+ Log.debug self
76
+ Log.debug output
77
+ output
44
78
  else
79
+ Log.warn "Oh there is no command."
45
80
  false
46
81
  end
47
82
  end
@@ -17,7 +17,6 @@ module ZabbixRubyClient
17
17
 
18
18
  info = get_info(dev, mapped)
19
19
  if info
20
- time = Time.now.to_i
21
20
  back = []
22
21
  back << "#{host} disk.space[#{mapped},size] #{time} #{to_m(info[1])}"
23
22
  back << "#{host} disk.space[#{mapped},used] #{time} #{to_m(info[2])}"
@@ -56,9 +55,30 @@ module ZabbixRubyClient
56
55
  info = diskinfo(device)
57
56
  if info
58
57
  back = info.split(/\s+/)
59
- io = getline("/proc/diskstats", " #{disk} ")
60
- if io
61
- back += io.split(/\s+/)
58
+ case os
59
+ when :linux
60
+ io = getline("/proc/diskstats", " #{disk} ")
61
+ if io
62
+ back += io.split(/\s+/)
63
+ end
64
+ when :unix
65
+ output = `iostat -x | grep "#{disk}"`
66
+ data = output.split(/\s+/)
67
+ back << 0 # --
68
+ back << 0 # --
69
+ back << 0 # --
70
+ back << data[3] # read_ok
71
+ back << 0 # read_merged
72
+ back << 0 # read_sector
73
+ back << 0 # read_time
74
+ back << data[4] # write_ok
75
+ back << 0 # write_merged
76
+ back << 0 # write_sector
77
+ back << 0 # write_time
78
+ back << 0 # io_time
79
+ back << 0 # io_merged
80
+ else
81
+ return false
62
82
  end
63
83
  back
64
84
  else
@@ -67,7 +87,7 @@ module ZabbixRubyClient
67
87
  end
68
88
 
69
89
  def diskinfo(disk)
70
- output = `df | grep "#{disk}"`
90
+ output = `df -k | grep "#{disk}"`
71
91
  if $?.to_i == 0
72
92
  Log.debug self
73
93
  Log.debug output
@@ -1,4 +1,4 @@
1
- # for more info check
1
+ # for more info check
2
2
  # http://juliano.info/en/Blog:Memory_Leak/Understanding_the_Linux_load_average
3
3
  require "zabbix-ruby-client/plugin_base"
4
4
 
@@ -12,7 +12,6 @@ module ZabbixRubyClient
12
12
  host = args[0]
13
13
  info = get_info
14
14
  if info
15
- time = Time.now.to_i
16
15
  back = []
17
16
  back << "#{host} load[one] #{time} #{info[0]}"
18
17
  back << "#{host} load[five] #{time} #{info[1]}"
@@ -27,10 +26,22 @@ module ZabbixRubyClient
27
26
  private
28
27
 
29
28
  def get_info
30
- info = getline("/proc/loadavg")
31
- if info
32
- back = info.split(/\s+/)
33
- back[3] = back[3].split(/\//)[0]
29
+ case os
30
+ when :linux
31
+ info = getline("/proc/loadavg")
32
+ if info
33
+ back = info.split(/\s+/)
34
+ back[3] = back[3].split(/\//)[0]
35
+ back
36
+ else
37
+ false
38
+ end
39
+ when :unix
40
+ output = `uptime | awk '{print $(NF-2)" "$(NF-1)" "$(NF-0)}' | tr "," " "`
41
+ back = output.split(/\s+/)
42
+ procs = `top -n | grep processes`
43
+ data = procs.split(/\s+/)
44
+ back << data[2]
34
45
  back
35
46
  else
36
47
  false
@@ -11,7 +11,6 @@ module ZabbixRubyClient
11
11
  host = args[0]
12
12
  info = get_info
13
13
  if info
14
- time = Time.now.to_i
15
14
  back = []
16
15
  back << "#{host} memory[total] #{time} #{info['MemTotal']}"
17
16
  back << "#{host} memory[free] #{time} #{info['MemFree']}"
@@ -30,16 +29,39 @@ module ZabbixRubyClient
30
29
  private
31
30
 
32
31
  def get_info
33
- info = meminfo
34
- if info
35
- back = splitinfo(info)
36
- back["MemTotal"] = back["MemTotal"] * 1024
37
- back["MemFree"] = (back['MemFree'] + back['Buffers'] + back['Cached']) * 1024
38
- back["MemUsed"] = back["MemTotal"] - back["MemFree"]
39
- back["MemPercent"] = (back["MemUsed"] / back["MemTotal"].to_f * 100).to_i
40
- back['SwapTotal'] = back['SwapTotal'] * 1024
41
- back['SwapFree'] = back['SwapFree'] * 1024
42
- back['SwapUsed'] = back['SwapTotal'] - back['SwapFree']
32
+ case os
33
+ when :linux
34
+ info = meminfo
35
+ if info
36
+ back = splitinfo(info)
37
+ back["MemTotal"] = back["MemTotal"] * 1024
38
+ back["MemFree"] = (back['MemFree'] + back['Buffers'] + back['Cached']) * 1024
39
+ back["MemUsed"] = back["MemTotal"] - back["MemFree"]
40
+ back["MemPercent"] = (back["MemUsed"] / back["MemTotal"].to_f * 100).to_i
41
+ back['SwapTotal'] = back['SwapTotal'] * 1024
42
+ back['SwapFree'] = back['SwapFree'] * 1024
43
+ back['SwapUsed'] = back['SwapTotal'] - back['SwapFree']
44
+ back['SwapPercent'] = 0
45
+ unless back['SwapTotal'] == 0
46
+ back['SwapPercent'] = (back['SwapUsed'] / back['SwapTotal'].to_f * 100).to_i
47
+ end
48
+ back
49
+ else
50
+ false
51
+ end
52
+ when :unix
53
+ memtotal = `sysctl hw.realmem | cut -d' ' -f2`.chop
54
+ memused = `sysctl hw.usermem | cut -d' ' -f2`.chop
55
+ swap = `swapinfo -k | tail -n 1`
56
+ _, _, swapused, swaptotal = *swap.split(/\s+/)
57
+ back = {}
58
+ back["MemTotal"] = memtotal
59
+ back["MemFree"] = memtotal.to_i - memused.to_i
60
+ back["MemUsed"] = memused
61
+ back["MemPercent"] = (memused.to_i / memtotal.to_f * 100).to_i
62
+ back['SwapTotal'] = swaptotal.to_i * 1024
63
+ back['SwapUsed'] = swapused.to_i * 1024
64
+ back['SwapFree'] = back['SwapTotal'] - back['SwapUsed']
43
65
  back['SwapPercent'] = 0
44
66
  unless back['SwapTotal'] == 0
45
67
  back['SwapPercent'] = (back['SwapUsed'] / back['SwapTotal'].to_f * 100).to_i
@@ -4,6 +4,7 @@ module ZabbixRubyClient
4
4
  module Plugins
5
5
  module Mysql
6
6
  extend self
7
+ extend ZabbixRubyClient::PluginBase
7
8
 
8
9
  def collect(*args)
9
10
  host = args[0]
@@ -16,7 +17,6 @@ module ZabbixRubyClient
16
17
  return []
17
18
  end
18
19
 
19
- time = Time.now.to_i
20
20
  back = []
21
21
  back << "#{host} mysql.status[Aborted_clients] #{time} #{status["Aborted_clients"]}"
22
22
  back << "#{host} mysql.status[Aborted_connects] #{time} #{status["Aborted_connects"]}"
@@ -4,6 +4,7 @@ module ZabbixRubyClient
4
4
  module Plugins
5
5
  module Mysqlcommand
6
6
  extend self
7
+ extend ZabbixRubyClient::PluginBase
7
8
 
8
9
  def collect(*args)
9
10
  host = args.shift
@@ -13,7 +14,6 @@ module ZabbixRubyClient
13
14
  mysqlcommand = "mysql #{mysqlargs} -s --skip-column-names -e \"%s\" #{mysqldb}"
14
15
  back = []
15
16
  Hash[*args].each do |name, command|
16
- time = Time.now.to_i
17
17
  comm = sprintf(mysqlcommand, command.gsub(/"/,'\"'))
18
18
  res = `#{comm}`
19
19
  if $?.to_i == 0
@@ -12,16 +12,15 @@ module ZabbixRubyClient
12
12
  interface = args[1]
13
13
  info = get_info(interface)
14
14
  if info
15
- time = Time.now.to_i
16
15
  back = []
17
- back << "#{host} net.rx_ok[#{interface}] #{time} #{info[1]}"
18
- back << "#{host} net.rx_packets[#{interface}] #{time} #{info[2]}"
19
- back << "#{host} net.rx_err[#{interface}] #{time} #{info[3]}"
20
- back << "#{host} net.rx_drop[#{interface}] #{time} #{info[4]}"
21
- back << "#{host} net.tx_ok[#{interface}] #{time} #{info[9]}"
22
- back << "#{host} net.tx_packets[#{interface}] #{time} #{info[10]}"
23
- back << "#{host} net.tx_err[#{interface}] #{time} #{info[11]}"
24
- back << "#{host} net.tx_drop[#{interface}] #{time} #{info[12]}"
16
+ back << "#{host} net.rx_ok[#{interface}] #{time} #{info[:rx_ok]}"
17
+ back << "#{host} net.rx_packets[#{interface}] #{time} #{info[:rx_packets]}"
18
+ back << "#{host} net.rx_err[#{interface}] #{time} #{info[:rx_err]}"
19
+ back << "#{host} net.rx_drop[#{interface}] #{time} #{info[:rx_drop]}"
20
+ back << "#{host} net.tx_ok[#{interface}] #{time} #{info[:tx_ok]}"
21
+ back << "#{host} net.tx_packets[#{interface}] #{time} #{info[:tx_packets]}"
22
+ back << "#{host} net.tx_err[#{interface}] #{time} #{info[:tx_err]}"
23
+ back << "#{host} net.tx_drop[#{interface}] #{time} #{info[:tx_drop]}"
25
24
  return back
26
25
  else
27
26
  return []
@@ -36,9 +35,40 @@ module ZabbixRubyClient
36
35
  private
37
36
 
38
37
  def get_info(interface)
39
- info = getline("/proc/net/dev", "#{interface}:")
40
- if info
41
- info.split(/\s+/)
38
+ back = {}
39
+ case os
40
+ when :linux
41
+ data = getline("/proc/net/dev", "#{interface}:")
42
+ if data
43
+ info = data.split(/\s+/)
44
+ back[:rx_ok] = info[1]
45
+ back[:rx_packets] = info[2]
46
+ back[:rx_err] = info[3]
47
+ back[:rx_drop] = info[4]
48
+ back[:tx_ok] = info[9]
49
+ back[:tx_packets] = info[10]
50
+ back[:tx_err] = info[11]
51
+ back[:tx_drop] = info[12]
52
+ return back
53
+ else
54
+ false
55
+ end
56
+ when :unix
57
+ data = `/usr/bin/netstat -i -b -n -I #{interface} | head -n 2 | tail -n 1`
58
+ if data
59
+ info = data.split(/\s+/)
60
+ back[:rx_ok] = info[7]
61
+ back[:rx_packets] = info[4]
62
+ back[:rx_err] = info[5].gsub(/-/, "0")
63
+ back[:rx_drop] = info[6].gsub(/-/, "0")
64
+ back[:tx_ok] = info[10]
65
+ back[:tx_packets] = info[8]
66
+ back[:tx_err] = info[9].gsub(/-/, "0")
67
+ back[:tx_drop] = info[11].gsub(/-/, "0")
68
+ return back
69
+ else
70
+ false
71
+ end
42
72
  else
43
73
  false
44
74
  end
@@ -11,7 +11,6 @@ module ZabbixRubyClient
11
11
  host = args[0]
12
12
  info = get_status
13
13
 
14
- time = Time.now.to_i
15
14
  back = []
16
15
  back << "#{host} nginx[total] #{time} #{info[:total]}"
17
16
  back << "#{host} nginx[reading] #{time} #{info[:reading]}"
@@ -14,7 +14,6 @@ module ZabbixRubyClient
14
14
  info = get_info(ovpnfile)
15
15
  back = []
16
16
  if info
17
- time = Time.now.to_i
18
17
  back << "#{host} ovpn[received] #{time} #{info['received']}"
19
18
  back << "#{host} ovpn[sent] #{time} #{info['sent']}"
20
19
  back << "#{host} ovpn[count] #{time} #{info['count']}"
@@ -4,6 +4,7 @@ module ZabbixRubyClient
4
4
  module Plugins
5
5
  module Postgres
6
6
  extend self
7
+ extend ZabbixRubyClient::PluginBase
7
8
 
8
9
  def collect(*args)
9
10
  host = args[0]
@@ -35,7 +36,6 @@ module ZabbixRubyClient
35
36
  return []
36
37
  end
37
38
 
38
- time = Time.now.to_i
39
39
  back = []
40
40
  status.each do |e,v|
41
41
  back << "#{host} postgres.#{e}[#{dbname}] #{time} #{v}"
@@ -10,14 +10,10 @@ module ZabbixRubyClient
10
10
  extend ZabbixRubyClient::PluginBase
11
11
 
12
12
  def collect(*args)
13
- host = args[0]
14
- rabbitmqadmin = args[1]
15
- login = args[2]
16
- pass = args[3]
13
+ host, rabbitmqadmin, login, pass = *args
17
14
  info = get_info(rabbitmqadmin, login, pass)
18
15
  back = []
19
16
  if info
20
- time = Time.now.to_i
21
17
  back << "#{host} rabbitmq.version #{time} #{info['rabbitmq_version']}"
22
18
  back << "#{host} rabbitmq.erlang.version #{time} #{info['erlang_version']}"
23
19
  %w(ack deliver deliver_get publish redeliver).each do |i|
@@ -5,6 +5,7 @@ module ZabbixRubyClient
5
5
  module Plugins
6
6
  module Redis
7
7
  extend self
8
+ extend ZabbixRubyClient::PluginBase
8
9
 
9
10
  def collect(*args)
10
11
  host = args[0]
@@ -20,7 +21,6 @@ module ZabbixRubyClient
20
21
 
21
22
  info[:keyspace_total] = info[:keyspace_hits].to_i + info[:keyspace_misses].to_i
22
23
 
23
- time = Time.now.to_i
24
24
  back = []
25
25
  back << "#{host} redis[role] #{time} #{info[:role]}"
26
26
  back << "#{host} redis[version] #{time} #{info[:redis_version]}"
@@ -4,18 +4,21 @@ module ZabbixRubyClient
4
4
  module Plugins
5
5
  module Sysinfo
6
6
  extend self
7
+ extend ZabbixRubyClient::PluginBase
7
8
 
8
9
  def collect(*args)
9
10
  host = args.delete_at(0)
10
11
  uname = `uname -a`
11
- if $?.to_i == 0
12
+ case os
13
+ when :linux
12
14
  arch, hostname, kernel, kernel_version, machine, os_debian,
13
- _, platform_debian, _, _, _, _, _, platform, os = uname.split(/ /)
15
+ _, platform_debian, _, _, _, _, _, platform, os = uname.split(/\s+/)
16
+ when :unix
17
+ os, hostname, _, platform, kernel, machine, kernel_version,
18
+ _, _, _, _, _, _, _, arch = uname.split(/\s+/)
14
19
  else
15
- Log.warn "Are you running on ubuntu ?"
16
20
  return []
17
21
  end
18
- time = Time.now.to_i
19
22
  back = []
20
23
  back << "#{host} sysinfo[name] #{time} #{host}"
21
24
  back << "#{host} sysinfo[arch] #{time} #{arch}"
@@ -4,6 +4,7 @@ module ZabbixRubyClient
4
4
  module Plugins
5
5
  module Who
6
6
  extend self
7
+ extend ZabbixRubyClient::PluginBase
7
8
 
8
9
  def collect(*args)
9
10
  host = args[0]
@@ -12,7 +13,6 @@ module ZabbixRubyClient
12
13
  Log.warn "Are you running on ubuntu ?"
13
14
  return []
14
15
  end
15
- time = Time.now.to_i
16
16
  back = []
17
17
  back << "#{host} who[total] #{time} #{who}"
18
18
  return back
@@ -24,6 +24,7 @@ module ZabbixRubyClient
24
24
  ZabbixRubyClient::Log.set_logger(File.join(@logsdir, 'zrc.log'), @config['loglevel'])
25
25
  ZabbixRubyClient::Log.debug @config.inspect
26
26
  @is_22 = /v2\.[24]\./.match zabbix_sender_version
27
+ @is_30 = /3\.[024]\./.match zabbix_sender_version
27
28
  ZabbixRubyClient::Log.debug "zabbix sender version #{zabbix_sender_version}"
28
29
  end
29
30
 
@@ -45,7 +46,7 @@ module ZabbixRubyClient
45
46
  ZabbixRubyClient::Log.debug command
46
47
  begin
47
48
  res = `#{command}`
48
- if @is_22
49
+ if @is_22 || @is_30
49
50
  case $?.to_i
50
51
  when 0
51
52
  ZabbixRubyClient::Log.debug "zabbix-sender: Data Sent (#{$?})"
@@ -1,3 +1,3 @@
1
1
  module ZabbixRubyClient
2
- VERSION ||= "0.1.2"
2
+ VERSION ||= "0.1.3"
3
3
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'spec_helper'
4
4
  require 'webmock/rspec'
5
+ require "zabbix-ruby-client/plugin_base"
5
6
  require "zabbix-ruby-client/plugins"
6
7
  ZabbixRubyClient::Plugins.scan_dirs ["zabbix-ruby-client/plugins"]
7
8
  require "zabbix-ruby-client/plugins/apache"
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require 'spec_helper'
4
+ require "zabbix-ruby-client/plugin_base"
4
5
  require "zabbix-ruby-client/plugins"
5
6
  ZabbixRubyClient::Plugins.scan_dirs ["zabbix-ruby-client/plugins"]
6
7
  require "zabbix-ruby-client/plugins/apt"
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require 'spec_helper'
4
+ require "zabbix-ruby-client/plugin_base"
4
5
  require "zabbix-ruby-client/plugins"
5
6
  ZabbixRubyClient::Plugins.scan_dirs ["zabbix-ruby-client/plugins"]
6
7
  require "zabbix-ruby-client/plugins/disk"
@@ -17,7 +18,7 @@ describe ZabbixRubyClient::Plugins::Disk do
17
18
  end
18
19
 
19
20
  it "launches a command to get disk space" do
20
- expect(ZabbixRubyClient::Plugins::Disk).to receive(:`).with('df | grep "xx"')
21
+ expect(ZabbixRubyClient::Plugins::Disk).to receive(:`).with('df -k | grep "xx"')
21
22
  ZabbixRubyClient::Plugins::Disk.send(:diskinfo, 'xx')
22
23
  end
23
24
 
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require 'spec_helper'
4
+ require "zabbix-ruby-client/plugin_base"
4
5
  require "zabbix-ruby-client/plugins"
5
6
  ZabbixRubyClient::Plugins.scan_dirs ["zabbix-ruby-client/plugins"]
6
7
  require "zabbix-ruby-client/plugins/load"
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require 'spec_helper'
4
+ require "zabbix-ruby-client/plugin_base"
4
5
  require "zabbix-ruby-client/plugins"
5
6
  ZabbixRubyClient::Plugins.scan_dirs ["zabbix-ruby-client/plugins"]
6
7
  require "zabbix-ruby-client/plugins/memory"
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require 'spec_helper'
4
+ require "zabbix-ruby-client/plugin_base"
4
5
  require "zabbix-ruby-client/plugins"
5
6
  ZabbixRubyClient::Plugins.scan_dirs ["zabbix-ruby-client/plugins"]
6
7
  require "zabbix-ruby-client/plugins/network"
@@ -18,25 +19,17 @@ describe ZabbixRubyClient::Plugins::Network do
18
19
  end
19
20
 
20
21
  it "prepare data to be usable" do
21
- expected = [
22
- "eth0:",
23
- "8523363858",
24
- "17554648",
25
- "0",
26
- "0",
27
- "0",
28
- "0",
29
- "0",
30
- "589997",
31
- "2479556217",
32
- "15780062",
33
- "0",
34
- "0",
35
- "0",
36
- "0",
37
- "0",
38
- "0"
39
- ]
22
+ expected = {
23
+ :rx_drop => "0",
24
+ :rx_err => "0",
25
+ :rx_ok => "8523363858",
26
+ :rx_packets => "17554648",
27
+ :tx_drop => "0",
28
+ :tx_err => "0",
29
+ :tx_ok => "2479556217",
30
+ :tx_packets => "15780062"
31
+ }
32
+
40
33
  stubfile = File.expand_path('../../../../spec/files/system/net_dev', __FILE__)
41
34
  allow(ZabbixRubyClient::Plugins::Network).to receive(:getline).and_return(File.read(stubfile))
42
35
  data = ZabbixRubyClient::Plugins::Network.send(:get_info, 'eth0')
@@ -5,7 +5,7 @@ require 'zabbix-ruby-client/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "zabbix-ruby-client"
8
- spec.version = ZabbixRubyClient::VERSION
8
+ spec.version = File.read(File.expand_path('../CHANGELOG.md', __FILE__))[/([0-9]+\.[0-9]+\.[0-9]+)/]
9
9
  spec.authors = ["mose"]
10
10
  spec.email = ["mose@mose.com"]
11
11
  spec.description = %q{A zabbix alternative to zabbix-agent using zabbix-sender.}
@@ -18,11 +18,11 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^spec/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "thor"
21
+ spec.add_dependency "thor", "~> 0.19"
22
22
 
23
- spec.add_development_dependency "bundler", "~> 1.3"
24
- spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.4"
25
25
  spec.add_development_dependency "rspec", "~> 3.0"
26
- spec.add_development_dependency "webmock"
26
+ spec.add_development_dependency "webmock", "~> 1.20"
27
27
  spec.add_development_dependency "coveralls"
28
28
  end
metadata CHANGED
@@ -1,57 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zabbix-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - mose
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-26 00:00:00.000000000 Z
11
+ date: 2016-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '0.19'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '0.19'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.3'
33
+ version: '1.7'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.3'
40
+ version: '1.7'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '10.4'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '10.4'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: webmock
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: '1.20'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: '1.20'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: coveralls
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -109,7 +109,6 @@ files:
109
109
  - CHANGELOG.md
110
110
  - Gemfile
111
111
  - Gemfile-packaging
112
- - Gemfile.lock
113
112
  - LICENSE.txt
114
113
  - README.md
115
114
  - Rakefile
@@ -223,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
223
222
  version: '0'
224
223
  requirements: []
225
224
  rubyforge_project:
226
- rubygems_version: 2.4.5
225
+ rubygems_version: 2.5.1
227
226
  signing_key:
228
227
  specification_version: 4
229
228
  summary: This tool is intended to use zabbix sender to propagate monitoring data for
@@ -1,63 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- zabbix-ruby-client (0.1.2)
5
- thor
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- addressable (2.3.6)
11
- coveralls (0.7.1)
12
- multi_json (~> 1.3)
13
- rest-client
14
- simplecov (>= 0.7)
15
- term-ansicolor
16
- thor
17
- crack (0.4.2)
18
- safe_yaml (~> 1.0.0)
19
- diff-lcs (1.2.5)
20
- docile (1.1.5)
21
- mime-types (2.3)
22
- multi_json (1.10.1)
23
- netrc (0.7.7)
24
- rake (10.3.2)
25
- rest-client (1.7.2)
26
- mime-types (>= 1.16, < 3.0)
27
- netrc (~> 0.7)
28
- rspec (3.0.0)
29
- rspec-core (~> 3.0.0)
30
- rspec-expectations (~> 3.0.0)
31
- rspec-mocks (~> 3.0.0)
32
- rspec-core (3.0.4)
33
- rspec-support (~> 3.0.0)
34
- rspec-expectations (3.0.4)
35
- diff-lcs (>= 1.2.0, < 2.0)
36
- rspec-support (~> 3.0.0)
37
- rspec-mocks (3.0.4)
38
- rspec-support (~> 3.0.0)
39
- rspec-support (3.0.4)
40
- safe_yaml (1.0.3)
41
- simplecov (0.9.0)
42
- docile (~> 1.1.0)
43
- multi_json
44
- simplecov-html (~> 0.8.0)
45
- simplecov-html (0.8.0)
46
- term-ansicolor (1.3.0)
47
- tins (~> 1.0)
48
- thor (0.19.1)
49
- tins (1.3.2)
50
- webmock (1.18.0)
51
- addressable (>= 2.3.6)
52
- crack (>= 0.3.2)
53
-
54
- PLATFORMS
55
- ruby
56
-
57
- DEPENDENCIES
58
- bundler (~> 1.3)
59
- coveralls
60
- rake
61
- rspec (~> 3.0)
62
- webmock
63
- zabbix-ruby-client!