zabbix-ruby-client 0.0.8 → 0.0.9

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.
data/CHANGELOG.md CHANGED
@@ -1,6 +1,15 @@
1
1
  Zabbbix Ruby Client Changelog
2
2
  -----------------------------
3
3
 
4
+ ### v0.0.9 - wip
5
+
6
+ * split configuration to have several upload frequencies
7
+ * added a -t option for specifying the list of plugins to run, default minutely.yml
8
+ * handled compatibility with previous configuration that includes list of plugins in config.yml
9
+ * added a sysinfo plugin for populating the hosts informations, including arbitrary information declared as plugin arguments
10
+ * started a mysql plugin but this one is not ready yet
11
+ * added an apt plugin to get the pending apt upgrades
12
+
4
13
  ### v0.0.8 - 2013-09-28
5
14
 
6
15
  * adding load stats
data/README.md CHANGED
@@ -29,10 +29,12 @@ Install it yourself as:
29
29
  bundle exec zrc
30
30
  # to list available commands
31
31
 
32
- bundle exec zrc show
32
+ bundle exec zrc show
33
33
  # to test the data collection
34
34
 
35
- And when ready just install a cron task according to your environment
35
+ ## Setting up cronjobs
36
+
37
+ When ready just install a cron task according to your environment
36
38
 
37
39
  echo '* * * * * /bin/bash -lc "cd /path/to/zrc && bundle exec zrc upload"' | crontab
38
40
  # or
@@ -40,16 +42,28 @@ And when ready just install a cron task according to your environment
40
42
  # or
41
43
  echo '* * * * * /bin/zsh -c "export RBENV_ROOT=/usr/local/var/rbenv && eval \"$(rbenv init - zsh)\" && cd /path/to/zrc && bundle exec zrc upload"' | crontab
42
44
 
45
+ By default `zrc show` and `zrc upload` will read config.yml (for the general config) and minutely.yml (for the list of plugins to run).
46
+
47
+ You can use -c to specify another config file, and -t to use another list of plugins. The `zrc init` command will create sample minutely.yml, hourly.yml and monthly.yml but you can create any arbitrary list of plugins, that can be used in your cronjobs.
48
+
49
+ Here is an example setup using the files generated by the init:
50
+
51
+ * * * * * /bin/zsh -c ". $HOME/.rvm/scripts/rvm && cd $HOME/zrc && bundle exec zrc upload"
52
+ 0 */6 * * * /bin/zsh -c ". $HOME/.rvm/scripts/rvm && cd $HOME/zrc && bundle exec zrc upload -t hourly.yml"
53
+ 0 0 1 * * /bin/zsh -c ". $HOME/.rvm/scripts/rvm && cd $HOME/zrc && bundle exec zrc upload -t monthly.yml"
54
+
43
55
  ## plugins
44
56
 
45
57
  There are a set of standart plugins included in the package, aimed at linux systems.
46
58
 
47
- * linux system stats ([system_tpl](master/zabbix-templates/system_tpl.xml) includes the floowing)
59
+ * ubuntu system stats ([system_tpl](master/zabbix-templates/system_tpl.xml) includes the following)
48
60
  * load (uses /proc/loadavg) [load_tpl](master/zabbix-templates/load_tpl.xml)
49
61
  * cpu (uses /proc/stat) [cpu_tpl](master/zabbix-templates/cpu_tpl.xml)
50
62
  * memory (requires iostat, apt-get install sysstat) [memory_tpl](master/zabbix-templates/memory_tpl.xml)
51
63
  * disk (uses /proc/diskstats) [disk_tpl](master/zabbix-templates/disk_tpl.xml)
52
64
  * network (uses /proc/net/dev) [network_tpl](master/zabbix-templates/network_tpl.xml)
65
+ * 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)
66
+ * 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)
53
67
  * apache (depends on mod_status with status_extended on) [apache_tpl](master/zabbix-templates/apache_tpl.xml)
54
68
 
55
69
  You can add extra plugin directories in the configuration file.
@@ -70,7 +84,7 @@ You can add extra plugin directories in the configuration file.
70
84
  * postfix
71
85
  * sendgrid
72
86
  * airbrake
73
- * disk occupation
87
+ * disk occupation (done)
74
88
  * try to work out a way to create host/graphs/alerts from the client using Zabbix API
75
89
  * verify compatibility with ruby 1.9
76
90
 
@@ -5,9 +5,14 @@ require "yaml"
5
5
 
6
6
  class ZabbixRubyClient
7
7
 
8
- def initialize(config_file)
8
+ def initialize(config_file,task_file)
9
9
  begin
