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.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -1
  3. data/.ruby-version +1 -0
  4. data/CHANGELOG.md +10 -1
  5. data/README.md +7 -2
  6. data/lib/zabbix-ruby-client/plugin_base.rb +28 -0
  7. data/lib/zabbix-ruby-client/plugins/ovpn.rb +55 -0
  8. data/lib/zabbix-ruby-client/plugins/postgres.rb +45 -0
  9. data/lib/zabbix-ruby-client/runner.rb +11 -1
  10. data/lib/zabbix-ruby-client/version.rb +1 -1
  11. data/spec/files/system/net_dev +1 -1
  12. data/spec/lib/cli_spec.rb +7 -7
  13. data/spec/lib/data_spec.rb +5 -5
  14. data/spec/lib/plugin_base_spec.rb +6 -6
  15. data/spec/lib/plugins/apache_spec.rb +1 -1
  16. data/spec/lib/plugins/apt_spec.rb +5 -5
  17. data/spec/lib/plugins/cpu_spec.rb +3 -3
  18. data/spec/lib/plugins/disk_spec.rb +40 -40
  19. data/spec/lib/plugins/load_spec.rb +5 -5
  20. data/spec/lib/plugins/memory_spec.rb +52 -52
  21. data/spec/lib/plugins/network_spec.rb +28 -29
  22. data/spec/lib/runner_spec.rb +21 -8
  23. data/zabbix-templates/apache_tpl.xml +115 -46
  24. data/zabbix-templates/apt_tpl.xml +13 -4
  25. data/zabbix-templates/cisco_tpl.xml +2089 -0
  26. data/zabbix-templates/cpu_tpl.xml +116 -53
  27. data/zabbix-templates/disk_tpl.xml +75 -29
  28. data/zabbix-templates/load_tpl.xml +21 -9
  29. data/zabbix-templates/memory_tpl.xml +52 -28
  30. data/zabbix-templates/mysql_tpl.xml +70 -28
  31. data/zabbix-templates/network_tpl.xml +40 -96
  32. data/zabbix-templates/nginx_tpl.xml +37 -16
  33. data/zabbix-templates/openvpn_tpl.xml +312 -0
  34. data/zabbix-templates/postgres_tpl.xml +891 -8
  35. data/zabbix-templates/redis_tpl.xml +46 -19
  36. data/zabbix-templates/sysinfo_tpl.xml +21 -3
  37. data/zabbix-templates/system_tpl.xml +339 -3
  38. metadata +26 -42
@@ -6,7 +6,7 @@ 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
9
-
9
+
10
10
 
11
11
  before :all do
12
12
  @logfile = File.expand_path("../../files/logs/spec.log", __FILE__)
@@ -24,71 +24,71 @@ describe ZabbixRubyClient::Plugins::Memory do
24
24
 
25
25
  it "prepare data to be usable" do
