zabbixapi 0.6.6 → 2.0.0

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 (62) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +11 -6
  3. data/README.md +21 -25
  4. data/lib/zabbixapi.rb +23 -10
  5. data/lib/zabbixapi/{1.8/basic → basic}/basic_alias.rb +0 -0
  6. data/lib/zabbixapi/{1.8/basic → basic}/basic_func.rb +3 -3
  7. data/lib/zabbixapi/{1.8/basic → basic}/basic_init.rb +0 -0
  8. data/lib/zabbixapi/{2.0/basic → basic}/basic_logic.rb +3 -3
  9. data/lib/zabbixapi/{1.8/classes → classes}/applications.rb +0 -0
  10. data/lib/zabbixapi/{1.8/classes → classes}/errors.rb +0 -0
  11. data/lib/zabbixapi/{1.8/classes → classes}/graphs.rb +0 -0
  12. data/lib/zabbixapi/{2.0/classes → classes}/hostgroups.rb +0 -0
  13. data/lib/zabbixapi/{2.0/classes → classes}/hosts.rb +4 -0
  14. data/lib/zabbixapi/{2.0/classes → classes}/items.rb +8 -0
  15. data/lib/zabbixapi/{1.8/classes → classes}/mediatypes.rb +0 -0
  16. data/lib/zabbixapi/{2.0/classes → classes}/proxies.rb +0 -0
  17. data/lib/zabbixapi/{2.0/classes → classes}/screens.rb +1 -19
  18. data/lib/zabbixapi/{1.8/classes → classes}/server.rb +0 -0
  19. data/lib/zabbixapi/{2.0/classes → classes}/templates.rb +4 -4
  20. data/lib/zabbixapi/{1.8/classes → classes}/triggers.rb +0 -0
  21. data/lib/zabbixapi/{1.8/classes → classes}/unusable.rb +0 -0
  22. data/lib/zabbixapi/{2.0/classes → classes}/usergroups.rb +0 -12
  23. data/lib/zabbixapi/{2.0/classes → classes}/usermacros.rb +0 -0
  24. data/lib/zabbixapi/{2.0/classes → classes}/users.rb +2 -2
  25. data/lib/zabbixapi/version.rb +1 -1
  26. data/spec/application.rb +74 -0
  27. data/spec/basic_func.rb +4 -0
  28. data/spec/graph.rb +135 -0
  29. data/spec/host.rb +136 -0
  30. data/spec/hostgroup.rb +55 -0
  31. data/spec/item.rb +132 -0
  32. data/spec/mediatype.rb +47 -0
  33. data/spec/query.rb +13 -0
  34. data/spec/screen.rb +88 -0
  35. data/spec/server.rb +17 -0
  36. data/spec/spec_helper.rb +21 -0
  37. data/spec/template.rb +148 -0
  38. data/spec/trigger.rb +74 -0
  39. data/spec/user.rb +99 -0
  40. data/spec/usergroup.rb +69 -0
  41. data/zabbixapi.gemspec +3 -3
  42. metadata +52 -44
  43. data/lib/zabbixapi/1.8/basic/basic_logic.rb +0 -103
  44. data/lib/zabbixapi/1.8/classes/hostgroups.rb +0 -26
  45. data/lib/zabbixapi/1.8/classes/hosts.rb +0 -58
  46. data/lib/zabbixapi/1.8/classes/items.rb +0 -54
  47. data/lib/zabbixapi/1.8/classes/screens.rb +0 -101
  48. data/lib/zabbixapi/1.8/classes/templates.rb +0 -109
  49. data/lib/zabbixapi/1.8/classes/usergroups.rb +0 -82
  50. data/lib/zabbixapi/1.8/classes/users.rb +0 -32
  51. data/lib/zabbixapi/2.0/basic/basic_alias.rb +0 -21
  52. data/lib/zabbixapi/2.0/basic/basic_func.rb +0 -55
  53. data/lib/zabbixapi/2.0/basic/basic_init.rb +0 -33
  54. data/lib/zabbixapi/2.0/classes/applications.rb +0 -45
  55. data/lib/zabbixapi/2.0/classes/errors.rb +0 -15
  56. data/lib/zabbixapi/2.0/classes/graphs.rb +0 -66
  57. data/lib/zabbixapi/2.0/classes/mediatypes.rb +0 -31
  58. data/lib/zabbixapi/2.0/classes/server.rb +0 -12
  59. data/lib/zabbixapi/2.0/classes/triggers.rb +0 -67
  60. data/lib/zabbixapi/2.0/classes/unusable.rb +0 -10
  61. data/spec/localhost.rb +0 -514
  62. data/spec/run.rb +0 -486