10
10
  @config ||= YAML::load_file(config_file)
11
+ if File.exists? task_file
12
+ @tasks ||= YAML::load_file(task_file)
13
+ else
14
+ @tasks = @config["plugins"]
15
+ end
11
16
  rescue Exception => e
12
17
  puts "Configuration file cannot be read"
13
18
  puts e.message
@@ -55,7 +60,7 @@ class ZabbixRubyClient
55
60
  end
56
61
 
57
62
  def collect
58
- @config['plugins'].each do |plugin|
63
+ @tasks.each do |plugin|
59
64
  run_plugin(plugin['name'], plugin['args'])
60
65
  end
61
66
  end
@@ -16,6 +16,11 @@ class ZabbixRubyClient
16
16
  banner: "PATH",
17
17
  default: File.expand_path("config.yml", Dir.pwd),
18
18
  desc: "Path to the configuration file to use"
19
+ class_option :taskfile,
20
+ aliases: "-t",
21
+ banner: "PATH",
22
+ default: File.expand_path("minutely.yml", Dir.pwd),
23
+ desc: "Path to the list of plugins to execute"
19
24
 
20
25
  desc "init", "Initialize a new zabbix ruby client"
21
26
  def init(name = "zabbix-ruby-client")
@@ -30,18 +35,18 @@ class ZabbixRubyClient
30
35
  say "No Gemfile found", :red
31
36
  abort
32
37
  end
33
- zrc = ZabbixRubyClient.new(options[:configfile])
38
+ zrc = ZabbixRubyClient.new(options[:configfile],options[:taskfile])
34
39
  zrc.collect
35
40
  zrc.show
36
41
  end
37
42
 
38
43
  desc "upload", "Collects and sends data to the zabbix server"
39
44
  def upload
40
- zrc = ZabbixRubyClient.new(options[:configfile])
45
+ zrc = ZabbixRubyClient.new(options[:configfile],options[:taskfile])
41
46
  zrc.collect
42
47
  zrc.upload
43
48
  end
44
49
 
45
50
  end
46
51
 
47
- end
52
+ end
@@ -0,0 +1,28 @@
1
+ class ZabbixRubyClient
2
+ module Plugins
3
+ module Apt
4
+ extend self
5
+
6
+ def collect(*args)
7
+ host = args[0]
8
+ aptcheck = `/usr/lib/update-notifier/apt-check 2>&1`
9
+ if $?.to_i == 0
10
+ security, pending = aptcheck.split(/;/).map(&:to_i)
11
+ else
12
+ logger.warn "Are you running on ubuntu ?"
13
+ return []
14
+ end
15
+ time = Time.now.to_i
16
+ back = []
17
+ back << "#{host} apt[security] #{time} #{security}"
18
+ back << "#{host} apt[pending] #{time} #{pending}"
19
+ back << "#{host} apt[status] #{time} TODO apt #{security}/#{pending}"
20
+ return back
21
+ end
22
+
23
+ end
24
+ end
25
+ end
26
+
27
+ ZabbixRubyClient::Plugins.register('apt', ZabbixRubyClient::Plugins::Apt)
28
+
@@ -10,6 +10,7 @@ class ZabbixRubyClient
10
10
  def collect(*args)
11
11
  host = args[0]
12
12
  dev = args[1]
13
+ mapped = args[2] || dev
13
14
  diskinfo = `cat /proc/diskstats | grep " #{dev} "`
14
15
  if $?.to_i == 0
15
16
  _, _, _, _, read_ok, read_merged, read_sector, read_time, write_ok, write_merged, write_sector, write_time, io_current, io_time, io_weighted = diskinfo.split(/\s+/)
@@ -17,7 +18,7 @@ class ZabbixRubyClient
17
18
  logger.warn "Please install sysstat."
18
19
  return []
19
20
  end
20
- diskspace = `df | grep "#{dev}"`
21
+ diskspace = `df | grep "#{mapped}"`
21
22
  if $?.to_i == 0
22
23
  _, size, used, available, percent_used, mount = diskspace.split(/\s+/)
23
24
  else