26
26
  expected = {
27
- "MemTotal"=>4229570560,
28
- "MemFree"=>685416448,
29
- "Buffers"=>59116,
30
- "Cached"=>385776,
31
- "SwapCached"=>204968,
32
- "Active"=>2664148,
33
- "Inactive"=>883200,
34
- "Unevictable"=>212,
35
- "Mlocked"=>212,
36
- "HighTotal"=>3280520,
37
- "HighFree"=>41136,
38
- "LowTotal"=>849920,
39
- "LowFree"=>183324,
40
- "SwapTotal"=>5999050752,
41
- "SwapFree"=>3666022400,
42
- "Dirty"=>532,
43
- "Writeback"=>0,
44
- "AnonPages"=>3002480,
45
- "Mapped"=>278560,
46
- "Shmem"=>110636,
47
- "Slab"=>92716,
48
- "SReclaimable"=>60300,
49
- "SUnreclaim"=>32416,
50
- "KernelStack"=>7752,
51
- "PageTables"=>49584,
52
- "NFS_Unstable"=>0,
53
- "Bounce"=>0,
54
- "WritebackTmp"=>0,
55
- "CommitLimit"=>7923668,
56
- "Committed_AS"=>15878488,
57
- "VmallocTotal"=>122880,
58
- "VmallocUsed"=>49400,
59
- "VmallocChunk"=>66212,
60
- "HardwareCorrupted"=>0,
61
- "AnonHugePages"=>0,
62
- "Hugepagesize"=>2048,
63
- "DirectMap4k"=>851960,
64
- "DirectMap2M"=>61440,
65
- "MemUsed"=>3544154112,
66
- "MemPercent"=>83,
67
- "SwapUsed"=>2333028352,
27
+ "MemTotal"=>4229570560,
28
+ "MemFree"=>685416448,
29
+ "Buffers"=>59116,
30
+ "Cached"=>385776,
31
+ "SwapCached"=>204968,
32
+ "Active"=>2664148,
33
+ "Inactive"=>883200,
34
+ "Unevictable"=>212,
35
+ "Mlocked"=>212,
36
+ "HighTotal"=>3280520,
37
+ "HighFree"=>41136,
38
+ "LowTotal"=>849920,
39
+ "LowFree"=>183324,
40
+ "SwapTotal"=>5999050752,
41
+ "SwapFree"=>3666022400,
42
+ "Dirty"=>532,
43
+ "Writeback"=>0,
44
+ "AnonPages"=>3002480,
45
+ "Mapped"=>278560,
46
+ "Shmem"=>110636,
47
+ "Slab"=>92716,
48
+ "SReclaimable"=>60300,
49
+ "SUnreclaim"=>32416,
50
+ "KernelStack"=>7752,
51
+ "PageTables"=>49584,
52
+ "NFS_Unstable"=>0,
53
+ "Bounce"=>0,
54
+ "WritebackTmp"=>0,
55
+ "CommitLimit"=>7923668,
56
+ "Committed_AS"=>15878488,
57
+ "VmallocTotal"=>122880,
58
+ "VmallocUsed"=>49400,
59
+ "VmallocChunk"=>66212,
60
+ "HardwareCorrupted"=>0,
61
+ "AnonHugePages"=>0,
62
+ "Hugepagesize"=>2048,
63
+ "DirectMap4k"=>851960,
64
+ "DirectMap2M"=>61440,
65
+ "MemUsed"=>3544154112,
66
+ "MemPercent"=>83,
67
+ "SwapUsed"=>2333028352,
68
68
  "SwapPercent"=>38
69
69
  }
70
70
  stubfile = File.expand_path('../../../../spec/files/system/meminfo', __FILE__)
71
- ZabbixRubyClient::Plugins::Memory.stub(:meminfo).and_return(File.read(stubfile))
71
+ allow(ZabbixRubyClient::Plugins::Memory).to receive(:meminfo).and_return(File.read(stubfile))
72
72
  data = ZabbixRubyClient::Plugins::Memory.send(:get_info)
73
73
  expect(data).to eq expected
74
74
  end
75
75
 
76
76
  it "populate a hash with extracted data" do
77
77
  expected = [
78
- "local memory[total] 123456789 4229570560",
78
+ "local memory[total] 123456789 4229570560",
79
79
  "local memory[free] 123456789 685416448",
80
- "local memory[used] 123456789 3544154112",
81
- "local memory[percent_used] 123456789 83",
82
- "local memory[swap_total] 123456789 5999050752",
83
- "local memory[swap_free] 123456789 3666022400",
84
- "local memory[swap_used] 123456789 2333028352",
80
+ "local memory[used] 123456789 3544154112",
81
+ "local memory[percent_used] 123456789 83",
82
+ "local memory[swap_total] 123456789 5999050752",
83
+ "local memory[swap_free] 123456789 3666022400",
84
+ "local memory[swap_used] 123456789 2333028352",
85
85
  "local memory[swap_percent_used] 123456789 38"
86
86
  ]
87
87
  stubfile = File.expand_path('../../../../spec/files/system/meminfo', __FILE__)
88
- ZabbixRubyClient::Plugins::Memory.stub(:meminfo).and_return(File.read(stubfile))
89
- Time.stub(:now).and_return("123456789")
88
+ allow(ZabbixRubyClient::Plugins::Memory).to receive(:meminfo).and_return(File.read(stubfile))
89
+ allow(Time).to receive(:now).and_return("123456789")
90
90
  data = ZabbixRubyClient::Plugins::Memory.send(:collect, 'local')
91
91
  expect(data).to eq expected
92
92
  end
93
93
 
94
- end
94
+ end
@@ -6,7 +6,7 @@ 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
9
-
9
+
10
10
 
11
11
  before :all do
12
12
  @logfile = File.expand_path("../../files/logs/spec.log", __FILE__)
@@ -19,45 +19,44 @@ describe ZabbixRubyClient::Plugins::Network do
19
19
 
20
20
  it "prepare data to be usable" do
21
21
  expected = [
22
- "",
23
- "eth0:",
24
- "8523363858",
25
- "17554648",
26
- "0",
27
- "0",
28
- "0",
29
- "0",
30
- "0",
31
- "589997",
32
- "2479556217",
33
- "15780062",
34
- "0",
35
- "0",
36
- "0",
37
- "0",
38
- "0",
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",
39
38
  "0"
40
39
  ]
