zabbixapi 3.1.0 → 3.2.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 (64) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +9 -0
  3. data/CHANGELOG.md +5 -0
  4. data/{LICENSE → LICENSE.md} +1 -1
  5. data/README.md +53 -569
  6. data/lib/zabbixapi.rb +102 -65
  7. data/lib/zabbixapi/basic/basic_alias.rb +21 -4
  8. data/lib/zabbixapi/basic/basic_func.rb +56 -23
  9. data/lib/zabbixapi/basic/basic_init.rb +21 -4
  10. data/lib/zabbixapi/basic/basic_logic.rb +75 -18
  11. data/lib/zabbixapi/classes/actions.rb +8 -4
  12. data/lib/zabbixapi/classes/applications.rb +20 -6
  13. data/lib/zabbixapi/classes/configurations.rb +23 -17
  14. data/lib/zabbixapi/classes/errors.rb +2 -4
  15. data/lib/zabbixapi/classes/graphs.rb +65 -15
  16. data/lib/zabbixapi/classes/hostgroups.rb +12 -4
  17. data/lib/zabbixapi/classes/hosts.rb +36 -10
  18. data/lib/zabbixapi/classes/httptests.rb +24 -4
  19. data/lib/zabbixapi/classes/items.rb +24 -5
  20. data/lib/zabbixapi/classes/maintenance.rb +8 -4
  21. data/lib/zabbixapi/classes/mediatypes.rb +20 -13
  22. data/lib/zabbixapi/classes/proxies.rb +29 -8
  23. data/lib/zabbixapi/classes/screens.rb +41 -25
  24. data/lib/zabbixapi/classes/server.rb +8 -4
  25. data/lib/zabbixapi/classes/templates.rb +46 -43
  26. data/lib/zabbixapi/classes/triggers.rb +43 -16
  27. data/lib/zabbixapi/classes/unusable.rb +0 -2
  28. data/lib/zabbixapi/classes/usergroups.rb +33 -26
  29. data/lib/zabbixapi/classes/usermacros.rb +137 -31
  30. data/lib/zabbixapi/classes/users.rb +32 -10
  31. data/lib/zabbixapi/classes/valuemaps.rb +50 -0
  32. data/lib/zabbixapi/client.rb +61 -22
  33. data/lib/zabbixapi/version.rb +1 -1
  34. data/zabbixapi.gemspec +26 -23
  35. metadata +25 -73
  36. data/.gitignore +0 -7
  37. data/.rspec +0 -1
  38. data/.travis.yml +0 -41
  39. data/Gemfile +0 -3
  40. data/Gemfile.lock +0 -36
  41. data/Rakefile +0 -1
  42. data/json-1.x.Gemfile +0 -4
  43. data/json-1.x.Gemfile.lock +0 -28
  44. data/spec/action.rb +0 -89
  45. data/spec/application.rb +0 -83
  46. data/spec/basic_func.rb +0 -4
  47. data/spec/configuration.rb +0 -122
  48. data/spec/graph.rb +0 -135
  49. data/spec/host.rb +0 -176
  50. data/spec/hostgroup.rb +0 -55
  51. data/spec/httptest.rb +0 -136
  52. data/spec/item.rb +0 -134
  53. data/spec/maintenance.rb +0 -81
  54. data/spec/mediatype.rb +0 -50
  55. data/spec/query.rb +0 -18
  56. data/spec/screen.rb +0 -88
  57. data/spec/script.rb +0 -123
  58. data/spec/server.rb +0 -15
  59. data/spec/spec_helper.rb +0 -21
  60. data/spec/template.rb +0 -148
  61. data/spec/trigger.rb +0 -103
  62. data/spec/user.rb +0 -116
  63. data/spec/usergroup.rb +0 -85
  64. data/spec/usermacro.rb +0 -190