@@ -0,0 +1,27 @@
1
+ class ZabbixRubyClient
2
+ module Plugins
3
+ module Mysql
4
+ extend self
5
+
6
+ def collect(*args)
7
+ host = args[0]
8
+ aptcheck = `/usr/lib/update-notifier/apt-check 2>&1`
9
+ if $?.to_i == 0
10
+ security, pending = aptcheck.split(/;/).map(&:to_i)
11
+ else
12
+ logger.warn "Are you running on ubuntu ?"
13
+ return []
14
+ end
15
+ time = Time.now.to_i
16
+ back = []
17
+ back << "#{host} mysql[security] #{time} #{security}"
18
+ back << "#{host} mysql[pending] #{time} #{pending}"
19
+ return back
20
+ end
21
+
22
+ end
23
+ end
24
+ end
25
+
26
+ ZabbixRubyClient::Plugins.register('mysql', ZabbixRubyClient::Plugins::Mysql)
27
+
@@ -0,0 +1,37 @@
1
+ class ZabbixRubyClient
2
+ module Plugins
3
+ module Sysinfo
4
+ extend self
5
+
6
+ def collect(*args)
7
+ host = args.delete_at(0)
8
+ uname = `uname -a`
9
+ if $?.to_i == 0
10
+ arch, hostname, kernel, kernel_version, machine, proc,
11
+ _, _, _, _, _, _, _, platform, os = uname.split(/ /)
12
+ else
13
+ logger.warn "Are you running on ubuntu ?"
14
+ return []
15
+ end
16
+ time = Time.now.to_i
17
+ back = []
18
+ back << "#{host} sysinfo[name] #{time} #{host}"
19
+ back << "#{host} sysinfo[arch] #{time} #{arch}"
20
+ back << "#{host} sysinfo[hostname] #{time} #{hostname}"
21
+ back << "#{host} sysinfo[kernel] #{time} #{kernel}"
22
+ back << "#{host} sysinfo[kernel_version] #{time} #{kernel_version}"
23
+ back << "#{host} sysinfo[machine] #{time} #{machine}"
24
+ back << "#{host} sysinfo[platform] #{time} #{platform}"
25
+ back << "#{host} sysinfo[os] #{time} #{os}"
26
+ Hash[*args].each do |k,v|
27
+ back << "#{host} sysinfo[#{k}] #{time} #{v}"
28
+ end
29
+ return back
30
+ end
31
+
32
+ end
33
+ end
34
+ end
35
+
36
+ ZabbixRubyClient::Plugins.register('sysinfo', ZabbixRubyClient::Plugins::Sysinfo)
37
+
@@ -1,3 +1,3 @@
1
1
  class ZabbixRubyClient
2
- VERSION ||= "0.0.8"
2
+ VERSION ||= "0.0.9"
3
3
  end
@@ -10,13 +10,3 @@ zabbix:
10
10
  host: zabbix.example.com
11
11
  port: 10051
12
12
  sender: /usr/bin/zabbix_sender
13
- plugins:
14
- - name: load
15
- - name: memory
16
- - name: cpu
17
- - name: network
18
- args: [ eth0 ]
19
- - name: disk
20
- args: [ sda1, / ]
21
- - name: network
22
- args: [ eth1 ]
@@ -0,0 +1,3 @@
1
+ ---
2
+ - name: apt
3
+
@@ -0,0 +1,10 @@
1
+ ---
2
+ - name: load
3
+ - name: memory
4
+ - name: cpu
5
+ - name: disk
6
+ args: [ sda1, / ]
7
+ - name: network
8
+ args: [ eth0 ]
9
+ - name: network
10
+ args: [ eth1 ]
@@ -0,0 +1,3 @@
1
+ ---
2
+ - name: sysinfo
3
+
@@ -1,13 +1,10 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <zabbix_export>
3
3
  <version>2.0</version>
4
- <date>2013-09-25T10:35:58Z</date>
4
+ <date>2013-10-01T06:29:18Z</date>
5
5
  <groups>
6
6
  <group>
7
- <name>Templates</name>
8
- </group>
9
- <group>
10
- <name>web apache</name>
7
+ <name>3. Service Apache</name>
11
8
  </group>
12
9
  </groups>
13
10
  <templates>
@@ -16,10 +13,7 @@
16
13
  <name>Apache (zrc)</name>
17
14
  <groups>
18
15
  <group>
19
- <name>Templates</name>
20
- </group>
21
- <group>
22
- <name>web apache</name>
16
+ <name>3. Service Apache</name>
23
17
  </group>
24
18
  </groups>
25
19
  <applications>
@@ -40,7 +34,7 @@
40
34
  <trends>365</trends>
41
35
  <status>0</status>
42
36
  <value_type>3</value_type>
43
- <allowed_hosts>mb-sandbox</allowed_hosts>
37
+ <allowed_hosts/>
44
38
  <units/>
45
39
  <delta>0</delta>
46
40
  <snmpv3_securityname/>
@@ -79,7 +73,7 @@
79
73
  <trends>365</trends>
