zabbixapi 0.3.0 → 0.4.1

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 (68) hide show
  1. data/.travis.yml +9 -0
  2. data/Gemfile +4 -0
  3. data/Gemfile.lock +20 -0
  4. data/README.md +123 -0
  5. data/Rakefile +1 -0
  6. data/lib/zabbixapi/applications.rb +37 -0
  7. data/lib/zabbixapi/client.rb +65 -0
  8. data/lib/zabbixapi/errors.rb +12 -0
  9. data/lib/zabbixapi/graphs.rb +47 -0
  10. data/lib/zabbixapi/hostgroups.rb +42 -0
  11. data/lib/zabbixapi/hosts.rb +80 -0
  12. data/lib/zabbixapi/items.rb +81 -0
  13. data/lib/zabbixapi/server.rb +12 -0
  14. data/lib/zabbixapi/templates.rb +78 -0
  15. data/lib/zabbixapi/triggers.rb +42 -0
  16. data/lib/zabbixapi/users.rb +59 -0
  17. data/lib/zabbixapi/version.rb +3 -0
  18. data/lib/zabbixapi.rb +51 -12
  19. data/spec/localhost.rb +227 -75
  20. data/spec/run.rb +265 -0
  21. data/zabbixapi.gemspec +15 -15
  22. metadata +35 -57
  23. data/README.rdoc +0 -65
  24. data/examples/basic_auth.rb +0 -30
  25. data/examples/config.yml +0 -4
  26. data/examples/maintenance-example.rb +0 -55
  27. data/examples/populate_new_zabbix.sh +0 -84
  28. data/examples/zabbix_availability +0 -73
  29. data/examples/zabbix_clear_default +0 -36
  30. data/examples/zabbix_cpufan-sersor +0 -114
  31. data/examples/zabbix_cputemp-sersor +0 -112
  32. data/examples/zabbix_disk_io +0 -152
  33. data/examples/zabbix_filesystem +0 -249
  34. data/examples/zabbix_group +0 -25
  35. data/examples/zabbix_hlsp +0 -100
  36. data/examples/zabbix_host +0 -37
  37. data/examples/zabbix_iops +0 -131
  38. data/examples/zabbix_ipmi-cpufan-sersor +0 -101
  39. data/examples/zabbix_ipmi_systemp +0 -110
  40. data/examples/zabbix_la +0 -136
  41. data/examples/zabbix_mailer +0 -125
  42. data/examples/zabbix_mdadm +0 -72
  43. data/examples/zabbix_megaraid +0 -71
  44. data/examples/zabbix_memory +0 -290
  45. data/examples/zabbix_named +0 -71
  46. data/examples/zabbix_net +0 -218
  47. data/examples/zabbix_nginx +0 -167
  48. data/examples/zabbix_nginx_500 +0 -112
  49. data/examples/zabbix_ntp +0 -71
  50. data/examples/zabbix_nv-gputemp +0 -111
  51. data/examples/zabbix_pgsql +0 -125
  52. data/examples/zabbix_server_process +0 -71
  53. data/examples/zabbix_smart_blade +0 -94
  54. data/examples/zabbix_ssh +0 -71
  55. data/examples/zabbix_varnish +0 -71
  56. data/lib/zabbixapi/application.rb +0 -40
  57. data/lib/zabbixapi/base.rb +0 -158
  58. data/lib/zabbixapi/graph.rb +0 -59
  59. data/lib/zabbixapi/group.rb +0 -66
  60. data/lib/zabbixapi/host.rb +0 -70
  61. data/lib/zabbixapi/item.rb +0 -130
  62. data/lib/zabbixapi/maintenance.rb +0 -78
  63. data/lib/zabbixapi/mediatype.rb +0 -53
  64. data/lib/zabbixapi/screen.rb +0 -119
  65. data/lib/zabbixapi/template.rb +0 -128
  66. data/lib/zabbixapi/trigger.rb +0 -71
  67. data/lib/zabbixapi/user.rb +0 -0
  68. data/lib/zabbixapi/usermacro.rb +0 -46