@@ -1,127 +1,164 @@
1
- require "zabbixapi/version"
2
- require "zabbixapi/client"
3
-
4
- require "zabbixapi/basic/basic_alias"
5
- require "zabbixapi/basic/basic_func"
6
- require "zabbixapi/basic/basic_init"
7
- require "zabbixapi/basic/basic_logic"
8
-
9
- require "zabbixapi/classes/applications"
10
- require "zabbixapi/classes/errors"
11
- require "zabbixapi/classes/graphs"
12
- require "zabbixapi/classes/hostgroups"
13
- require "zabbixapi/classes/maintenance"
14
- require "zabbixapi/classes/hosts"
15
- require "zabbixapi/classes/httptests"
16
- require "zabbixapi/classes/items"
17
- require "zabbixapi/classes/mediatypes"
18
- require "zabbixapi/classes/proxies"
19
- require "zabbixapi/classes/screens"
20
- require "zabbixapi/classes/server"
21
- require "zabbixapi/classes/templates"
22
- require "zabbixapi/classes/triggers"
23
- require "zabbixapi/classes/unusable"
24
- require "zabbixapi/classes/usergroups"
25
- require "zabbixapi/classes/usermacros"
26
- require "zabbixapi/classes/users"
27
- require "zabbixapi/classes/configurations"
28
- require "zabbixapi/classes/actions"
29
- require "zabbixapi/classes/scripts"
1
+ require 'zabbixapi/version'
2
+ require 'zabbixapi/client'
3
+
4
+ require 'zabbixapi/basic/basic_alias'
5
+ require 'zabbixapi/basic/basic_func'
6
+ require 'zabbixapi/basic/basic_init'
7
+ require 'zabbixapi/basic/basic_logic'
8
+
9
+ require 'zabbixapi/classes/actions'
10
+ require 'zabbixapi/classes/applications'
11
+ require 'zabbixapi/classes/configurations'
12
+ require 'zabbixapi/classes/errors'
13
+ require 'zabbixapi/classes/graphs'
14
+ require 'zabbixapi/classes/hostgroups'
15
+ require 'zabbixapi/classes/hosts'
16
+ require 'zabbixapi/classes/httptests'
17
+ require 'zabbixapi/classes/items'
18
+ require 'zabbixapi/classes/maintenance'
19
+ require 'zabbixapi/classes/mediatypes'
20
+ require 'zabbixapi/classes/proxies'
21
+ require 'zabbixapi/classes/screens'
22
+ require 'zabbixapi/classes/scripts'
23
+ require 'zabbixapi/classes/server'
24
+ require 'zabbixapi/classes/templates'
25
+ require 'zabbixapi/classes/triggers'
26
+ require 'zabbixapi/classes/unusable'
27
+ require 'zabbixapi/classes/usergroups'
28
+ require 'zabbixapi/classes/usermacros'
29
+ require 'zabbixapi/classes/users'
30
+ require 'zabbixapi/classes/valuemaps'
30
31
 
31
32
  class ZabbixApi
33
+ # @return [ZabbixApi::Client]
34
+ attr_reader :client
32
35
 
33
- attr :client
34
-
36
+ # Initializes a new ZabbixApi object
37
+ #
38
+ # @param options [Hash]
39
+ # @return [ZabbixApi]
35
40
  def self.connect(options = {})
36
41
  new(options)
37
42
  end
38
43
 
44
+ # @return [ZabbixApi]
39
45
  def self.current
40
46
  @current ||= ZabbixApi.new
41
47
  end
42
48
 
49
+ # Executes an API request directly using a custom query
50
+ #
51
+ # @param data [Hash]
52
+ # @return [Hash]
43
53
  def query(data)
44
54
  @client.api_request(:method => data[:method], :params => data[:params])
45
55
  end
46
56
 
57
+ # Initializes a new ZabbixApi object
58
+ #
59
+ # @param options [Hash]
60
+ # @return [ZabbixApi::Client]
47
61
  def initialize(options = {})
48
62
  @client = Client.new(options)
49
63
  end
50
64
 
51
- def server
52
- @server ||= Server.new(@client)
65
+ # @return [ZabbixApi::Actions]
66
+ def actions
67
+ @actions ||= Actions.new(@client)
53
68
  end
54
69
 
55
- def users
56
- @users ||= Users.new(@client)
70
+ # @return [ZabbixApi::Applications]
71
+ def applications
72
+ @applications ||= Applications.new(@client)
57
73
  end
58
74
 
59
- def items
60
- @items ||= Items.new(@client)
75
+ # @return [ZabbixApi::Configurations]
76
+ def configurations
77
+ @configurations ||= Configurations.new(@client)
61
78
  end
62
79
 
63
- def hosts
64
- @hosts ||= Hosts.new(@client)
80
+ # @return [ZabbixApi::Graphs]
81
+ def graphs
82
+ @graphs ||= Graphs.new(@client)
65
83
  end
66
84
 