80
74
  <status>0</status>
81
75
  <value_type>0</value_type>
82
- <allowed_hosts>mb-sandbox</allowed_hosts>
76
+ <allowed_hosts/>
83
77
  <units>B</units>
84
78
  <delta>0</delta>
85
79
  <snmpv3_securityname/>
@@ -118,7 +112,7 @@
118
112
  <trends>365</trends>
119
113
  <status>0</status>
120
114
  <value_type>0</value_type>
121
- <allowed_hosts>mb-sandbox</allowed_hosts>
115
+ <allowed_hosts/>
122
116
  <units>Bps</units>
123
117
  <delta>0</delta>
124
118
  <snmpv3_securityname/>
@@ -157,7 +151,7 @@
157
151
  <trends>365</trends>
158
152
  <status>0</status>
159
153
  <value_type>3</value_type>
160
- <allowed_hosts>mb-sandbox</allowed_hosts>
154
+ <allowed_hosts/>
161
155
  <units/>
162
156
  <delta>0</delta>
163
157
  <snmpv3_securityname/>
@@ -196,7 +190,7 @@
196
190
  <trends>365</trends>
197
191
  <status>0</status>
198
192
  <value_type>0</value_type>
199
- <allowed_hosts>mb-sandbox</allowed_hosts>
193
+ <allowed_hosts/>
200
194
  <units/>
201
195
  <delta>0</delta>
202
196
  <snmpv3_securityname/>
@@ -235,7 +229,7 @@
235
229
  <trends>365</trends>
236
230
  <status>0</status>
237
231
  <value_type>3</value_type>
238
- <allowed_hosts>mb-sandbox</allowed_hosts>
232
+ <allowed_hosts/>
239
233
  <units/>
240
234
  <delta>0</delta>
241
235
  <snmpv3_securityname/>
@@ -313,7 +307,7 @@
313
307
  <trends>365</trends>
314
308
  <status>0</status>
315
309
  <value_type>3</value_type>
316
- <allowed_hosts>mb-sandbox</allowed_hosts>
310
+ <allowed_hosts/>
317
311
  <units/>
318
312
  <delta>0</delta>
319
313
  <snmpv3_securityname/>
@@ -352,7 +346,7 @@
352
346
  <trends>365</trends>
353
347
  <status>0</status>
354
348
  <value_type>3</value_type>
355
- <allowed_hosts>mb-sandbox</allowed_hosts>
349
+ <allowed_hosts/>
356
350
  <units/>
357
351
  <delta>0</delta>
358
352
  <snmpv3_securityname/>
@@ -391,7 +385,7 @@
391
385
  <trends>365</trends>
392
386
  <status>0</status>
393
387
  <value_type>3</value_type>
394
- <allowed_hosts>mb-sandbox</allowed_hosts>
388
+ <allowed_hosts/>
395
389
  <units/>
396
390
  <delta>0</delta>
397
391
  <snmpv3_securityname/>
@@ -430,7 +424,7 @@
430
424
  <trends>365</trends>
431
425
  <status>0</status>
432
426
  <value_type>3</value_type>
433
- <allowed_hosts>mb-sandbox</allowed_hosts>
427
+ <allowed_hosts/>
434
428
  <units/>
435
429
  <delta>0</delta>
436
430
  <snmpv3_securityname/>
@@ -469,7 +463,7 @@
469
463
  <trends>365</trends>
470
464
  <status>0</status>
471
465
  <value_type>3</value_type>
472
- <allowed_hosts>mb-sandbox</allowed_hosts>
466
+ <allowed_hosts/>
473
467
  <units/>
474
468
  <delta>0</delta>
475
469
  <snmpv3_securityname/>
@@ -508,7 +502,7 @@
508
502
  <trends>365</trends>
509
503
  <status>0</status>
510
504
  <value_type>3</value_type>
511
- <allowed_hosts>mb-sandbox</allowed_hosts>
505
+ <allowed_hosts/>
512
506
  <units/>
513
507
  <delta>0</delta>
514
508
  <snmpv3_securityname/>
@@ -547,7 +541,7 @@
547
541
  <trends>365</trends>
548
542
  <status>0</status>
549
543
  <value_type>3</value_type>
550
- <allowed_hosts>mb-sandbox</allowed_hosts>
544
+ <allowed_hosts/>
551
545
  <units/>
552
546
  <delta>0</delta>
553
547
  <snmpv3_securityname/>
@@ -586,7 +580,7 @@
586
580
  <trends>365</trends>
587
581
  <status>0</status>
588
582
  <value_type>0</value_type>
