zabbixapi 0.3.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
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,130 +0,0 @@
1
- module Zabbix
2
- class ZabbixApi
3
-
4
- def add_item(item)
5
- # Default item options
6
- # See: http://www.zabbix.com/documentation/1.8/api/item
7
- ## Item types (see ./frontends/php/include/defines.inc.php in zabbix source)
8
- # ITEM_TYPE_ZABBIX 0
9
- # ITEM_TYPE_SNMPV1 1
10
- # ITEM_TYPE_TRAPPER 2
11
- # ITEM_TYPE_SIMPLE 3
12
- # ITEM_TYPE_SNMPV2C 4
13
- # ITEM_TYPE_INTERNAL 5
14
- # ITEM_TYPE_SNMPV3 6
15
- # ITEM_TYPE_ZABBIX_ACTIVE 7
16
- # ITEM_TYPE_AGGREGATE 8
17
- # ITEM_TYPE_HTTPTEST 9
18
- # ITEM_TYPE_EXTERNAL 10
19
- # ITEM_TYPE_DB_MONITOR 11
20
- # ITEM_TYPE_IPMI 12
21
- # ITEM_TYPE_SSH 13
22
- # ITEM_TYPE_TELNET 14
23
- # ITEM_TYPE_CALCULATED 15
24
- item_options = {
25
- 'description' => nil,
26
- 'key_' => nil,
27
- 'hostid' => nil,
28
- 'delay' => 60,
29
- 'history' => 60,
30
- 'status' => 0,
31
- 'type' => 7,
32
- 'snmp_community' => '',
33
- 'snmp_oid' => '',
34
- 'value_type' => 3,
35
- 'data_type' => 0,
36
- 'trapper_hosts' => 'localhost',
37
- 'snmp_port' => 161,
38
- 'units' => '',
39
- 'multiplier' => 0,
40
- 'delta' => 0,
41
- 'snmpv3_securityname' => '',
42
- 'snmpv3_securitylevel' => 0,
43
- 'snmpv3_authpassphrase' => '',
44
- 'snmpv3_privpassphrase' => '',
45
- 'formula' => 0,
46
- 'trends' => 365,
47
- 'logtimefmt' => '',
48
- 'valuemapid' => 0,
49
- 'delay_flex' => '',
50
- 'authtype' => 0,
51
- 'username' => '',
52
- 'password' => '',
53
- 'publickey' => '',
54
- 'privatekey' => '',
55
- 'params' => '',
56
- 'ipmi_sensor' => '',
57
- 'applications' => '',
58
- 'templateid' => 0
59
- }
60
- item_options.merge!(item)
61
- message = {
62
- 'method' => 'item.create',
63
- 'params' => [item_options]
64
- }
65
- response = send_request(message)
66
- response.empty? ? nil : response['itemids'][0]
67
- end
68
-
69
- def get_item_id(host_id, item_name)
70
- message = {
71
- 'method' => 'item.get',
72
- 'params' => {
73
- 'filter' => {
74
- 'hostid' => host_id,
75
- 'description' => item_name
76
- }
77
- }
78
- }
79
- response = send_request(message)
80
- response.empty? ? nil : response[0]['itemid']
81
- end
82
-
83
- def add_or_get_item(host_id, item_options)
84
- unless i_id = get_item_id(host_id, item_options['description'])
85
- i_id = add_item(item_options)
86
- end
87
- return i_id
88
- end
89
-
90
- def item_exist?(host_id, item_name)
91
- item_id = get_item_id(host_id, item_name)
92
- item_id ? true : false
93
- end
94
-
95
- def update_item(item_id, options)
96
- options["item_id"]
97
- message = {
98
- 'method' => 'item.update',
99
- 'params' => options
100
- }
101
- response = send_request(message)
102
- response.empty? ? nil : response['itemids'][0]
103
- end
104
-
105
- # Don't work with api < 1.8.4
106
- def delete_item(item_ids)
107
- if item_ids.kind_of? Array
108
- message = {
109
- 'method' => 'item.delete',
110
- 'params' => item_ids
111
- }
112
- elsif item_ids.kind_of? Fixnum or item_ids.kind_of? String
113
- message = {
114
- 'method' => 'item.delete',
115
- 'params' => [item_ids]
116
- }
117
- else
118
- raise Zabbix::ArgumentError.new("Zabbix::ZabbixApi.delete_item() argument error. item_ids => #{item_ids.inspect}")
119
- end
120
- response = send_request(message)
121
- if response.empty?
122
- result = nil
123
- else
124
- response['itemids'].count == 1 ? result = response['itemids'][0] : result = response['itemids']
125
- end
126
- return result
127
- end
128
-
129
- end
130
- end
@@ -1,78 +0,0 @@
1
- module Zabbix
2
- class ZabbixApi
3
-
4
- def create_maintenance(host_id, maintenance_options)
5
-
6
- time_now = Time.now.to_i
7
-
8
- maintenance_default = {
9
- 'hostids' => [host_id],
10
- 'groupids' => [],
11
- 'name' => '',
12
- 'maintenance_type' => '0', # 0 = with data collection, 1 = without
13
- 'description' => '',
14
- 'active_since' => '',
15
- 'active_till' => ''
16
- }
17
- message = {
18
- 'method' => 'maintenance.create',
19
- 'params' => merge_opt(maintenance_default, maintenance_options)
20
- }
21
- response = send_request(message)
22
- response.empty? ? nil : response['maintenanceids'][0].to_i
23
- end
24
-
25
- def get_maintenance_id(host_id)
26
- message = {
27
- 'method' => 'maintenance.get',
28
- 'params' => {
29
- 'hostids' => [host_id]
30
- }
31
- }
32
- response = send_request(message)
33
- response.empty? ? nil : response[0]['maintenanceid'].to_i
34
- end
35
-
36
- def maintenance_exists?(maintenance_id)
37
- # seems like .nodeids and .maintenance are ignored
38
- # mmethner: .maintenanceid is the only settings which not always returns true
39
- message = {
40
- 'method' => 'maintenance.exists',
41
- 'params' => {
42
- 'nodeids' => [],
43
- 'maintenance' => '',
44
- 'maintenanceid' => maintenance_id,
45
- }
46
- }
47
- response = send_request(message)
48
- response
49
- end
50
-
51
- def update_maintenance(maintenance_id, maintenance_options)
52
-
53
- maintenance_options["maintenanceid"] = maintenance_id
54
- message = {
55
- 'method' => 'maintenance.update',
56
- 'params' => maintenance_options
57
- }
58
- response = send_request(message)
59
-
60
- # the zabbix api returns boolean
61
- # even the official zabbix api documentation specifies an array
62
- response
63
- end
64
-
65
- def delete_maintenance(maintenance_id)
66
- message = {
67
- 'method' => 'maintenance.delete',
68
- 'params' => [maintenance_id]
69
- }
70
- response = send_request(message)
71
-
72
- # the zabbix api returns boolean
73
- # even the official zabbix api documentation specifies an array
74
- response
75
- end
76
-
77
- end
78
- end
@@ -1,53 +0,0 @@
1
- module Zabbix
2
- class ZabbixApi
3
-
4
- def get_mediatype_id(mediatype)
5
- message = {
6
- 'method' => 'mediatype.get',
7
- 'params' => {
8
- 'search' => {
9
- 'description' => mediatype
10
- },
11
- 'output' => 'extend',
12
- }
13
- }
14
- response = send_request(message)
15
- response.empty? ? nil : response[0]['mediatypeid'].to_i
16
- end
17
-
18
- def add_mediatype(mediatype_options)
19
- mediatype_default = {
20
- 'type' => '0',
21
- 'description' => '',
22
- 'smtp_server' => '',
23
- 'smtp_helo' => '',
24
- 'smtp_email' => '',
25
- 'exec_path' => '',
26
- 'gsm_modem' => '',
27
- 'username' => '',
28
- 'passwd' => ''
29
- }
30
- mediatype = merge_opt(mediatype_default, mediatype_options)
31
- message = {
32
- 'method' => 'mediatype.create',
33
- 'params' => mediatype
34
- }
35
- response = send_request(message)
36
- response.empty? ? nil : response['mediatypeids'][0].to_i
37
- end
38
-
39
- def delete_mediatype(mediatype)
40
- if mediatype_id = get_mediatype_id(mediatype)
41
- message = {
42
- 'method' => 'mediatype.delete',
43
- 'params' =>
44
- [mediatype_id]
45
- }
46
- response = send_request(message)
47
- response.empty? ? nil : response['mediatypeids'][0]
48
- end
49
- end
50
-
51
- end
52
- end
53
-
@@ -1,119 +0,0 @@
1
- module Zabbix
2
- class ZabbixApi
3
-
4
- def get_screen_id(screen_name)
5
- message = {
6
- 'method' => 'screen.get',
7
- 'params' => {
8
- 'filter' => {
9
- 'name' => screen_name
10
- }
11
- }
12
- }
13
- response = send_request(message)
14
- response.empty? ? nil : response[0]['screenid']
15
- end
16
-
17
- def get_screen_parameter(screen_name, param_name)
18
- message = {
19
- 'method' => 'screen.get',
20
- 'params' => {
21
- 'extendoutput' => '1',
22
- 'filter' => {
23
- 'name' => screen_name
24
- }
25
- }
26
- }
27
- response = send_request(message)
28
- response.empty? ? nil : response[0][param_name]
29
- end
30
-
31
- def get_screen_graph_ids(screen_id)
32
- message = {
33
- 'method' => 'screen.get',
34
- 'params' => {
35
- 'extendoutput' => '1',
36
- 'select_screenitems' => '1',
37
- 'screenids' => [screen_id]
38
- }
39
- }
40
- response = send_request(message)
41
- if response.empty?
42
- result = nil
43
- else
44
- result = []
45
- screenitems = response[0]['screenitems']
46
- screenitems.each() do |item|
47
- result << item['resourceid'] if item['resourcetype'].to_i == 0
48
- end
49
- end
50
- return result
51
- end
52
-
53
- def set_screen_parameter(screen_id, param_name, param_value)
54
- message = {
55
- 'method' => 'screen.update',
56
- 'params' => {
57
- param_name => param_value,
58
- 'screenid' => screen_id
59
- }
60
- }
61
- response = send_request(message)
62
- response.empty? ? nil : response[0]['screenids'].to_i
63
- end
64
-
65
- def del_all_graphs_from_screen(screen_id)
66
- message = {
67
- 'method' => 'screen.deleteItems',
68
- 'params' => {
69
- 'screenids' => [screen_id],
70
- }
71
- }
72
- response = send_request(message)
73
- response ? response[0]['screenids'].to_i : nil
74
- end
75
-
76
- def add_graph_to_screen(screen_id, graph_id, x, y)
77
- message = {
78
- 'method' => 'screen.addItems',
79
- 'params' => {
80
- 'screenids' => [screen_id],
81
- 'screenitems' => [
82
- {
83
- 'resourcetype' => 'graph',
84
- 'resourceid' => graph_id,
85
- 'width' => '800',
86
- 'height' => '200',
87
- 'x' => x,
88
- 'y' => y,
89
- 'valign' => 'Middle',
90
- 'halign' => 'Centre',
91
- 'colspan' => '0',
92
- 'rowspan' => '0',
93
- 'elements' => '0',
94
- 'dynamic' => '0',
95
- 'url' => '0',
96
- 'style' => '0'
97
- }
98
- ]
99
- }
100
- }
101
- response = send_request(message)
102
- return response
103
- end
104
-
105
- def add_screen(screen_name, hsize, vsize)
106
- message = {
107
- 'method' => 'screen.create',
108
- 'params' => {
109
- 'name' => screen_name,
110
- 'hsize' => hsize,
111
- 'vsize' => vsize
112
- }
113
- }
114
- response = send_request(message)
115
- response.empty? ? nil : response['screenids'][0]
116
- end
117
-
118
- end
119
- end
@@ -1,128 +0,0 @@
1
- module Zabbix
2
- class ZabbixApi
3
-
4
- def add_template(template_options)
5
- template_default = {
6
- 'host' => nil,
7
- 'groups' => [],
8
- }
9
- template_options['groups'].map! { |group_id| {'groupid' => group_id} }
10
- template = merge_opt(template_default, template_options)
11
- message = {
12
- 'method' => 'template.create',
13
- 'params' => template
14
- }
15
- response = send_request(message)
16
- response.empty? ? nil : response['templateids'][0].to_i
17
- end
18
-
19
- def add_or_get_template(template_options)
20
- unless t_id = get_template_id(template_options['host'])
21
- t_id = add_template(template_options)
22
- end
23
- return t_id
24
- end
25
-
26
- def get_template_ids_by_host(host_id)
27
- message = {
28
- 'method' => 'template.get',
29
- 'params' => {
30
- 'hostids' => [host_id]
31
- }
32
- }
33
- response = send_request(message)
34
- if response.empty?
35
- result = nil
36
- else
37
- result = []
38
- response.each_key() do |template_id|
39
- result << template_id
40
- end
41
- end
42
- return result
43
- end
44
-
45
- def get_templates()
46
- message = {
47
- 'method' => 'template.get',
48
- 'params' => {
49
- 'extendoutput' => '0'
50
- }
51
- }
52
- response = send_request(message)
53
- if response.empty?
54
- result = nil
55
- else
56
- result = {}
57
- if response.kind_of? Hash
58
- template_ids = response.keys()
59
- template_ids.each() do |template_id|
60
- template_name = response[template_id]['host']
61
- result[template_id] = template_name
62
- end
63
- elsif response.kind_of? Array
64
- response.each do |template_info|
65
- result[template_info['hostid']] = template_info['host']
66
- end
67
- end
68
- end
69
- return result
70
- end
71
-
72
- def get_template_id(template_name)
73
- message = {
74
- 'method' => 'template.get',
75
- 'params' => {
76
- 'filter' => {
77
- 'host' => template_name
78
- }
79
- }
80
- }
81
- response = send_request(message)
82
- response.empty? ? nil : response[0]['templateid'].to_i
83
- end
84
-
85
- def link_templates_with_hosts(templates_id, hosts_id)
86
- templates_id.class == Array ? message_templates_id = templates_id : message_templates_id = [templates_id]
87
- hosts_id.class == Array ? message_hosts_id = hosts_id : message_hosts_id = [hosts_id]
88
- message = {
89
- 'method' => 'template.massAdd',
90
- 'params' => {
91
- 'hosts' => message_hosts_id.map { |t| {"hostid" => t} },
92
- 'templates' => message_templates_id.map { |t| {"templateid" => t} }
93
- }
94
- }
95
- response = send_request(message)
96
- response.empty? ? nil : response['templateid'][0].to_i
97
- end
98
-
99
- def unlink_templates_from_hosts(templates_id, hosts_id)
100
- templates_id.class == Array ? message_templates_id = templates_id : message_templates_id = [templates_id]
101
- hosts_id.class == Array ? message_hosts_id = hosts_id : message_hosts_id = [hosts_id]
102
- message = {
103
- 'method' => 'template.massRemove',
104
- 'params' => {
105
- 'hostids' => message_hosts_id,
106
- 'templateids' => message_templates_id,
107
- 'force' => '1'
108
- }
109
- }
110
- response = send_request(message)
111
- response.empty? ? nil : response['templateids'][0].to_i
112
- end
113
-
114
- def delete_template(template_name)
115
- message = {
116
- 'method' => 'template.delete',
117
- 'params' => [
118
- {
119
- "templateid" => get_template_id(template_name)
120
- }
121
- ]
122
- }
123
- response = send_request(message)
124
- response.empty? ? nil : response['templateids'][0].to_i
125
- end
126
-
127
- end
128
- end
@@ -1,71 +0,0 @@
1
- module Zabbix
2
- class ZabbixApi
3
-
4
- def add_trigger(trigger)
5
- message = {
6
- 'method' => 'trigger.create',
7
- 'params' => [ trigger ]
8
- }
9
- response = send_request(message)
10
- response.empty? ? nil : response['triggerids'][0]
11
- end
12
-
13
- def add_or_get_trigger(host_id, trigger)
14
- unless tr_id = get_trigger_id(host_id, trigger['description'])
15
- tr_id = add_trigger(trigger)
16
- end
17
- return tr_id
18
- end
19
-
20
- def get_trigger_id(host_id, trigger_name)
21
- message = {
22
- 'method' => 'trigger.get',
23
- 'params' => {
24
- 'filter' => {
25
- 'hostid' => host_id,
26
- 'description' => [ trigger_name ]
27
- }
28
- }
29
- }
30
- response = send_request(message)
31
- response.empty? ? nil : response[0]['triggerid']
32
- end
33
-
34
- def get_triggers_by_host(host_id)
35
- message = {
36
- 'method' => 'trigger.get',
37
- 'params' => {
38
- 'filter' => {
39
- 'hostid' => host_id,
40
- },
41
- 'extendoutput' => '1'
42
- }
43
- }
44
- response = send_request(message)
45
- if response.empty?
46
- result = {}
47
- else
48
- result = {}
49
- response.each do |trigger|
50
- trigger_id = trigger['triggerid']
51
- description = trigger['description']
52
- result[trigger_id] = description
53
- end
54
- end
55
- return result
56
- end
57
-
58
- def update_trigger_status(trigger_id, status)
59
- message = {
60
- 'method' => 'trigger.update_status',
61
- 'params' => {
62
- 'triggerid' => trigger_id,
63
- 'status' => status
64
- }
65
- }
66
- response = send_request(message)
67
- response.empty? ? nil : response['triggerids'][0]
68
- end
69
-
70
- end
71
- end
File without changes
@@ -1,46 +0,0 @@
1
- module Zabbix
2
- class ZabbixApi
3
-
4
- def add_macro(host_id, macro_name, macro_value)
5
- message = {
6
- 'method' => 'Usermacro.create',
7
- 'params' => {
8
- 'hostid' => host_id,
9
- 'macro' => macro_name,
10
- 'value' => macro_value
11
- }
12
- }
13
- response = send_request(message)
14
- hostmacroids == response['hostmacroids'] ? hostmacroids : nil
15
- end
16
-
17
- def get_macro(host_id, macro_name)
18
- message = {
19
- 'method' => 'Usermacro.get',
20
- 'params' => {
21
- 'hostids' => host_id,
22
- 'macros' => macro_name,
23
- 'extendoutput' => '1'
24
- }
25
- }
26
- response = send_request(message)
27
- if response.empty?
28
- result = nil
29
- else
30
- if hostmacroid == response[0]['hostmacroid']
31
- macro_id = hostmacroid
32
- macro_value = response[0]['value']
33
-
34
- result = {
35
- 'id' => macro_id,
36
- 'value' => macro_value
37
- }
38
- else
39
- result = nil
40
- end
41
- end
42
- return result
43
- end
44
-
45
- end
46
- end