67
- def httptests
68
- @httptests ||= HttpTests.new(@client)
85
+ # @return [ZabbixApi::HostGroups]
86
+ def hostgroups
87
+ @hostgroups ||= HostGroups.new(@client)
69
88
  end
70
89
 
71
- def applications
72
- @applications ||= Applications.new(@client)
90
+ # @return [ZabbixApi::Hosts]
91
+ def hosts
92
+ @hosts ||= Hosts.new(@client)
73
93
  end
74
94
 
75
- def templates
76
- @templates ||= Templates.new(@client)
95
+ # @return [ZabbixApi::HttpTests]
96
+ def httptests
97
+ @httptests ||= HttpTests.new(@client)
77
98
  end
78
99
 
79
- def hostgroups
80
- @hostgroups ||= HostGroups.new(@client)
100
+ # @return [ZabbixApi::Items]
101
+ def items
102
+ @items ||= Items.new(@client)
81
103
  end
82
104
 
105
+ # @return [ZabbixApi::Maintenance]
83
106
  def maintenance
84
107
  @maintenance ||= Maintenance.new(@client)
85
108
  end
86
109
 
87
- def triggers
88
- @triggers ||= Triggers.new(@client)
89
- end
90
-
91
- def graphs
92
- @graphs ||= Graphs.new(@client)
110
+ # @return [ZabbixApi::Mediatypes]
111
+ def mediatypes
112
+ @mediatypes ||= Mediatypes.new(@client)
93
113
  end
94
114
 
115
+ # @return [ZabbixApi::Proxies]
95
116
  def proxies
96
117
  @proxies ||= Proxies.new(@client)
97
118
  end
98
119
 
120
+ # @return [ZabbixApi::Screens]
99
121
  def screens
100
122
  @screens ||= Screens.new(@client)
101
123
  end
102
124
 
103
- def usergroups
104
- @usergroups ||= Usergroups.new(@client)
125
+ # @return [ZabbixApi::Scripts]
126
+ def scripts
127
+ @scripts ||= Scripts.new(@client)
105
128
  end
106
129
 
107
- def usermacros
108
- @usermacros ||= Usermacros.new(@client)
130
+ # @return [ZabbixApi::Server]
131
+ def server
132
+ @server ||= Server.new(@client)
109
133
  end
110
134
 
111
- def mediatypes
112
- @mediatypes ||= Mediatypes.new(@client)
135
+ # @return [ZabbixApi::Templates]
136
+ def templates
137
+ @templates ||= Templates.new(@client)
113
138
  end
114
139
 
115
- def configurations
116
- @configurations ||= Configurations.new(@client)
140
+ # @return [ZabbixApi::Triggers]
141
+ def triggers
142
+ @triggers ||= Triggers.new(@client)
117
143
  end
118
144
 
119
- def actions
120
- @actions ||= Actions.new(@client)
145
+ # @return [ZabbixApi::Usergroups]
146
+ def usergroups
147
+ @usergroups ||= Usergroups.new(@client)
121
148
  end
122
149
 
123
- def scripts
124
- @scripts ||= Scripts.new(@client)
150
+ # @return [ZabbixApi::Usermacros]
151
+ def usermacros
152
+ @usermacros ||= Usermacros.new(@client)
153
+ end
154
+
155
+ # @return [ZabbixApi::Users]
156
+ def users
157
+ @users ||= Users.new(@client)
125
158
  end
126
159
 
160
+ # @return [ZabbixApi::ValueMaps]
161
+ def valuemaps
162
+ @valuemaps ||= ValueMaps.new(@client)
163
+ end
127
164
  end
@@ -1,20 +1,37 @@
1
1
  class ZabbixApi
2
2
  class Basic
3
-
3
+ # Get Zabbix object data from API by id
4
+ #
5
+ # @param data [Hash] Should include object's id field name (indentify) and id value
6
+ # @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
7
+ # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
8
+ # @return [Hash]
4
9
  def get(data)
5
10
  get_full_data(data)
6
11
  end
7
12
 
13
+ # Add new Zabbix object using API create
14
+ #
15
+ # @param data [Hash]
16
+ # @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
17
+ # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
18
+ # @return [Integer] The object id if a single object is created
19
+ # @return [Boolean] True/False if multiple objects are created
8
20
  def add(data)
9
21
  create(data)
10
22
  end
11
23
 