589
- <allowed_hosts>mb-sandbox</allowed_hosts>
583
+ <allowed_hosts/>
590
584
  <units/>
591
585
  <delta>0</delta>
592
586
  <snmpv3_securityname/>
@@ -625,7 +619,7 @@
625
619
  <trends>365</trends>
626
620
  <status>0</status>
627
621
  <value_type>3</value_type>
628
- <allowed_hosts>mb-sandbox</allowed_hosts>
622
+ <allowed_hosts/>
629
623
  <units/>
630
624
  <delta>0</delta>
631
625
  <snmpv3_securityname/>
@@ -664,7 +658,7 @@
664
658
  <trends>365</trends>
665
659
  <status>0</status>
666
660
  <value_type>3</value_type>
667
- <allowed_hosts>mb-sandbox</allowed_hosts>
661
+ <allowed_hosts/>
668
662
  <units/>
669
663
  <delta>0</delta>
670
664
  <snmpv3_securityname/>
@@ -703,7 +697,7 @@
703
697
  <trends>365</trends>
704
698
  <status>0</status>
705
699
  <value_type>3</value_type>
706
- <allowed_hosts>mb-sandbox</allowed_hosts>
700
+ <allowed_hosts/>
707
701
  <units/>
708
702
  <delta>0</delta>
709
703
  <snmpv3_securityname/>
@@ -742,7 +736,7 @@
742
736
  <trends>365</trends>
743
737
  <status>0</status>
744
738
  <value_type>0</value_type>
745
- <allowed_hosts>mb-sandbox</allowed_hosts>
739
+ <allowed_hosts/>
746
740
  <units/>
747
741
  <delta>0</delta>
748
742
  <snmpv3_securityname/>
@@ -781,7 +775,7 @@
781
775
  <trends>365</trends>
782
776
  <status>0</status>
783
777
  <value_type>0</value_type>
784
- <allowed_hosts>mb-sandbox</allowed_hosts>
778
+ <allowed_hosts/>
785
779
  <units/>
786
780
  <delta>0</delta>
787
781
  <snmpv3_securityname/>
@@ -820,7 +814,7 @@
820
814
  <trends>365</trends>
821
815
  <status>0</status>
822
816
  <value_type>3</value_type>
823
- <allowed_hosts>mb-sandbox</allowed_hosts>
817
+ <allowed_hosts/>
824
818
  <units/>
825
819
  <delta>0</delta>
826
820
  <snmpv3_securityname/>
@@ -1139,5 +1133,49 @@
1139
1133
  </graph_item>
1140
1134
  </graph_items>
1141
1135
  </graph>
1136
+ <graph>
1137
+ <name>s. Apache workers</name>
1138
+ <width>900</width>
1139
+ <height>200</height>
1140
+ <yaxismin>0.0000</yaxismin>
1141
+ <yaxismax>100.0000</yaxismax>
1142
+ <show_work_period>1</show_work_period>
1143
+ <show_triggers>0</show_triggers>
1144
+ <type>0</type>
1145
+ <show_legend>0</show_legend>
1146
+ <show_3d>0</show_3d>
1147
+ <percent_left>0.0000</percent_left>
1148
+ <percent_right>0.0000</percent_right>
1149
+ <ymin_type_1>1</ymin_type_1>
1150
+ <ymax_type_1>0</ymax_type_1>
1151
+ <ymin_item_1>0</ymin_item_1>
1152
+ <ymax_item_1>0</ymax_item_1>
1153
+ <graph_items>
1154
+ <graph_item>
1155
+ <sortorder>0</sortorder>
1156
+ <drawtype>0</drawtype>
1157
+ <color>C80000</color>
1158
+ <yaxisside>0</yaxisside>
1159
+ <calc_fnc>7</calc_fnc>
1160
+ <type>0</type>
1161
+ <item>
1162
+ <host>Apache Stats</host>
1163
+ <key>apache[BusyWorkers]</key>
1164
+ </item>
1165
+ </graph_item>
1166
+ <graph_item>
1167
+ <sortorder>1</sortorder>
1168
+ <drawtype>0</drawtype>
1169
+ <color>00C800</color>
1170
+ <yaxisside>0</yaxisside>
1171
+ <calc_fnc>7</calc_fnc>
1172
+ <type>0</type>
1173
+ <item>
1174
+ <host>Apache Stats</host>
1175
+ <key>apache[IdleWorkers]</key>
1176
+ </item>
1177
+ </graph_item>
1178
+ </graph_items>
1179
+ </graph>
1142
1180
  </graphs>
1143
1181
  </zabbix_export>