zabbix-ruby-client 0.0.20 → 0.0.21
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 +2 -1
- data/.ruby-version +1 -0
- data/CHANGELOG.md +10 -1
- data/README.md +7 -2
- data/lib/zabbix-ruby-client/plugin_base.rb +28 -0
- data/lib/zabbix-ruby-client/plugins/ovpn.rb +55 -0
- data/lib/zabbix-ruby-client/plugins/postgres.rb +45 -0
- data/lib/zabbix-ruby-client/runner.rb +11 -1
- data/lib/zabbix-ruby-client/version.rb +1 -1
- data/spec/files/system/net_dev +1 -1
- data/spec/lib/cli_spec.rb +7 -7
- data/spec/lib/data_spec.rb +5 -5
- data/spec/lib/plugin_base_spec.rb +6 -6
- data/spec/lib/plugins/apache_spec.rb +1 -1
- data/spec/lib/plugins/apt_spec.rb +5 -5
- data/spec/lib/plugins/cpu_spec.rb +3 -3
- data/spec/lib/plugins/disk_spec.rb +40 -40
- data/spec/lib/plugins/load_spec.rb +5 -5
- data/spec/lib/plugins/memory_spec.rb +52 -52
- data/spec/lib/plugins/network_spec.rb +28 -29
- data/spec/lib/runner_spec.rb +21 -8
- data/zabbix-templates/apache_tpl.xml +115 -46
- data/zabbix-templates/apt_tpl.xml +13 -4
- data/zabbix-templates/cisco_tpl.xml +2089 -0
- data/zabbix-templates/cpu_tpl.xml +116 -53
- data/zabbix-templates/disk_tpl.xml +75 -29
- data/zabbix-templates/load_tpl.xml +21 -9
- data/zabbix-templates/memory_tpl.xml +52 -28
- data/zabbix-templates/mysql_tpl.xml +70 -28
- data/zabbix-templates/network_tpl.xml +40 -96
- data/zabbix-templates/nginx_tpl.xml +37 -16
- data/zabbix-templates/openvpn_tpl.xml +312 -0
- data/zabbix-templates/postgres_tpl.xml +891 -8
- data/zabbix-templates/redis_tpl.xml +46 -19
- data/zabbix-templates/sysinfo_tpl.xml +21 -3
- data/zabbix-templates/system_tpl.xml +339 -3
- metadata +26 -42
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8b7c785e3e21c22e937319260db7d843e953c691
|
4
|
+
data.tar.gz: d768690cf80f157cca3cce5a154b67c147a721f9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3bc559deeca1dd30f9fe176c589ce6de10fe626556c5e1fe9bab2f6851e1409e0086037f951fd377358d861cd001d1960ae031b5c86db50c1e0297170aa894ba
|
7
|
+
data.tar.gz: 072cc243d2329ea0631148846f908407385b0913fa4735f3ea55e4565742aaaebf5b769a859043b2035114100f35c4393b12d84c6a29699443c22170533a1311
|
data/.gitignore
CHANGED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,15 @@
|
|
1
1
|
Zabbbix Ruby Client Changelog
|
2
2
|
-----------------------------
|
3
3
|
|
4
|
+
### v0.0.21 - 2014-08-01
|
5
|
+
|
6
|
+
* fix zabbix_sender return code 256
|
7
|
+
* update all templates with shorter history
|
8
|
+
* added a simple openvpn plugin + template
|
9
|
+
* small fix on network template
|
10
|
+
* improved postgres template
|
11
|
+
* add cisco template
|
12
|
+
|
4
13
|
### v0.0.20 - 2013-12-25
|
5
14
|
|
6
15
|
* fix network plugin
|
@@ -27,7 +36,7 @@ Zabbbix Ruby Client Changelog
|
|
27
36
|
|
28
37
|
### v0.0.16 - 2013-10-31
|
29
38
|
|
30
|
-
* _if you have custom plugins_ the class ZabbixRubyClient is now a module just for namespacing, update your code!
|
39
|
+
* _if you have custom plugins_ the class ZabbixRubyClient is now a module just for namespacing, update your code!
|
31
40
|
* fix the logger
|
32
41
|
* refactoring and more tests
|
33
42
|
* adding travis and coverall to stimulate testing, also added gemnasium
|
data/README.md
CHANGED
@@ -96,9 +96,12 @@ There are a set of standart plugins included in the package, aimed at linux syst
|
|
96
96
|
* nginx (requires httpStubStatus nginx module) [nginx_tpl](master/zabbix-templates/nginx_tpl.xml)
|
97
97
|
* redis (uses redis-cli info) [redis_tpl](master/zabbix-templates/redis_tpl.xml)
|
98
98
|
* args [ "/path/to/redis-cli", "options to connect" ]
|
99
|
+
* openvpn (uses /etc/openvpn/openvpn-status.log) [openvpn_tpl](master/zabbix-templates/openvpn_tpl.xml)
|
100
|
+
* args [ "/etc/openvpn/openvpn-status.log" ]
|
101
|
+
* cisco (type ASA 5510) [cisco_tpl](master/zabbix-templates/cisco_tpl.xml)
|
102
|
+
* uses a snmp setup
|
99
103
|
|
100
|
-
|
101
|
-
You can add extra plugins in a plugins/ dir in the working dir, just by copying one of the existing plugins in the repo and change to your need. All plugins present in plugins/ will be loaded if present in the config file you use. That can be convenient to test by using the -t flag, for example `bundle exec zrc -t testplugin.yml` where testplugin.yml only contains the name and args for yoiur plugin.
|
104
|
+
You can add extra plugins in a plugins/ dir in the working dir, just by copying one of the existing plugins in the repo and change to your need. All plugins present in plugins/ will be loaded if present in the config file you use. That can be convenient to test by using the -t flag, for example `bundle exec zrc -t testplugin.yml` where testplugin.yml only contains the name and args for your plugin.
|
102
105
|
|
103
106
|
## Custom plugins how-to
|
104
107
|
|
@@ -152,6 +155,8 @@ The zabbix ruby client has a pending system, that keeps the data if it was not s
|
|
152
155
|
|
153
156
|
## Note about security
|
154
157
|
|
158
|
+
*note: I switched to usage of OpenVPN for communication between all my servers, which is much better than ssh tunnels, but this setup described below still is useful*
|
159
|
+
|
155
160
|
As you may already know, Zabbix is not very concerned about securing exchanges between agent and server, or sender and server. A cautious sysadmin will then properly manage his setup using ssh tunneling.
|
156
161
|
|
157
162
|
After launching manual tunnels and ensuring their survival with monit I tried `autossh` which is much more reliable. It requires to have keys exchanged from server and client, in my case I prefer doing reverse tunnels from server, because I have some plan about doing a resend from client in case server didn't open the tunnel (in case of server reboot or network failure). That resend trick is not implemented yet though.
|
@@ -37,5 +37,33 @@ module ZabbixRubyClient
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
+
def getlines(file, pattern=false)
|
41
|
+
lines = []
|
42
|
+
if File.readable? file
|
43
|
+
File.open(file,'r') do |f|
|
44
|
+
f.each do |l|
|
45
|
+
line = l.strip
|
46
|
+
if pattern
|
47
|
+
if Regexp.new(pattern).match line
|
48
|
+
Log.debug "File #{file}: #{line}"
|
49
|
+
lines << line
|
50
|
+
end
|
51
|
+
else
|
52
|
+
lines << line
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
Log.warn "File #{file}: pattern \"#{pattern}\" not found." unless lines.count > 0
|
57
|
+
lines
|
58
|
+
else
|
59
|
+
if File.file? file
|
60
|
+
Log.error "File not readable: #{file}"
|
61
|
+
else
|
62
|
+
Log.error "File not found: #{file}"
|
63
|
+
end
|
64
|
+
false
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
40
68
|
end
|
41
69
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# read the /etc/openvpn/openvpn-status.log file
|
2
|
+
require "zabbix-ruby-client/logger"
|
3
|
+
require "zabbix-ruby-client/plugin_base"
|
4
|
+
|
5
|
+
module ZabbixRubyClient
|
6
|
+
module Plugins
|
7
|
+
module Ovpn
|
8
|
+
extend self
|
9
|
+
extend ZabbixRubyClient::PluginBase
|
10
|
+
|
11
|
+
def collect(*args)
|
12
|
+
host = args[0]
|
13
|
+
ovpnfile = args[1]
|
14
|
+
info = get_info(ovpnfile)
|
15
|
+
back = []
|
16
|
+
if info
|
17
|
+
time = Time.now.to_i
|
18
|
+
back << "#{host} ovpn[received] #{time} #{info['received']}"
|
19
|
+
back << "#{host} ovpn[sent] #{time} #{info['sent']}"
|
20
|
+
back << "#{host} ovpn[count] #{time} #{info['count']}"
|
21
|
+
end
|
22
|
+
back
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def get_info(ovpnfile)
|
28
|
+
ret = {}
|
29
|
+
info = getlines(ovpnfile, "[^,]*,[^,]*,.* [0-9]{4}")
|
30
|
+
if info
|
31
|
+
received = 0
|
32
|
+
sent = 0
|
33
|
+
count = 0
|
34
|
+
info.each do |line|
|
35
|
+
if line[0] =~ /^[a-z]/
|
36
|
+
back = line.split(',')
|
37
|
+
received += back[2].to_i
|
38
|
+
sent += back[3].to_i
|
39
|
+
count += 1
|
40
|
+
end
|
41
|
+
end
|
42
|
+
ret["received"] = received
|
43
|
+
ret["sent"] = sent
|
44
|
+
ret["count"] = count
|
45
|
+
ret
|
46
|
+
else
|
47
|
+
false
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
ZabbixRubyClient::Plugins.register('ovpn', ZabbixRubyClient::Plugins::Ovpn)
|
@@ -20,12 +20,32 @@ module ZabbixRubyClient
|
|
20
20
|
Log.warn "The connection failed."
|
21
21
|
return []
|
22
22
|
end
|
23
|
+
psqlactivity = `psql #{psqlargs} -A -t -c "select state, count(*) from pg_stat_activity group by state" #{dbname}`
|
24
|
+
if $?.to_i == 0
|
25
|
+
activity = get_activity(psqlactivity)
|
26
|
+
else
|
27
|
+
Log.warn "The connection failed."
|
28
|
+
return []
|
29
|
+
end
|
30
|
+
psqlwriter = `psql #{psqlargs} -A -t -c "select * from pg_stat_bgwriter" #{dbname}`
|
31
|
+
if $?.to_i == 0
|
32
|
+
writer = get_writer(psqlwriter)
|
33
|
+
else
|
34
|
+
Log.warn "The connection failed."
|
35
|
+
return []
|
36
|
+
end
|
23
37
|
|
24
38
|
time = Time.now.to_i
|
25
39
|
back = []
|
26
40
|
status.each do |e,v|
|
27
41
|
back << "#{host} postgres.#{e}[#{dbname}] #{time} #{v}"
|
28
42
|
end
|
43
|
+
activity.each do |e,v|
|
44
|
+
back << "#{host} postgres.connections.#{e} #{time} #{v}"
|
45
|
+
end
|
46
|
+
writer.each do |e,v|
|
47
|
+
back << "#{host} postgres.#{e} #{time} #{v}"
|
48
|
+
end
|
29
49
|
return back
|
30
50
|
end
|
31
51
|
|
@@ -56,6 +76,31 @@ module ZabbixRubyClient
|
|
56
76
|
ret
|
57
77
|
end
|
58
78
|
|
79
|
+
def get_activity(status)
|
80
|
+
ar = { "active" => "0", "idle" => "0", "idle_in_transaction" => "0"}
|
81
|
+
status.each_line.reduce([]) do |a,l|
|
82
|
+
els = l.split("|").map(&:strip)
|
83
|
+
ar[els[0].gsub(" ","_")] = els[1]
|
84
|
+
end
|
85
|
+
ar
|
86
|
+
end
|
87
|
+
|
88
|
+
def get_writer(status)
|
89
|
+
ret = {}
|
90
|
+
els = status.split "|"
|
91
|
+
ret["checkpoints_timed"] = els[1]
|
92
|
+
ret["checkpoints_req"] = els[1]
|
93
|
+
ret["checkpoint_write_time"] = els[2]
|
94
|
+
ret["checkpoint_sync_time"] = els[3]
|
95
|
+
ret["buffers_checkpoint"] = els[4]
|
96
|
+
ret["buffers_clean"] = els[5]
|
97
|
+
ret["maxwritten_clean"] = els[6]
|
98
|
+
ret["buffers_backend"] = els[7]
|
99
|
+
ret["buffers_backend_fsync"] = els[8]
|
100
|
+
ret["buffers_alloc"] = els[9]
|
101
|
+
ret
|
102
|
+
end
|
103
|
+
|
59
104
|
end
|
60
105
|
end
|
61
106
|
end
|
@@ -23,7 +23,6 @@ module ZabbixRubyClient
|
|
23
23
|
ZabbixRubyClient::Plugins.scan_dirs([ PLUGINDIR ] + @config['plugindirs'])
|
24
24
|
ZabbixRubyClient::Log.set_logger(File.join(@logsdir, 'zrc.log'), @config['loglevel'])
|
25
25
|
ZabbixRubyClient::Log.debug @config.inspect
|
26
|
-
zabbix_sender_version = `zabbix_sender -V | head -1`.split(/\s/)[2]
|
27
26
|
@is_22 = /v2\.2\./.match zabbix_sender_version
|
28
27
|
end
|
29
28
|
|
@@ -53,6 +52,10 @@ module ZabbixRubyClient
|
|
53
52
|
@store.keepdata(file)
|
54
53
|
ZabbixRubyClient::Log.error "zabbix-sender: Sending failed"
|
55
54
|
ZabbixRubyClient::Log.error res
|
55
|
+
when 256
|
56
|
+
@store.keepdata(file)
|
57
|
+
ZabbixRubyClient::Log.warn "zabbix-sender: shit happens (unknown code 256)"
|
58
|
+
ZabbixRubyClient::Log.warn res
|
56
59
|
when 512
|
57
60
|
ZabbixRubyClient::Log.warn "zabbix-sender: Some values failed"
|
58
61
|
ZabbixRubyClient::Log.warn res
|
@@ -84,5 +87,12 @@ module ZabbixRubyClient
|
|
84
87
|
dir
|
85
88
|
end
|
86
89
|
|
90
|
+
def zabbix_sender_version
|
91
|
+
v = `#{@config['zabbix']['sender']} -V &> /dev/null | head -1`
|
92
|
+
v.split(/\s/)[2]
|
93
|
+
rescue
|
94
|
+
false
|
95
|
+
end
|
96
|
+
|
87
97
|
end
|
88
98
|
end
|
data/spec/files/system/net_dev
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
eth0: 8523363858 17554648 0 0 0 0 0 589997 2479556217 15780062 0 0 0 0 0 0
|
data/spec/lib/cli_spec.rb
CHANGED
@@ -27,22 +27,22 @@ describe ZabbixRubyClient::Cli do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
it "init creates a working directory" do
|
30
|
-
expect(File.file? 'Gemfile').to
|
30
|
+
expect(File.file? 'Gemfile').to be_truthy
|
31
31
|
end
|
32
32
|
|
33
33
|
it "show displays the list of data collected" do
|
34
|
-
ZabbixRubyClient::Runner.
|
35
|
-
Object.
|
36
|
-
Object.
|
34
|
+
allow(ZabbixRubyClient::Runner).to receive(:new).and_return(Object)
|
35
|
+
allow(Object).to receive(:collect)
|
36
|
+
allow(Object).to receive(:show)
|
37
37
|
@cli.shell.mute do
|
38
38
|
@cli.show
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
it "upload collects and uploads the data from system" do
|
43
|
-
ZabbixRubyClient::Runner.
|
44
|
-
Object.
|
45
|
-
Object.
|
43
|
+
allow(ZabbixRubyClient::Runner).to receive(:new).and_return(Object)
|
44
|
+
allow(Object).to receive(:collect)
|
45
|
+
allow(Object).to receive(:upload)
|
46
46
|
@cli.shell.mute do
|
47
47
|
@cli.upload
|
48
48
|
end
|
data/spec/lib/data_spec.rb
CHANGED
@@ -33,7 +33,7 @@ describe ZabbixRubyClient::Data do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
it "logs an error when plugin is not found" do
|
36
|
-
ZabbixRubyClient::
|
36
|
+
allow(ZabbixRubyClient::Runner).to receive(:error).with("Plugin unknown_plugin not found.")
|
37
37
|
@data.run_plugin("unknown_plugin")
|
38
38
|
end
|
39
39
|
|
@@ -44,17 +44,17 @@ describe ZabbixRubyClient::Data do
|
|
44
44
|
end
|
45
45
|
|
46
46
|
it "ignores buggy plugins" do
|
47
|
-
expect(@data.run_plugin("sample_buggy")).to
|
47
|
+
expect(@data.run_plugin("sample_buggy")).to be_truthy
|
48
48
|
end
|
49
49
|
|
50
50
|
it "logs buggy plugins" do
|
51
|
-
ZabbixRubyClient::Log.
|
52
|
-
ZabbixRubyClient::Log.
|
51
|
+
allow(ZabbixRubyClient::Log).to receive(:fatal).with("Oops")
|
52
|
+
allow(ZabbixRubyClient::Log).to receive(:fatal).with("Exception")
|
53
53
|
@data.run_plugin("sample_buggy")
|
54
54
|
end
|
55
55
|
|
56
56
|
it "merges collected and discovered data" do
|
57
|
-
Time.
|
57
|
+
allow(Time).to receive(:now).and_return("123456789")
|
58
58
|
@data.run_plugin("sample")
|
59
59
|
@data.run_plugin("sample_discover")
|
60
60
|
result = ["host sample.discover 123456789 { \"data\": [ {\"{#SAMPLE}\": \"\"} ] }",
|
@@ -27,20 +27,20 @@ describe ZabbixRubyClient::PluginBase do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
it "logs a debug entry when it extracts a line from a file" do
|
30
|
-
expect(ZabbixRubyClient::Log).to receive(:debug).with("File #{@stubfile}: #{@expected_line}")
|
30
|
+
expect(ZabbixRubyClient::Log).to receive(:debug).with("File #{@stubfile}: #{@expected_line}")
|
31
31
|
ZabbixRubyClient::PluginBase.getline(@stubfile, "eth0: ")
|
32
32
|
end
|
33
33
|
|
34
34
|
it "logs a warn entry when a line is not found in a file" do
|
35
|
-
expect(ZabbixRubyClient::Log).to receive(:warn).with("File #{@stubfile}: pattern \" xxx \" not found.")
|
35
|
+
expect(ZabbixRubyClient::Log).to receive(:warn).with("File #{@stubfile}: pattern \" xxx \" not found.")
|
36
36
|
x = ZabbixRubyClient::PluginBase.getline(@stubfile, " xxx ")
|
37
|
-
expect(x).to
|
37
|
+
expect(x).to be_falsey
|
38
38
|
end
|
39
39
|
|
40
40
|
it "logs an error entry when a file is not found" do
|
41
41
|
expect(ZabbixRubyClient::Log).to receive(:error).with("File not found: /tmp/xxxxx")
|
42
42
|
x = ZabbixRubyClient::PluginBase.getline("/tmp/xxxxx", " xxx ")
|
43
|
-
expect(x).to
|
43
|
+
expect(x).to be_falsey
|
44
44
|
end
|
45
45
|
|
46
46
|
it "logs an error entry when a file is not readable" do
|
@@ -48,7 +48,7 @@ describe ZabbixRubyClient::PluginBase do
|
|
48
48
|
FileUtils.chmod 0300, "/tmp/xxxxx"
|
49
49
|
expect(ZabbixRubyClient::Log).to receive(:error).with("File not readable: /tmp/xxxxx")
|
50
50
|
x = ZabbixRubyClient::PluginBase.getline("/tmp/xxxxx", " xxx ")
|
51
|
-
expect(x).to
|
51
|
+
expect(x).to be_falsey
|
52
52
|
end
|
53
53
|
|
54
|
-
end
|
54
|
+
end
|
@@ -79,7 +79,7 @@ describe ZabbixRubyClient::Plugins::Apache do
|
|
79
79
|
it "collects data properly" do
|
80
80
|
stub_request(:get, '127.0.0.1:80/server-status?auto').
|
81
81
|
to_return({ :body => @data })
|
82
|
-
Time.
|
82
|
+
allow(Time).to receive(:now).and_return("123456789")
|
83
83
|
data = ZabbixRubyClient::Plugins::Apache.send(:collect, 'local')
|
84
84
|
expect(data).to eq @expected_data
|
85
85
|
end
|
@@ -24,20 +24,20 @@ describe ZabbixRubyClient::Plugins::Apt do
|
|
24
24
|
it "prepare data to be usable" do
|
25
25
|
expected = [23, 14]
|
26
26
|
stubfile = File.expand_path('../../../../spec/files/system/apt-check', __FILE__)
|
27
|
-
ZabbixRubyClient::Plugins::Apt.
|
27
|
+
allow(ZabbixRubyClient::Plugins::Apt).to receive(:aptinfo).and_return(File.read(stubfile))
|
28
28
|
data = ZabbixRubyClient::Plugins::Apt.send(:get_info)
|
29
29
|
expect(data).to eq expected
|
30
30
|
end
|
31
31
|
|
32
32
|
it "populate a hash with extracted data" do
|
33
33
|
expected = [
|
34
|
-
"local apt[security] 123456789 23",
|
35
|
-
"local apt[pending] 123456789 14",
|
34
|
+
"local apt[security] 123456789 23",
|
35
|
+
"local apt[pending] 123456789 14",
|
36
36
|
"local apt[status] 123456789 TODO apt 23/14"
|
37
37
|
]
|
38
38
|
stubfile = File.expand_path('../../../../spec/files/system/apt-check', __FILE__)
|
39
|
-
ZabbixRubyClient::Plugins::Apt.
|
40
|
-
Time.
|
39
|
+
allow(ZabbixRubyClient::Plugins::Apt).to receive(:aptinfo).and_return(File.read(stubfile))
|
40
|
+
allow(Time).to receive(:now).and_return("123456789")
|
41
41
|
data = ZabbixRubyClient::Plugins::Apt.send(:collect, 'local')
|
42
42
|
expect(data).to eq expected
|
43
43
|
end
|
@@ -32,7 +32,7 @@ describe ZabbixRubyClient::Plugins::Cpu do
|
|
32
32
|
"total" => 193453420
|
33
33
|
}
|
34
34
|
stubfile = File.expand_path('../../../../spec/files/system/proc_cpu', __FILE__)
|
35
|
-
ZabbixRubyClient::Plugins::Cpu.
|
35
|
+
allow(ZabbixRubyClient::Plugins::Cpu).to receive(:getline).and_return(File.read(stubfile))
|
36
36
|
data = ZabbixRubyClient::Plugins::Cpu.send(:get_info)
|
37
37
|
expect(data).to eq expected
|
38
38
|
end
|
@@ -52,8 +52,8 @@ describe ZabbixRubyClient::Plugins::Cpu do
|
|
52
52
|
"local cpu[total] 123456789 193453420"
|
53
53
|
]
|
54
54
|
stubfile = File.expand_path('../../../../spec/files/system/proc_cpu', __FILE__)
|
55
|
-
ZabbixRubyClient::Plugins::Cpu.
|
56
|
-
Time.
|
55
|
+
allow(ZabbixRubyClient::Plugins::Cpu).to receive(:getline).and_return(File.read(stubfile))
|
56
|
+
allow(Time).to receive(:now).and_return("123456789")
|
57
57
|
data = ZabbixRubyClient::Plugins::Cpu.send(:collect, 'local')
|
58
58
|
expect(data).to eq expected
|
59
59
|
end
|
@@ -6,7 +6,7 @@ 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
|
9
|
-
|
9
|
+
|
10
10
|
before :all do
|
11
11
|
@logfile = File.expand_path("../../files/logs/spec.log", __FILE__)
|
12
12
|
ZabbixRubyClient::Log.set_logger(@logfile)
|
@@ -23,58 +23,58 @@ describe ZabbixRubyClient::Plugins::Disk do
|
|
23
23
|
|
24
24
|
it "prepare data to be usable" do
|
25
25
|
expected = [
|
26
|
-
"/dev/sda2",
|
27
|
-
"288238944",
|
28
|
-
"76560212",
|
29
|
-
"197013928",
|
30
|
-
"28%",
|
31
|
-
"/home",
|
32
|
-
"",
|
33
|
-
"8",
|
34
|
-
"1",
|
35
|
-
"sda1",
|
36
|
-
"974243",
|
37
|
-
"695335",
|
38
|
-
"37526290",
|
39
|
-
"4648644",
|
40
|
-
"711455",
|
41
|
-
"785503",
|
42
|
-
"27660904",
|
43
|
-
"11097172",
|
44
|
-
"0",
|
45
|
-
"6283844",
|
26
|
+
"/dev/sda2",
|
27
|
+
"288238944",
|
28
|
+
"76560212",
|
29
|
+
"197013928",
|
30
|
+
"28%",
|
31
|
+
"/home",
|
32
|
+
"",
|
33
|
+
"8",
|
34
|
+
"1",
|
35
|
+
"sda1",
|
36
|
+
"974243",
|
37
|
+
"695335",
|
38
|
+
"37526290",
|
39
|
+
"4648644",
|
40
|
+
"711455",
|
41
|
+
"785503",
|
42
|
+
"27660904",
|
43
|
+
"11097172",
|
44
|
+
"0",
|
45
|
+
"6283844",
|
46
46
|
"15744924"
|
47
47
|
]
|
48
48
|
stubfile_df = File.expand_path('../../../../spec/files/system/df', __FILE__)
|
49
49
|
stubfile_io = File.expand_path('../../../../spec/files/system/diskstats', __FILE__)
|
50
|
-
ZabbixRubyClient::Plugins::Disk.
|
51
|
-
ZabbixRubyClient::Plugins::Disk.
|
50
|
+
allow(ZabbixRubyClient::Plugins::Disk).to receive(:diskinfo).and_return(File.read(stubfile_df))
|
51
|
+
allow(ZabbixRubyClient::Plugins::Disk).to receive(:getline).and_return(File.read(stubfile_io))
|
52
52
|
data = ZabbixRubyClient::Plugins::Disk.send(:get_info, 0, 0)
|
53
53
|
expect(data).to eq expected
|
54
54
|
end
|
55
55
|
|
56
56
|
it "populate a hash with extracted data" do
|
57
57
|
expected = [
|
58
|
-
"local disk.space[xxx,size] 123456789 288238944000",
|
59
|
-
"local disk.space[xxx,used] 123456789 76560212000",
|
60
|
-
"local disk.space[xxx,available] 123456789 197013928000",
|
61
|
-
"local disk.space[xxx,percent_used] 123456789 28",
|
62
|
-
"local disk.io[xxx,read_ok] 123456789 sda1",
|
63
|
-
"local disk.io[xxx,read_merged] 123456789 974243",
|
64
|
-
"local disk.io[xxx,read_sector] 123456789 695335",
|
65
|
-
"local disk.io[xxx,read_time] 123456789 37526290",
|
66
|
-
"local disk.io[xxx,write_ok] 123456789 4648644",
|
67
|
-
"local disk.io[xxx,write_merged] 123456789 711455",
|
68
|
-
"local disk.io[xxx,write_sector] 123456789 785503",
|
69
|
-
"local disk.io[xxx,write_time] 123456789 27660904",
|
70
|
-
"local disk.io[xxx,io_time] 123456789 11097172",
|
58
|
+
"local disk.space[xxx,size] 123456789 288238944000",
|
59
|
+
"local disk.space[xxx,used] 123456789 76560212000",
|
60
|
+
"local disk.space[xxx,available] 123456789 197013928000",
|
61
|
+
"local disk.space[xxx,percent_used] 123456789 28",
|
62
|
+
"local disk.io[xxx,read_ok] 123456789 sda1",
|
63
|
+
"local disk.io[xxx,read_merged] 123456789 974243",
|
64
|
+
"local disk.io[xxx,read_sector] 123456789 695335",
|
65
|
+
"local disk.io[xxx,read_time] 123456789 37526290",
|
66
|
+
"local disk.io[xxx,write_ok] 123456789 4648644",
|
67
|
+
"local disk.io[xxx,write_merged] 123456789 711455",
|
68
|
+
"local disk.io[xxx,write_sector] 123456789 785503",
|
69
|
+
"local disk.io[xxx,write_time] 123456789 27660904",
|
70
|
+
"local disk.io[xxx,io_time] 123456789 11097172",
|
71
71
|
"local disk.io[xxx,io_weighted] 123456789 0"
|
72
72
|
]
|
73
73
|
stubfile_df = File.expand_path('../../../../spec/files/system/df', __FILE__)
|
74
74
|
stubfile_io = File.expand_path('../../../../spec/files/system/diskstats', __FILE__)
|
75
|
-
ZabbixRubyClient::Plugins::Disk.
|
76
|
-
ZabbixRubyClient::Plugins::Disk.
|
77
|
-
Time.
|
75
|
+
allow(ZabbixRubyClient::Plugins::Disk).to receive(:diskinfo).and_return(File.read(stubfile_df))
|
76
|
+
allow(ZabbixRubyClient::Plugins::Disk).to receive(:getline).and_return(File.read(stubfile_io))
|
77
|
+
allow(Time).to receive(:now).and_return("123456789")
|
78
78
|
data = ZabbixRubyClient::Plugins::Disk.send(:collect, 'local', 'xxx', 'xxx')
|
79
79
|
expect(data).to eq expected
|
80
80
|
end
|
@@ -85,4 +85,4 @@ describe ZabbixRubyClient::Plugins::Disk do
|
|
85
85
|
expect(data).to eq expected
|
86
86
|
end
|
87
87
|
|
88
|
-
end
|
88
|
+
end
|
@@ -19,21 +19,21 @@ describe ZabbixRubyClient::Plugins::Load do
|
|
19
19
|
it "prepare data to be usable" do
|
20
20
|
expected = ["0.89", "1.29", "1.05", "2", "2768"]
|
21
21
|
stubfile = File.expand_path('../../../../spec/files/system/loadavg', __FILE__)
|
22
|
-
ZabbixRubyClient::Plugins::Load.
|
22
|
+
allow(ZabbixRubyClient::Plugins::Load).to receive(:getline).and_return(File.read(stubfile).strip)
|
23
23
|
data = ZabbixRubyClient::Plugins::Load.send(:get_info)
|
24
24
|
expect(data).to eq expected
|
25
25
|
end
|
26
26
|
|
27
27
|
it "populate a hash with extracted data" do
|
28
28
|
expected = [
|
29
|
-
"local load[one] 123456789 0.89",
|
29
|
+
"local load[one] 123456789 0.89",
|
30
30
|
"local load[five] 123456789 1.29",
|
31
|
-
"local load[fifteen] 123456789 1.05",
|
31
|
+
"local load[fifteen] 123456789 1.05",
|
32
32
|
"local load[procs] 123456789 2"
|
33
33
|
]
|
34
34
|
stubfile = File.expand_path('../../../../spec/files/system/loadavg', __FILE__)
|
35
|
-
ZabbixRubyClient::Plugins::Load.
|
36
|
-
Time.
|
35
|
+
allow(ZabbixRubyClient::Plugins::Load).to receive(:getline).and_return(File.read(stubfile))
|
36
|
+
allow(Time).to receive(:now).and_return("123456789")
|
37
37
|
data = ZabbixRubyClient::Plugins::Load.send(:collect, 'local')
|
38
38
|
expect(data).to eq expected
|
39
39
|
end
|