24
+ # Destroy Zabbix object using API delete
25
+ #
26
+ # @param data [Hash] Should include object's id field name (indentify) and id value
27
+ # @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
28
+ # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
29
+ # @return [Integer] The object id if a single object is deleted
30
+ # @return [Boolean] True/False if multiple objects are deleted
12
31
  def destroy(data)
13
32
  delete(data)
14
33
  end
15
34
 
16
- def method_name
17
- end
18
-
35
+ def method_name; end
19
36
  end
20
37
  end
@@ -1,10 +1,17 @@
1
1
  class ZabbixApi
2
2
  class Basic
3
-
3
+ # Log messages to stdout when debugging
4
+ #
5
+ # @param message [String]
4
6
  def log(message)
5
- puts "#{message}" if @client.options[:debug]
7
+ puts message.to_s if @client.options[:debug]
6
8
  end
7
9
 
10
+ # Compare two hashes for equality
11
+ #
12
+ # @param a [Hash]
13
+ # @param b [Hash]
14
+ # @return [Boolean]
8
15
  def hash_equals?(a, b)
9
16
  a_new = normalize_hash(a)
10
17
  b_new = normalize_hash(b)
@@ -13,40 +20,64 @@ class ZabbixApi
13
20
  hash1 == hash2
14
21
  end
15
22
 
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
23
+ # Convert all hash/array keys to symbols
24
+ #
25
+ # @param object [Array, Hash]
26
+ # @return [Array, Hash]
27
+ def symbolize_keys(object)
28
+ if object.is_a?(Array)
29
+ object.each_with_index do |val, index|
30
+ object[index] = symbolize_keys(val)
31
+ end
32
+ elsif object.is_a?(Hash)
33
+ object.keys.each do |key|
34
+ object[key.to_sym] = symbolize_keys(object.delete(key))
35
+ end
36
+ end
37
+ object
20
38
  end
21
39
 
40
+ # Normalize all hash values to strings
41
+ #
42
+ # @param hash [Hash]
43
+ # @return [Hash]
22
44
  def normalize_hash(hash)
23
45
  result = hash.dup
24
- result.delete(:hostid) #TODO remove to logig. TemplateID and HostID has different id
46
+
47
+ result.delete(:hostid) # TODO: remove to logig. TemplateID and HostID has different id
48
+
25
49
  result.each do |key, value|
26
- case value
27
- when Array
28
- result[key] = normalize_array(value)
29
- else
30
- result[key] = value.to_s
31
- end
50
+ result[key] = value.is_a?(Array) ? normalize_array(value) : value.to_s
32
51
  end
52
+
33
53
  result
34
54
  end
35
55
 
56
+ # Normalize all array values to strings
57
+ #
58
+ # @param array [Array]
59
+ # @return [Array]
36
60
  def normalize_array(array)
37
61
  result = []
62
+
38
63
  array.each do |e|
39
- case e
40
- when Array
41
- result << normalize_array(e)
42
- when Hash
43
- result << normalize_hash(e)
44
- else
45
- result << e.to_s
64
+ if e.is_a?(Array)
65
+ result.push(normalize_array(e))
66
+ elsif e.is_a?(Hash)
67
+ result.push(normalize_hash(e))
68
+ else
69
+ result.push(e.to_s)
46
70
  end
47
71
  end
72
+
73
+ result
48
74
  end
49
75
 
76
+ # Parse a data hash for id key or boolean to return
77
+ #
78
+ # @param data [Hash]
79
+ # @return [Integer] The object id if a single object hash is provided with key
80
+ # @return [Boolean] True/False if multiple class object hash is provided
50
81
  def parse_keys(data)
51
82
  case data
52
83
  when Hash
@@ -55,15 +86,17 @@ class ZabbixApi
55
86
  true
56
87
  when FalseClass
57
88
  false
58
- else
59
- nil
60
89
  end
61
90
  end
62
91
 
92
+ # Merge two hashes into a single new hash
93
+ #
94
+ # @param a [Hash]
95
+ # @param b [Hash]
96
+ # @return [Hash]
63
97
  def merge_params(a, b)
64
98
  new = a.dup
65
99
  new.merge(b)
66
100
  end
67
-
68
101
  end
69
102
  end
@@ -1,29 +1,46 @@
1
1
  class ZabbixApi
2
2
  class Basic
3
-
3
+ # Initializes a new Basic object with ZabbixApi Client
4
+ #
5
+ # @param client [ZabbixApi::Client]
6
+ # @return [ZabbixApi::Client]
4
7
  def initialize(client)