@@ -1,73 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rubygems'
4
- require 'getopt/std'
5
- require 'yaml'
6
- require 'zabbixapi'
7
-
8
- opt = Getopt::Std.getopts("g:E:")
9
-
10
- group_name = opt["g"]
11
- zabbix_env = opt["E"]
12
-
13
- template_name = "TMPL_Availability"
14
-
15
- # read config
16
- config = YAML::load(open('./config.yml'))
17
-
18
- api_url = config[zabbix_env]["api_url"]
19
- api_login = config[zabbix_env]["api_login"]
20
- api_password = config[zabbix_env]["api_password"]
21
-
22
-
23
- # Esablish new connection
24
- zbx = Zabbix::ZabbixApi.new(api_url, api_login, api_password)
25
-
26
- # Create new template
27
- p " * Creating template #{template_name}."
28
- g_id = zbx.add_or_get_group(group_name)
29
-
30
- options = {
31
- 'groups' => [ g_id.to_i ],
32
- 'host' => template_name
33
- }
34
-
35
- t_id = zbx.add_or_get_template(options)
36
-
37
- # Create application #{app_name}
38
- app_name = "Availability"
39
- p " ** Create application #{app_name}."
40
- application = {
41
- 'hostid' => t_id,
42
- 'name' => app_name
43
- }
44
- a_id = zbx.add_or_get_application(t_id, application)
45
-
46
- # 'Ping.'
47
- options = {
48
- 'description' => "Ping",
49
- 'key_' => "agent.ping",
50
- 'hostid' => t_id.to_i,
51
- 'applications' => [ a_id.to_i ],
52
- 'history' => 7,
53
- 'trends' => 30,
54
- 'delay' => 30,
55
- 'value_type' => 0,
56
- 'type' => '0'
57
- }
58
- p " ** Add 'Ping' to #{template_name}."
59
- i_id = zbx.add_or_get_item(t_id, options)
60
-
61
- # TRIGGERS
62
- options = {
63
- 'description' => "Host availability",
64
- 'expression' => "{#{template_name}:agent.ping.nodata(61)}=1",
65
- 'priority' => 5, #disaster
66
- 'templateid' => 0,
67
- 'comments' => "Host availability",
68
- 'type' => 0,
69
- 'status' => '0'
70
- }
71
-
72
- p " ** Add 'Host availability disaster trigger'"
73
- tr_id = zbx.add_or_get_trigger(t_id, options)
@@ -1,36 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rubygems'
4
- require 'getopt/std'
5
- require 'yaml'
6
- require 'zabbixapi'
7
-
8
- opt = Getopt::Std.getopts("g:E:")
9
-
10
- group_name = opt["g"]
11
- zabbix_env = opt["E"]
12
-
13
- template_name = "TMPL_Availability"
14
-
15
- # read config
16
- config = YAML::load(open('./config.yml'))
17
-
18
- api_url = config[zabbix_env]["api_url"]
19
- api_login = config[zabbix_env]["api_login"]
20
- api_password = config[zabbix_env]["api_password"]
21
-
22
-
23
- # Esablish new connection
24
- zbx = Zabbix::ZabbixApi.new(api_url, api_login, api_password)
25
-
26
- defaults = zbx.get_templates()
27
-
28
- p " * Delete all template ^Template_."
29
-
30
- defaults.each do |template|
31
- if template[1].match('^Template_')
32
- p " ** Delete template #{template[1]}"
33
- zbx.delete_template(template[1])
34
- end
35
- end
36
-
@@ -1,114 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rubygems'
4
- require 'getopt/std'
5
- require 'yaml'
6
- require 'zabbixapi'
7
-
8
- opt = Getopt::Std.getopts("g:E:")
9
-
10
- group_name = opt["g"]
11
- zabbix_env = opt["E"]
12
-
13
- template_name = "TMPL_cpufan_sensor"
14
- app_name = "cpufan_sensor"
15
- high_disaster_rpm = '5000'
16
- low_disaster_rpm = '800'
17
-
18
- # read config
19
- config = YAML::load(open('./config.yml'))
20
-
21
- api_url = config[zabbix_env]["api_url"]
22
- api_login = config[zabbix_env]["api_login"]
23
- api_password = config[zabbix_env]["api_password"]
24
-
25
- # Esablish new connection
26
- zbx = Zabbix::ZabbixApi.new(api_url, api_login, api_password)
27
-
28
- # Create new template
29
- p " * Creating template #{template_name}."
30
- g_id = zbx.add_or_get_group(group_name)
31
-
32
- options = {
33
- 'groups' => [ g_id.to_i ],
34
- 'host' => template_name
35
- }
36
-
37
- t_id = zbx.add_or_get_template(options)
38
-
39
- # Create application #{app_name}
40
- app_name = "cpufan_sensor"
41
- p " ** Create application #{app_name}."
42
- application = {
43
- 'hostid' => t_id.to_i,
44
- 'name' => app_name
45
- }
46
- a_id = zbx.add_or_get_application(t_id, application)
47
-
48
- # 'cpu fan speed'
49
- options = {
50
- 'description' => "CPU FAN Speed sensor",
51
- 'key_' => "cpufansensor",
52
- 'hostid' => t_id.to_i,
53
- 'applications' => [ a_id.to_i ],
54
- 'history' => 7,
55
- 'trends' => 30,
56
- 'delay' => 60,
57
- 'templateid' => t_id,
58
- 'value_type' => '3',
59
- 'units' => 'rpm'
60
- }
61
- p " ** Add 'cpufansensor' to #{template_name}."
62
- sensor_item_id = zbx.add_or_get_item(t_id, options)
63
-
64
- # TRIGGER
65
- # cpufan disaster (high threshold)
66
- options = {
67
- 'description' => "CPU FAN sensor high",
68
- 'expression' => "{#{template_name}:cpufansensor.last(0)}>#{high_disaster_rpm}",
69
- 'priority' => 5, # disaster
70
- 'templateid' => 0,
71
- 'comments' => "Cpufan sensor high threshold (Disaster)",
72
- 'type' => 0,
73
- 'status' => '0'
74
- }
75
- p " ** Add 'cpufan sensor high disaster' trigger"
76
- zbx.debug = true
77
- tr_id = zbx.add_or_get_trigger(t_id, options)
78
-
79
- # TRIGGER
80
- # cpufan disaster (high threshold)
81
- options = {
82
- 'description' => "CPU FAN sensor low",
83
- 'expression' => "{#{template_name}:cpufansensor.last(0)}<#{low_disaster_rpm}",
84
- 'priority' => 5, # disaster
85
- 'templateid' => 0,
86
- 'comments' => "Cpufan sensor low threshold (Disaster)",
87
- 'type' => 0,
88
- 'status' => '0'
89
- }
90
- p " ** Add 'cpufan sensor low disaster' trigger"
91
- tr_id = zbx.add_or_get_trigger(t_id, options)
92
-
93
- # GRAPH
94
- options = {
95
- 'gitems' => [
96
- {
97
- "itemid" => sensor_item_id,
98
- "drawtype" => "0",
99
- "sortorder" => "0",
100
- "color" => "AA0000",
101
- "yaxisside" => "0",
102
- "calc_fnc" => "2",
103
- "type" => "0",
104
- "periods_cnt" => "5"
105
- }
106
- ],
107
- "show_triggers" => "1",
108
- "name" => "CPU FAN Speed sensor data from lm-sensors",
109
- "width" => "900",
110
- "height" => "200",
111
- "templateid" => "0"
112
- }
113
-
114
- g_id = zbx.add_or_get_graph(t_id, options)
@@ -1,112 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rubygems'
4
- require 'getopt/std'
5
- require 'yaml'
6
- require 'zabbixapi'
7
-
8
- opt = Getopt::Std.getopts("g:E:")
9
-
10
- group_name = opt["g"]
11
- zabbix_env = opt["E"]
12
-
13
- template_name = "TMPL_cputemp_sensor"
14
- app_name = "cputemp_sensor"
15
- high_temperature = '60'
16
- crit_temperature = '80'
17
-
18
- # read config
19
- config = YAML::load(open('./config.yml'))
20
-
21
- api_url = config[zabbix_env]["api_url"]
22
- api_login = config[zabbix_env]["api_login"]
23
- api_password = config[zabbix_env]["api_password"]
24
-
25
- # Esablish new connection
26
- zbx = Zabbix::ZabbixApi.new(api_url, api_login, api_password)
27
-
28
- # Create new template
29
- p " * Creating template #{template_name}."
30
- g_id = zbx.add_or_get_group(group_name)
31
-
32
- options = {
33
- 'groups' => [ g_id.to_i ],
34
- 'host' => template_name
35
- }
36
-
37
- t_id = zbx.add_or_get_template(options)
38
-
39
- # Create application #{app_name}
40
- app_name = "cputemp_sensor"
41
- p " ** Create application #{app_name}."
42
- application = {
43
- 'hostid' => t_id.to_i,
44
- 'name' => app_name
45
- }
46
- a_id = zbx.add_or_get_application(t_id, application)
47
-
48
- # 'cpu temperature sensor'
49
- options = {
50
- 'description' => "CPU Temperature sensor",
51
- 'key_' => "cputempsensor",
52
- 'hostid' => t_id.to_i,
53
- 'applications' => [ a_id.to_i ],
54
- 'history' => 7,
55
- 'trends' => 30,
56
- 'delay' => 60,
57
- 'value_type' => '3',
58
- 'units' => 'C'
59
- }
60
- p " ** Add 'cputempsensor' to #{template_name}."
61
- sensor_item_id = zbx.add_or_get_item(t_id, options)
62
-
63
- # TRIGGER
64
- # cputemp disaster (high threshold)
65
- options = {
66
- 'description' => "CPU Temperature sensor warning",
67
- 'expression' => "{#{template_name}:cputempsensor.last(0)}>#{high_temperature}",
68
- 'priority' => 2, # warning
69
- 'templateid' => 0,
70
- 'comments' => "Cputemp sensor (Warning)",
71
- 'type' => 0,
72
- 'status' => '0'
73
- }
74
- p " ** Add 'cputemp sensor warning' trigger"
75
- tr_id = zbx.add_or_get_trigger(t_id, options)
76
-
77
- # TRIGGER
78
- # cputemp disaster (high threshold)
79
- options = {
80
- 'description' => "CPU temperature sensor disaster",
81
- 'expression' => "{#{template_name}:cputempsensor.last(0)}>#{crit_temperature}",
82
- 'priority' => 5, # disaster
83
- 'templateid' => 0,
84
- 'comments' => "Cputemp sensor (Disaster)",
85
- 'type' => 0,
86
- 'status' => '0'
87
- }
88
- p " ** Add 'cputemp sensor disaster' trigger"
89
- tr_id = zbx.add_or_get_trigger(t_id, options)
90
-
91
- # GRAPH
92
- options = {
93
- 'gitems' => [
94
- {
95
- "itemid" => sensor_item_id,
96
- "drawtype" => "0",
97
- "sortorder" => "0",
98
- "color" => "AA0000",
99
- "yaxisside" => "0",
100
- "calc_fnc" => "2",
101
- "type" => "0",
102
- "periods_cnt" => "5"
103
- }
104
- ],
105
- "show_triggers" => "1",
106
- "name" => "CPU Temperature from lm-sensors",
107
- "width" => "900",
108
- "height" => "200",
109
- "templateid" => "0"
110
- }
111
-
112
- g_id = zbx.add_or_get_graph(t_id, options)
@@ -1,152 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rubygems'
4
- require 'getopt/std'
5
- require 'yaml'
6
- require 'zabbixapi'
7
-
8
- opt = Getopt::Std.getopts("d:g:E:")
9
-
10
- group_name = opt["g"]
11
- disk_name = opt["d"]
12
- zabbix_env = opt["E"]
13
-
14
- template_name = "TMPL_Disk_" + disk_name.gsub(/\//, "_")
15
-
16
- # read config
17
- config = YAML::load(open('./config.yml'))
18
-
19
- api_url = config[zabbix_env]["api_url"]
20
- api_login = config[zabbix_env]["api_login"]
21
- api_password = config[zabbix_env]["api_password"]
22
-
23
- # Esablish new connection
24
- zbx = Zabbix::ZabbixApi.new(api_url, api_login, api_password)
25
- zbx.debug = true
26
-
27
- # Create new template
28
- p " * Creating template #{template_name}."
29
- g_id = zbx.add_or_get_group(group_name)
30
-
31
- options = {
32
- 'groups' => [ g_id.to_i ],
33
- 'host' => template_name
34
- }
35
-
36
- t_id = zbx.add_or_get_template(options)
37
-
38
- # Create application #{app_name}
39
- app_name = "Disk_" + disk_name.gsub(/\//, "_")
40
- p " ** Create application #{app_name}."
41
- application = {
42
- 'hostid' => t_id.to_i,
43
- 'name' => app_name
44
- }
45
- a_id = zbx.add_or_get_application(t_id, application)
46
-
47
- # 'IOPS Read on #{disk_name} avg5'
48
- options = {
49
- 'description' => "IOPS Read on #{disk_name} avg5",
50
- 'key_' => "vfs.dev.read[#{disk_name}, ops, avg5]",
51
- 'hostid' => t_id.to_i,
52
- 'applications' => [ a_id.to_i ],
53
- 'units' => 'ops',
54
- 'history' => 7,
55
- 'trends' => 30,
56
- 'delay' => 300,
57
- 'value_type' => 0,
58
- }
59
- p " ** Add 'IOPS Read on #{disk_name} avg5' to #{template_name}."
60
-
61
- i_id = zbx.add_or_get_item(t_id, options)
62
-
63
- # 'IOPS Write on #{disk_name} avg5'
64
- options = {
65
- 'description' => "IOPS Write on #{disk_name} avg5",
66
- 'key_' => "vfs.dev.write[#{disk_name}, ops, avg5]",
67
- 'hostid' => t_id.to_i,
68
- 'applications' => [ a_id.to_i ],
69
- 'units' => 'ops',
70
- 'history' => 7,
71
- 'trends' => 30,
72
- 'delay' => 300,
73
- 'value_type' => 0,
74
- }
75
- p " ** Add 'IOPS Write on #{disk_name} avg5' to #{template_name}."
76
-
77
- i_id = zbx.add_or_get_item(t_id, options)
78
-
79
- # 'BPS Read on #{disk_name} avg5'
80
- options = {
81
- 'description' => "BPS Read on #{disk_name} avg5",
82
- 'key_' => "vfs.dev.read[#{disk_name}, sps, avg5]",
83
- 'hostid' => t_id.to_i,
84
- 'applications' => [ a_id.to_i ],
85
-
86
- # convert sectors to bytes
87
- 'multiplier' => 1,
88
- 'formula' => 512,
89
-
90
- 'value_type' => 0,
91
- 'units' => 'Bps',
92
- 'history' => 7,
93
- 'trends' => 30,
94
- 'delay' => 300,
95
- }
96
- p " ** Add 'BPS Read on #{disk_name} avg5' to #{template_name}."
97
-
98
- bps_r_avg5_id = zbx.add_or_get_item(t_id, options)
99
-
100
- # 'BPS Write on #{disk_name}'
101
- options = {
102
- 'description' => "BPS Write on #{disk_name} avg5",
103
- 'key_' => "vfs.dev.write[#{disk_name}, sps, avg5]",
104
- 'hostid' => t_id.to_i,
105
- 'applications' => [ a_id.to_i ],
106
-
107
- # convert sectors to bytes
108
- 'multiplier' => 1,
109
- 'formula' => 512,
110
-
111
- 'value_type' => 0,
112
- 'units' => 'Bps',
113
- 'history' => 7,
114
- 'trends' => 30,
115
- 'delay' => 300
116
- }
117
- p " ** Add 'BPS Write on #{disk_name} avg5' to #{template_name}."
118
-
119
- bps_w_avg5_id = zbx.add_or_get_item(t_id, options)
120
-
121
- # Create graph 'Disk usage #{disk_name}'
122
- options = {
123
- 'gitems' => [
124
- {
125
- "itemid" => bps_w_avg5_id,
126
- "drawtype" => "0",
127
- "sortorder" => "0",
128
- "color" => "AA0000",
129
- "yaxisside" => "0",
130
- "calc_fnc" => "2",
131
- "type" => "0",
132
- "periods_cnt" => "5"
133
- },
134
- {
135
- "itemid" => bps_r_avg5_id,
136
- "drawtype" => "0",
137
- "sortorder" => "0",
138
- "color" => "009900",
139
- "yaxisside" => "0",
140
- "calc_fnc" => "2",
141
- "type" => "0",
142
- "periods_cnt" => "5"
143
- }
144
- ],
145
- "show_triggers" => "1",
146
- "name" => "Disk usage #{disk_name}",
147
- "width" => "900",
148
- "height" => "200",
149
- "templateid" => "0"
150
- }
151
- p " ** Add 'Disk usage #{disk_name} graph'"
152
- g_id = zbx.add_or_get_graph(t_id, options)