41
40
  stubfile = File.expand_path('../../../../spec/files/system/net_dev', __FILE__)
42
- ZabbixRubyClient::Plugins::Network.stub(:getline).and_return(File.read(stubfile))
41
+ allow(ZabbixRubyClient::Plugins::Network).to receive(:getline).and_return(File.read(stubfile))
43
42
  data = ZabbixRubyClient::Plugins::Network.send(:get_info, 'eth0')
44
43
  expect(data).to eq expected
45
44
  end
46
45
 
47
46
  it "populate a hash with extracted data" do
48
47
  expected = [
49
- "local net.rx_ok[eth0] 123456789 8523363858",
50
- "local net.rx_packets[eth0] 123456789 17554648",
51
- "local net.rx_err[eth0] 123456789 0",
52
- "local net.rx_drop[eth0] 123456789 0",
53
- "local net.tx_ok[eth0] 123456789 2479556217",
54
- "local net.tx_packets[eth0] 123456789 15780062",
55
- "local net.tx_err[eth0] 123456789 0",
48
+ "local net.rx_ok[eth0] 123456789 8523363858",
49
+ "local net.rx_packets[eth0] 123456789 17554648",
50
+ "local net.rx_err[eth0] 123456789 0",
51
+ "local net.rx_drop[eth0] 123456789 0",
52
+ "local net.tx_ok[eth0] 123456789 2479556217",
53
+ "local net.tx_packets[eth0] 123456789 15780062",
54
+ "local net.tx_err[eth0] 123456789 0",
56
55
  "local net.tx_drop[eth0] 123456789 0"
57
56
  ]
58
57
  stubfile = File.expand_path('../../../../spec/files/system/net_dev', __FILE__)
59
- ZabbixRubyClient::Plugins::Network.stub(:getline).and_return(File.read(stubfile))
60
- Time.stub(:now).and_return("123456789")
58
+ allow(ZabbixRubyClient::Plugins::Network).to receive(:getline).and_return(File.read(stubfile))
59
+ allow(Time).to receive(:now).and_return("123456789")
61
60
  data = ZabbixRubyClient::Plugins::Network.send(:collect, 'local', 'eth0')
62
61
  expect(data).to eq expected
63
62
  end
@@ -68,4 +67,4 @@ describe ZabbixRubyClient::Plugins::Network do
68
67
  expect(data).to eq expected
69
68
  end
70
69
 
71
- end
70
+ end
@@ -5,28 +5,41 @@ require "zabbix-ruby-client"
5
5
 
6
6
  describe ZabbixRubyClient::Runner do
7
7
 
8
+ let(:config) { {
9
+ 'datadir' => 'data',
10
+ 'logsdir' => 'logs',
11
+ 'plugindirs' => [ 'plugins' ],
12
+ 'keepdata' => false,
13
+ 'host' => 'localhost',
14
+ 'taskfile' => nil,
15
+ 'zabbix' => {
16
+ 'host' => 'localhost',
17
+ 'sender' => '/bin/true'
18
+ }
19
+ } }
20
+ let(:tasks) { {
21
+ 'name' => 'sysinfo'
22
+ } }
23
+
8
24
  before :each do
9
25
  @basedir = File.expand_path("../../files", __FILE__)
10
26
  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
27
  end
16
28
 
17
29
  after :each do
18
- logfile = File.join("logs", "zrc.log")
30
+ logfile = File.join(config['logsdir'], "zrc.log")
19
31
  File.unlink(logfile) if File.exists?(logfile)
32
+ FileUtils.rmdir(config['logsdir']) if Dir.exists?(config['logsdir'])
20
33
  end
21
34
 
22
35
  it "initialize the client object" do
23
- @zrc = ZabbixRubyClient::Runner.new(@config, @tasks)
36
+ @zrc = ZabbixRubyClient::Runner.new(config, tasks)
24
37
  expect(@zrc.instance_variable_get(:@config)['host']).to eq 'localhost'
25
38
  end
26
39
 
27
40
  it "creates dirs if needed" do
28
- @zrc = ZabbixRubyClient::Runner.new(@config, @tasks)
29
- expect(Dir.exists? "logs").to be_true
41
+ @zrc = ZabbixRubyClient::Runner.new(config, tasks)
42
+ expect(Dir.exists? "logs").to be_truthy
30
43
  end
31
44
 
32
45
  pending "loads list of plugins"