5
8
  @client = client
6
9
  end
7
10
 
11
+ # Placeholder for inherited objects to provide object-specific method name
12
+ #
13
+ # @raise [ApiError] Basic object does not directly support method_name
8
14
  def method_name
9
15
  raise ApiError.new("Can't call method_name here")
10
16
  end
11
17
 
18
+ # Placeholder for inherited objects to provide default options
19
+ #
20
+ # @return [Hash]
12
21
  def default_options
13
22
  {}
14
23
  end
15
24
 
25
+ # Returns the object's plural id field name (indentify) based on key
26
+ #
27
+ # @return [String]
16
28
  def keys
17
- key + "s"
29
+ key + 's'
18
30
  end
19
31
 
32
+ # Returns the object's id field name (indentify) based on method_name + id
33
+ #
34
+ # @return [String]
20
35
  def key
21
- method_name + "id"
36
+ method_name + 'id'
22
37
  end
23
38
 
39
+ # Placeholder for inherited objects to provide object-specific id field name
40
+ #
41
+ # @raise [ApiError] Basic object does not directly support indentify
24
42
  def indentify
25
43
  raise ApiError.new("Can't call indentify here")
26
44
  end
27
-
28
45
  end
29
46
  end
@@ -1,6 +1,12 @@
1
1
  class ZabbixApi
2
2
  class Basic
3
-
3
+ # Create new Zabbix object using API (with defaults)
4
+ #
5
+ # @param data [Hash]
6
+ # @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
7
+ # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
8
+ # @return [Integer] The object id if a single object is created
9
+ # @return [Boolean] True/False if multiple objects are created
4
10
  def create(data)
5
11
  log "[DEBUG] Call create with parameters: #{data.inspect}"
6
12
 
@@ -10,6 +16,13 @@ class ZabbixApi
10
16
  parse_keys result
11
17
  end
12
18
 
19
+ # Delete Zabbix object using API
20
+ #
21
+ # @param data [Hash] Should include object's id field name (indentify) and id value
22
+ # @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
23
+ # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
24
+ # @return [Integer] The object id if a single object is deleted
25
+ # @return [Boolean] True/False if multiple objects are deleted
13
26
  def delete(data)
14
27
  log "[DEBUG] Call delete with parameters: #{data.inspect}"
15
28
 
@@ -18,6 +31,13 @@ class ZabbixApi
18
31
  parse_keys result
19
32
  end
20
33
 
34
+ # Create or update Zabbix object using API
35
+ #
36
+ # @param data [Hash] Should include object's id field name (indentify) and id value
37
+ # @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
38
+ # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
39
+ # @return [Integer] The object id if a single object is created
40
+ # @return [Boolean] True/False if multiple objects are created
21
41
  def create_or_update(data)
22
42
  log "[DEBUG] Call create_or_update with parameters: #{data.inspect}"
23
43
 
@@ -25,26 +45,36 @@ class ZabbixApi
25
45
  id ? update(data.merge(key.to_sym => id.to_s)) : create(data)
26
46
  end
27
47
 
28
- def update(data, force=false)
48
+ # Update Zabbix object using API
49
+ #
50
+ # @param data [Hash] Should include object's id field name (indentify) and id value
51
+ # @param force [Boolean] Whether to force an object update even if provided data matches Zabbix
52
+ # @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
53
+ # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
54
+ # @return [Integer] The object id if a single object is created
55
+ # @return [Boolean] True/False if multiple objects are created
56
+ def update(data, force = false)
29
57
  log "[DEBUG] Call update with parameters: #{data.inspect}"
30
-
31
58
  dump = {}
32
- item_id = data[key.to_sym].to_i
33
59
  dump_by_id(key.to_sym => data[key.to_sym]).each do |item|
34
60
  dump = symbolize_keys(item) if item[key].to_i == data[key.to_sym].to_i
35
61
  end
36
-
37
- if hash_equals?(dump, data) and not force
62
+ if hash_equals?(dump, data) && !force
38
63
  log "[DEBUG] Equal keys #{dump} and #{data}, skip update"
39
- item_id
64
+ data[key.to_sym].to_i
40
65
  else
41
66
  data_update = [data]
42
67
  result = @client.api_request(:method => "#{method_name}.update", :params => data_update)
43
68
  parse_keys result