@@ -1,109 +0,0 @@
1
- class ZabbixApi
2
- class Templates < Basic
3
-
4
- def array_flag
5
- true
6
- end
7
-
8
- def method_name
9
- "template"
10
- end
11
-
12
- def indentify
13
- "host"
14
- end
15
-
16
-
17
- # Delete template
18
- #
19
- # * *Args* :
20
- # - +data+ -> Hash with :host => "Template_Name"
21
- # * *Returns* :
22
- # - Nil or Integer
23
- def delete(data)
24
- result = @client.api_request(:method => "template.delete", :params => [:templateid => data])
25
- result.empty? ? nil : result['templateids'][0].to_i
26
- end
27
-
28
- # Return templateids linked with host
29
- #
30
- # * *Args* :
31
- # - +data+ -> Hash with :hostids => [hostid]
32
- # * *Returns* :
33
- # - Array with templateids
34
- def get_ids_by_host(data)
35
- result = []
36
- @client.api_request(:method => "template.get", :params => data).each do |tmpl|
37
- result << tmpl['templateid']
38
- end
39
- result
40
- end
41
-
42
- # Return templateid
43
- #
44
- # * *Args* :
45
- # - +data+ -> Hash with :host => "Template_Name" and :groups => array with hostgroup ids
46
- # * *Returns* :
47
- # - Integer
48
- def get_or_create(data)
49
- unless (templateid = get_id(:host => data[:host]))
50
- templateid = create(data)
51
- end
52
- templateid
53
- end
54
-
55
- # Analog Zabbix api call massUpdate
56
- #
57
- # * *Args* :
58
- # - +data+ -> Hash with :hosts_id => [hostid1, hostid2 ...], and :templates_id => [templateid1, templateid2 ...]
59
- # * *Returns* :
60
- # - True or False
61
- def mass_update(data)
62
- result = @client.api_request(
63
- :method => "template.massAdd",
64
- :params => {
65
- :hosts => data[:hosts_id].map { |t| {:hostid => t} },
66
- :templates => data[:templates_id].map { |t| {:templateid => t} }
67
- }
68
- )
69
- result.empty? ? false : true
70
- end
71
-
72
- # Analog Zabbix api call massAdd
73
- #
74
- # * *Args* :
75
- # - +data+ -> Hash with :hosts_id => [hostid1, hostid2 ...], and :templates_id => [templateid1, templateid2 ...]
76
- # * *Returns* :
77
- # - True or False
78
- def mass_add(data)
79
- result = @client.api_request(
80
- :method => "template.massAdd",
81
- :params => {
82
- :hosts => data[:hosts_id].map { |t| {:hostid => t} },
83
- :templates => data[:templates_id].map { |t| {:templateid => t} }
84
- }
85
- )
86
- result.empty? ? false : true
87
- end
88
-
89
- # Analog Zabbix api call massRemove
90
- #
91
- # * *Args* :
92
- # - +data+ -> Hash with :hosts_id => [hostid1, hostid2 ...], and :templates_id => [templateid1, templateid2 ...]
93
- # * *Returns* :
94
- # - True or False
95
- def mass_remove(data)
96
- result = @client.api_request(
97
- :method => "template.massRemove",
98
- :params => {
99
- :hostids => data[:hosts_id],
100
- :templateids => data[:templates_id],
101
- :groupids => data[:group_id],
102
- :force => 1
103
- }
104
- )
105
- result.empty? ? false : true
106
- end
107
-
108
- end
109
- end
@@ -1,82 +0,0 @@
1
- class ZabbixApi
2
- class Usergroups < Basic
3
-
4
- def array_flag
5
- true
6
- end
7
-
8
- def method_name
9
- "usergroup"
10
- end
11
-
12
- def key
13
- "usrgrpid"
14
- end
15
-
16
- def indentify
17
- "name"
18
- end
19
-
20
- # Delete UserGroup
21
- #
22
- # * *Args* :
23
- # - +data+ -> Array with usrgrpids
24
- # * *Returns* :
25
- # - Nil or Integer
26
- def delete(data)
27
- result = @client.api_request(:method => "usergroup.delete", :params => data)
28
- result ? result['usrgrpids'][0].to_i : nil
29
- end
30
-
31
-
32
- # Return usrgrpid
33
- #
34
- # * *Args* :
35
- # - +data+ -> Hash with :name => "UserGroup"
36
- # * *Returns* :
37
- # - Integer
38
- def get_or_create(data)
39
- usrgrpid = get_id(data)
40
- if usrgrpid.nil?
41
- usrgrpid = create(data)
42
- end
43
- usrgrpid
44
- end
45
-
46
- # Set permission for usrgrp on some hostgroup
47
- #
48
- # * *Args* :
49
- # - +data+ -> Hash with :usrgrpids => id, :hostgroupids => [], :permission => 2,3 (read and read write)
50
- # * *Returns* :
51
- # - Integer
52
- def set_perms(data)
53
- permission = data[:permission] || 2
54
- result = @client.api_request(
55
- :method => "usergroup.massAdd",
56
- :params => {
57
- :usrgrpids => [data[:usrgrpid]],
58
- :rights => data[:hostgroupids].map { |t| {:permission => permission, :id => t} }
59
- }
60
- )
61
- result ? result['usrgrpids'][0].to_i : nil
62
- end
63
-
64
- # Update usergroup, add user
65
- #
66
- # * *Args* :
67
- # - +data+ -> Hash with :usrgrpids => id, :userids => []
68
- # * *Returns* :
69
- # - Integer
70
- def add_user(data)
71
- result = @client.api_request(
72
- :method => "usergroup.massAdd",
73
- :params => {
74
- :usrgrpids => data[:usrgrpids],
75
- :userids => data[:userids]
76
- }
77
- )
78
- result ? result['usrgrpids'][0].to_i : nil
79
- end
80
-
81
- end
82
- end
@@ -1,32 +0,0 @@
1
- class ZabbixApi
2
- class Users < Basic
3
-
4
- def method_name
5
- "user"
6
- end
7
-
8
- def keys
9
- "userids"
10
- end
11
-
12
- def key
13
- "userid"
14
- end
15
-
16
- def indentify
17
- "name"
18
- end
19
-
20
- def add_medias(data)
21
- result = @client.api_request(
22
- :method => "user.addMedia",
23
- :params => {
24
- :users => data[:userids].map { |t| {:userid => t} },
25
- :medias => data[:media]
26
- }
27
- )
28
- result ? result['userids'][0].to_i : nil
29
- end
30
-
31
- end
32
- end
@@ -1,21 +0,0 @@
1
- class ZabbixApi
2
- class Basic
3
-
4
- def get(data)
5
- get_full_data(data)
6
- end
7
-
8
- def add(data)
9
- create(data)
10
- end
11
-
12
- def destroy(data)
13
- delete(data)
14
- end
15
-
16
- def method_name
17
-
18
- end
19
-
20
- end
21
- end
@@ -1,55 +0,0 @@
1
- class ZabbixApi
2
- class Basic
3
-
4
- def log(message)
5
- puts "#{message}" if @client.options[:debug]
6
- end
7
-
8
- def hash_equals?(a, b)
9
- a_new = normalize_hash(a)
10
- b_new = normalize_hash(b)
11
- hash1 = a_new.merge(b_new)
12
- hash2 = b_new.merge(a_new)
13
- hash1 == hash2
14
- end
15
-
16
- def symbolize_keys(obj)
17
- return obj.inject({}){|memo,(k,v)| memo[k.to_sym] = symbolize_keys(v); memo} if obj.is_a? Hash
18
- return obj.inject([]){|memo,v | memo << symbolize_keys(v); memo} if obj.is_a? Array
19
- obj
20
- end
21
-
22
- def normalize_hash(hash)
23
- result = hash.dup
24
- result.delete(:hostid) #TODO remove to logig. TemplateID and HostID has different id
25
- result.each do |key, value|
26
- case value
27
- when Array
28
- result.delete(key)
29
- else
30
- result[key] = value.to_s
31
- end
32
- end
33
- result
34
- end
35
-
36
- def parse_keys(data)
37
- case data
38
- when Hash
39
- data.empty? ? nil : data[keys][0].to_i
40
- when TrueClass
41
- true
42
- when FalseClass
43
- false
44
- else
45
- nil
46
- end
47
- end
48
-
49
- def merge_params(params)
50
- result = JSON.generate(default_options).to_s + "," + JSON.generate(params).to_s
51
- JSON.parse(result.gsub('},{', ','))
52
- end
53
-
54
- end
55
- end
@@ -1,33 +0,0 @@
1
- class ZabbixApi
2
- class Basic
3
-
4
- def initialize(client)
5
- @client = client
6
- end
7
-
8
- def method_name
9
- raise "Can't call method_name here"
10
- end
11
-
12
- def default_options
13
- {}
14
- end
15
-
16
- def keys
17
- key + "s"
18
- end
19
-
20
- def key
21
- method_name + "id"
22
- end
23
-
24
- def indentify
25
- raise "Can't call indentify here"
26
- end
27
-
28
- def array_flag
29
- false
30
- end
31
-
32
- end
33
- end
@@ -1,45 +0,0 @@
1
- class ZabbixApi
2
- class Applications
3
-
4
- def initialize(client)
5
- @client = client
6
- end
7
-
8
- def create(data)
9
- result = @client.api_request(:method => "application.create", :params => [data])
10
- result.empty? ? nil : result['applicationids'][0].to_i
11
- end
12
-
13
- def add(data)
14
- create(data)
15
- end
16
-
17
- def delete(data)
18
- result = @client.api_request(:method => "application.delete", :params => [data])
19
- result.empty? ? nil : result['applicationids'][0].to_i
20
- end
21
-
22
- def get_or_create(data)
23
- unless (appid = get_id(data))
24
- appid = create(data)
25
- end
26
- appid
27
- end
28
-
29
- def destroy(data)
30
- delete(data)
31
- end
32
-
33
- def get_full_data(data)
34
- @client.api_request(:method => "application.get", :params => {:filter => data, :output => "extend"})
35
- end
36
-
37
- def get_id(data)
38
- result = get_full_data(data)
39
- applicationid = nil
40
- result.each { |app| applicationid = app['applicationid'].to_i if app['name'] == data[:name] }
41
- applicationid
42
- end
43
-
44
- end
45
- end
@@ -1,15 +0,0 @@
1
- class ZabbixApi
2
-
3
- class BaseError < RuntimeError
4
- end
5
-
6
- class ApiError < BaseError
7
- end
8
-
9
- class HttpError < BaseError
10
- end
11
-
12
- class SocketError < BaseError
13
- end
14
-
15
- end
@@ -1,66 +0,0 @@
1
- class ZabbixApi
2
- class Graphs < Basic
3
-
4
- def array_flag
5
- true
6
- end
7
-
8
- def method_name
9
- "graph"
10
- end
11
-
12
- def indentify
13
- "name"
14
- end
15
-
16
- def get_full_data(data)
17
- log "[DEBUG] Call get_full_data with parametrs: #{data.inspect}"
18
-
19
- @client.api_request(
20
- :method => "#{method_name}.get",
21
- :params => {
22
- :search => {
23
- indentify.to_sym => data[indentify.to_sym]
24
- },
25
- :output => "extend"
26
- }
27
- )
28
- end
29
-
30
- def get_ids_by_host(data)
31
- ids = []
32
- graphs = Hash.new
33
- result = @client.api_request(:method => "graph.get", :params => {:filter => {:host => data[:host]}, :output => "extend"})
34
- result.each do |graph|
35
- num = graph['graphid']
36
- name = graph['name']
37
- graphs[name] = num
38
- filter = data[:filter]
39
-
40
- unless filter.nil?
41
- if /#{filter}/ =~ name
42
- ids.push(graphs[name])
43
- end
44
- else
45
- ids.push(graphs[name])
46
- end
47
- end
48
- ids
49
- end
50
-
51
- def get_items(data)
52
- @client.api_request(:method => "graphitem.get", :params => { :graphids => [data], :output => "extend" } )
53
- end
54
-
55
- def create_or_update(data)
56
- graphid = get_id(:name => data[:name], :templateid => data[:templateid])
57
- graphid ? _update(data.merge(:graphid => graphid)) : create(data)
58
- end
59
-
60
- def _update(data)
61
- data.delete(:name)
62
- update(data)
63
- end
64
-
65
- end
66
- end