44
69
  end
45
-
46
70
  end
47
71
 
72
+ # Get full/extended Zabbix object data from API
73
+ #
74
+ # @param data [Hash] Should include object's id field name (indentify) and id value
75
+ # @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
76
+ # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
77
+ # @return [Hash]
48
78
  def get_full_data(data)
49
79
  log "[DEBUG] Call get_full_data with parameters: #{data.inspect}"
50
80
 
@@ -52,13 +82,19 @@ class ZabbixApi
52
82
  :method => "#{method_name}.get",
53
83
  :params => {
54
84
  :filter => {
55
- indentify.to_sym => data[indentify.to_sym]
85
+ indentify.to_sym => data[indentify.to_sym],
56
86
  },
57
- :output => "extend"
87
+ :output => 'extend',
58
88
  }
59
89
  )
60
90
  end
61
91
 
92
+ # Get raw Zabbix object data from API
93
+ #
94
+ # @param data [Hash]
95
+ # @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
96
+ # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
97
+ # @return [Hash]
62
98
  def get_raw(data)
63
99
  log "[DEBUG] Call get_raw with parameters: #{data.inspect}"
64
100
 
@@ -68,6 +104,12 @@ class ZabbixApi
68
104
  )
69
105
  end
70
106
 
107
+ # Dump Zabbix object data by key from API
108
+ #
109
+ # @param data [Hash] Should include desired object's key and value
110
+ # @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
111
+ # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
112
+ # @return [Hash]
71
113
  def dump_by_id(data)
72
114
  log "[DEBUG] Call dump_by_id with parameters: #{data.inspect}"
73
115
 
@@ -75,34 +117,44 @@ class ZabbixApi
75
117
  :method => "#{method_name}.get",
76
118
  :params => {
77
119
  :filter => {
78
- key.to_sym => data[key.to_sym]
120
+ key.to_sym => data[key.to_sym],
79
121
  },
80
- :output => "extend"
122
+ :output => 'extend',
81
123
  }
82
124
  )
83
125
  end
84
126
 
127
+ # Get full/extended Zabbix data for all objects of type/class from API
128
+ #
129
+ # @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
130
+ # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
131
+ # @return [Array<Hash>] Array of matching objects
85
132
  def all
86
133
  result = {}
87
- @client.api_request(:method => "#{method_name}.get", :params => {:output => "extend"}).each do |item|
134
+ @client.api_request(:method => "#{method_name}.get", :params => {:output => 'extend'}).each do |item|
88
135
  result[item[indentify]] = item[key]
89
136
  end
90
137
  result
91
138
  end
92
139
 
140
+ # Get Zabbix object id from API based on provided data
141
+ #
142
+ # @param data [Hash]
143
+ # @raise [ApiError] Error returned when there is a problem with the Zabbix API call or missing object's id field name (indentify).
144
+ # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
145
+ # @return [Integer] Zabbix object id
93
146
  def get_id(data)
94
147
  log "[DEBUG] Call get_id with parameters: #{data.inspect}"
95
-
96
148
  # symbolize keys if the user used string keys instead of symbols
97
149
  data = symbolize_keys(data) if data.key?(indentify)
98
- # raise an error if indentify name was not supplied
150
+ # raise an error if indentify name was not supplied
99
151
  name = data[indentify.to_sym]
100
- raise ApiError.new("#{indentify} not supplied in call to get_id") if name == nil
152
+ raise ApiError.new("#{indentify} not supplied in call to get_id") if name.nil?
101
153
  result = @client.api_request(
102
154
  :method => "#{method_name}.get",
103
155
  :params => {
104
156
  :filter => data,
105
- :output => [key, indentify]
157
+ :output => [key, indentify],
106
158
  }
107
159
  )
108
160
  id = nil
@@ -110,6 +162,12 @@ class ZabbixApi
110
162
  id
111
163
  end
112
164
 
165
+ # Get or Create Zabbix object using API
166
+ #
167
+ # @param data [Hash] Should include object's id field name (indentify) and id value
168
+ # @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
169
+ # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
170
+ # @return [Integer] Zabbix object id
113
171
  def get_or_create(data)
114
172
  log "[DEBUG] Call get_or_create with parameters: #{data.inspect}"
115
173
 
@@ -118,6 +176,5 @@ class ZabbixApi
118
176
  end
119
177
  id
120
178
  end
121
-
122
179
  end
123
180
  end