zabbixapi 4.0.0 → 5.0.0.pre.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +20 -0
  3. data/LICENSE.md +1 -1
  4. data/README.md +30 -17
  5. data/lib/zabbixapi.rb +31 -1
  6. data/lib/zabbixapi/basic/basic_alias.rb +2 -2
  7. data/lib/zabbixapi/basic/basic_func.rb +13 -12
  8. data/lib/zabbixapi/basic/basic_init.rb +5 -5
  9. data/lib/zabbixapi/basic/basic_logic.rb +35 -34
  10. data/lib/zabbixapi/classes/actions.rb +25 -1
  11. data/lib/zabbixapi/classes/applications.rb +4 -4
  12. data/lib/zabbixapi/classes/configurations.rb +3 -3
  13. data/lib/zabbixapi/classes/drules.rb +55 -0
  14. data/lib/zabbixapi/classes/errors.rb +5 -2
  15. data/lib/zabbixapi/classes/events.rb +17 -0
  16. data/lib/zabbixapi/classes/graphs.rb +23 -33
  17. data/lib/zabbixapi/classes/hostgroups.rb +1 -1
  18. data/lib/zabbixapi/classes/hosts.rb +20 -20
  19. data/lib/zabbixapi/classes/httptests.rb +7 -7
  20. data/lib/zabbixapi/classes/items.rb +36 -36
  21. data/lib/zabbixapi/classes/maintenance.rb +1 -1
  22. data/lib/zabbixapi/classes/mediatypes.rb +86 -11
  23. data/lib/zabbixapi/classes/problems.rb +101 -0
  24. data/lib/zabbixapi/classes/proxies.rb +4 -4
  25. data/lib/zabbixapi/classes/roles.rb +114 -0
  26. data/lib/zabbixapi/classes/screens.rb +18 -17
  27. data/lib/zabbixapi/classes/scripts.rb +18 -10
  28. data/lib/zabbixapi/classes/server.rb +1 -1
  29. data/lib/zabbixapi/classes/templates.rb +19 -21
  30. data/lib/zabbixapi/classes/triggers.rb +14 -13
  31. data/lib/zabbixapi/classes/unusable.rb +1 -1
  32. data/lib/zabbixapi/classes/usergroups.rb +16 -19
  33. data/lib/zabbixapi/classes/usermacros.rb +24 -24
  34. data/lib/zabbixapi/classes/users.rb +16 -17
  35. data/lib/zabbixapi/classes/valuemaps.rb +4 -4
  36. data/lib/zabbixapi/client.rb +34 -16
  37. data/lib/zabbixapi/version.rb +1 -1
  38. data/zabbixapi.gemspec +2 -2
  39. metadata +16 -14
  40. data/.yardopts +0 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c92de7e8f577d018cb8da54114638729fb7117d5
4
- data.tar.gz: 5dc0590f4332ba0590cb07eed6c2cb1f07c73d38
2
+ SHA256:
3
+ metadata.gz: 872ce78b417080b9ad0affdf398753332f6c88fb3cfac7b5db991413711e2b65
4
+ data.tar.gz: 077a81ef6f1d562091f61ab58b973192f12b4d1579c9683d8421779c907e6e33
5
5
  SHA512:
6
- metadata.gz: ef2229602eac1fac5257b9d32c2d45f079d163a989a3f25efa2ae80390ea3ffd840f6f8a637dcd73df593054480c21c3b7674b5c3f20b4300bd01a7ebf3f2f6f
7
- data.tar.gz: 159e41fb0f8467456c808c0e4895e87aaf8f3ee0d0d462879815c568f8773ce3838be74234581eca655f466a234155c425a89d43b3018efa61e5f65c54476542
6
+ metadata.gz: c818c7285117d51cc70dc770ba43c75ae5c8cab4ded5e553b2ffcb5a1256b1578da4720faeec57cdc086c02dbc152ccc540c620aba27b02a0426ed0eefedd289
7
+ data.tar.gz: ba45247a6463b805aa8fbcd3c1bf8ec2d9531e6a3e5db9bf82805ba29fc9c6a972bf8a0f8cb8f063c69b7429337bd89b1a7fe30d9e0054cbd73e1ca64ff7ada3
@@ -1,3 +1,23 @@
1
+ #CHANGELOG
2
+
3
+ ## 4.2.0
4
+ [PR #102](https://github.com/express42/zabbixapi/pull/102) Add events get method method. Fixed all testing failures. (Thanks @kevin-j-smith)
5
+
6
+ ## 4.1.2
7
+ [PR #99](https://github.com/express42/zabbixapi/pull/99) Patch addressing log error function not found
8
+
9
+ ## 4.1.1
10
+
11
+ [PR #97](https://github.com/express42/zabbixapi/pull/97) Bumped version
12
+
13
+ [PR #98](https://github.com/express42/zabbixapi/pull/98) Removed strict zabbix versioning error
14
+
15
+ ## 4.1.0
16
+
17
+ [PR #82](https://github.com/express42/zabbixapi/pull/82) Add logout method (Thanks @baurmatt)
18
+
19
+ [PR #86](https://github.com/express42/zabbixapi/pull/86) Feature: add support for Discovery Rules (`drule` API) (Thanks @lehn-etracker)
20
+
1
21
  ## 4.0.0
2
22
 
3
23
  [PR #90](https://github.com/express42/zabbixapi/pull/90) Add 4.0 support (Thanks @svdasein)
data/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2017 Express 42
3
+ Copyright (c) 2015-2018 Express 42
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
data/README.md CHANGED
@@ -1,15 +1,21 @@
1
1
  # Ruby Zabbix Api Module
2
2
 
3
3
  [![Gem Version](http://img.shields.io/gem/v/zabbixapi.svg)][gem]
4
- [![Build Status](http://img.shields.io/travis/express42/zabbixapi.svg)][travis]
4
+ [![Build Status](https://github.com/anapsix/zabbixapi/workflows/CI/badge.svg)][github-ci]
5
5
 
6
6
  [gem]: https://rubygems.org/gems/zabbixapi
7
- [travis]: https://travis-ci.org/express42/zabbixapi
7
+ [github-ci]: https://github.com/express42/zabbixapi/actions?query=workflow%3ACI
8
8
 
9
9
  Simple and lightweight ruby module for working with [Zabbix][Zabbix] via the [Zabbix API][Zabbix API]
10
10
 
11
11
  ## Installation
12
- gem install zabbixapi
12
+ ```sh
13
+ # latest
14
+ gem install zabbixapi
15
+
16
+ # specific version
17
+ gem install zabbixapi -v 4.2.0
18
+ ```
13
19
 
14
20
  ## Documentation
15
21
  [http://rdoc.info/gems/zabbixapi][documentation]
@@ -22,7 +28,10 @@ Simple and lightweight ruby module for working with [Zabbix][Zabbix] via the [Za
22
28
  [examples]: https://github.com/express42/zabbixapi/tree/master/examples
23
29
 
24
30
  ## Version Policy
25
- We support only two last versions of zabbix (3.4 and 4.0), so you should consider all previous versions deprecated.
31
+
32
+ **NOTE:** `master` branch is used for ongoing development on Zabbix API 5.x (5.0 and 5.2).
33
+
34
+ We support only two last versions of zabbix (5.0 and 5.2), so you should consider all previous versions deprecated.
26
35
 
27
36
  * Zabbix 1.8.2 (api version 1.2) | zabbixapi 0.6.x | [branch zabbix1.8](https://github.com/express42/zabbixapi/tree/zabbix1.8)
28
37
  * Zabbix 1.8.9 (api version 1.3) | zabbixapi 0.6.x | [branch zabbix1.8](https://github.com/express42/zabbixapi/tree/zabbix1.8)
@@ -30,18 +39,19 @@ We support only two last versions of zabbix (3.4 and 4.0), so you should conside
30
39
  * Zabbix 2.2.x (api version 2.2.x) | zabbixapi 2.2.x | [branch zabbix2.2](https://github.com/express42/zabbixapi/tree/zabbix2.2)
31
40
  * Zabbix 2.4.x (api version 2.2.x) | zabbixapi 2.4.x | [branch zabbix2.4](https://github.com/express42/zabbixapi/tree/zabbix2.4)
32
41
  * Zabbix 3.0.x (api version 3.0.x) | zabbixapi 3.0.x | [branch zabbix3.0](https://github.com/express42/zabbixapi/tree/zabbix3.0)
33
- * Zabbix 3.2.x (api version 3.2.x) | zabbixapi 3.0.x | [branch zabbix3.2](https://github.com/express42/zabbixapi/tree/zabbix3.2)
42
+ * Zabbix 3.2.x (api version 3.2.x) | zabbixapi 3.2.x | [branch zabbix3.2](https://github.com/express42/zabbixapi/tree/zabbix3.2)
43
+ * Zabbix 4.0.x (api version 4.0.x) | zabbixapi 4.1.x | [branch zabbix4.0](https://github.com/express42/zabbixapi/tree/zabbix4.0)
44
+ * Zabbix 4.2.x (api version 4.2.x) | zabbixapi 4.1.x | [branch zabbix4.0](https://github.com/express42/zabbixapi/tree/zabbix4.0)
45
+ * Zabbix 4.4.x (api version 4.4.x) | zabbixapi 4.2.x | [branch zabbix4.2](https://github.com/express42/zabbixapi/tree/zabbix4.2)
34
46
 
35
47
  ## Supported Ruby Versions
36
- This library aims to support and is [tested against][travis] the following Ruby
48
+ This library aims to support and is [tested against][github-ci] the following Ruby
37
49
  versions:
38
50
 
39
- * Ruby 2.0
40
- * Ruby 2.1
41
- * Ruby 2.2
42
- * Ruby 2.3
43
- * Ruby 2.4
44
- * JRuby 9.1.6.0
51
+ * Ruby 2.5
52
+ * Ruby 2.6
53
+ * Ruby 2.7
54
+ * JRuby 9.2.10.0
45
55
 
46
56
  If something doesn't work on one of these versions, it's a bug.
47
57
 
@@ -59,12 +69,12 @@ dropped.
59
69
  ## Dependencies
60
70
 
61
71
  * net/http
62
- * net/https
63
72
  * json
64
73
 
65
74
  ## Contributing
66
75
 
67
76
  * Fork the project.
77
+ * Base your work on the master branch.
68
78
  * Make your feature addition or bug fix, write tests, write documentation/examples.
69
79
  * Commit, do not mess with rakefile, version.
70
80
  * Make a pull request.
@@ -75,11 +85,14 @@ dropped.
75
85
  * [Zabbix API docs][Zabbix API]
76
86
 
77
87
  [Zabbix]: https://www.zabbix.com
78
- [Zabbix API]: https://www.zabbix.com/documentation/3.2/manual/api
88
+ [Zabbix API]: https://www.zabbix.com/documentation/5.2/manual/api
79
89
 
80
90
  ## Copyright
81
- Copyright (c) 2015-2018 Express 42
82
91
 
83
- See [LICENSE][] for details.
92
+ - Copyright (c) 2021 [contributors]
93
+ - Copyright (c) 2015-2018 Express 42 and [contributors]
94
+
95
+ See [LICENSE] for details.
84
96
 
85
- [license]: LICENSE.md
97
+ [LICENSE]: LICENSE.md
98
+ [contributors]: https://github.com/express42/zabbixapi/graphs/contributors
@@ -10,6 +10,7 @@ require 'zabbixapi/classes/actions'
10
10
  require 'zabbixapi/classes/applications'
11
11
  require 'zabbixapi/classes/configurations'
12
12
  require 'zabbixapi/classes/errors'
13
+ require 'zabbixapi/classes/events'
13
14
  require 'zabbixapi/classes/graphs'
14
15
  require 'zabbixapi/classes/hostgroups'
15
16
  require 'zabbixapi/classes/hosts'
@@ -18,6 +19,8 @@ require 'zabbixapi/classes/items'
18
19
  require 'zabbixapi/classes/maintenance'
19
20
  require 'zabbixapi/classes/mediatypes'
20
21
  require 'zabbixapi/classes/proxies'
22
+ require 'zabbixapi/classes/problems'
23
+ require 'zabbixapi/classes/roles'
21
24
  require 'zabbixapi/classes/screens'
22
25
  require 'zabbixapi/classes/scripts'
23
26
  require 'zabbixapi/classes/server'
@@ -28,6 +31,7 @@ require 'zabbixapi/classes/usergroups'
28
31
  require 'zabbixapi/classes/usermacros'
29
32
  require 'zabbixapi/classes/users'
30
33
  require 'zabbixapi/classes/valuemaps'
34
+ require 'zabbixapi/classes/drules'
31
35
 
32
36
  class ZabbixApi
33
37
  # @return [ZabbixApi::Client]
@@ -51,7 +55,13 @@ class ZabbixApi
51
55
  # @param data [Hash]
52
56
  # @return [Hash]
53
57
  def query(data)
54
- @client.api_request(:method => data[:method], :params => data[:params])
58
+ @client.api_request(method: data[:method], params: data[:params])
59
+ end
60
+
61
+ # Invalidate current authentication token
62
+ # @return [Boolean]
63
+ def logout
64
+ @client.logout
55
65
  end
56
66
 
57
67
  # Initializes a new ZabbixApi object
@@ -77,6 +87,11 @@ class ZabbixApi
77
87
  @configurations ||= Configurations.new(@client)
78
88
  end
79
89
 
90
+ # @return [ZabbixApi::Events]
91
+ def events
92
+ @events ||= Events.new(@client)
93
+ end
94
+
80
95
  # @return [ZabbixApi::Graphs]
81
96
  def graphs
82
97
  @graphs ||= Graphs.new(@client)
@@ -112,11 +127,21 @@ class ZabbixApi
112
127
  @mediatypes ||= Mediatypes.new(@client)
113
128
  end
114
129
 
130
+ # @return [ZabbixApi::Problems]
131
+ def problems
132
+ @problems ||= Problems.new(@client)
133
+ end
134
+
115
135
  # @return [ZabbixApi::Proxies]
116
136
  def proxies
117
137
  @proxies ||= Proxies.new(@client)
118
138
  end
119
139
 
140
+ # @return [ZabbixApi::Roles]
141
+ def roles
142
+ @roles ||= Roles.new(@client)
143
+ end
144
+
120
145
  # @return [ZabbixApi::Screens]
121
146
  def screens
122
147
  @screens ||= Screens.new(@client)
@@ -161,4 +186,9 @@ class ZabbixApi
161
186
  def valuemaps
162
187
  @valuemaps ||= ValueMaps.new(@client)
163
188
  end
189
+
190
+ # @return [ZabbixApi::Drules]
191
+ def drules
192
+ @drules ||= Drules.new(@client)
193
+ end
164
194
  end
@@ -2,7 +2,7 @@ class ZabbixApi
2
2
  class Basic
3
3
  # Get Zabbix object data from API by id
4
4
  #
5
- # @param data [Hash] Should include object's id field name (indentify) and id value
5
+ # @param data [Hash] Should include object's id field name (identify) and id value
6
6
  # @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
7
7
  # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
8
8
  # @return [Hash]
@@ -23,7 +23,7 @@ class ZabbixApi
23
23
 
24
24
  # Destroy Zabbix object using API delete
25
25
  #
26
- # @param data [Hash] Should include object's id field name (indentify) and id value
26
+ # @param data [Hash] Should include object's id field name (identify) and id value
27
27
  # @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
28
28
  # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
29
29
  # @return [Integer] The object id if a single object is deleted
@@ -9,14 +9,15 @@ class ZabbixApi
9
9
 
10
10
  # Compare two hashes for equality
11
11
  #
12
- # @param a [Hash]
13
- # @param b [Hash]
12
+ # @param first_hash [Hash]
13
+ # @param second_hash [Hash]
14
14
  # @return [Boolean]
15
- def hash_equals?(a, b)
16
- a_new = normalize_hash(a)
17
- b_new = normalize_hash(b)
18
- hash1 = a_new.merge(b_new)
19
- hash2 = b_new.merge(a_new)
15
+ def hash_equals?(first_hash, second_hash)
16
+ normalized_first_hash = normalize_hash(first_hash)
17
+ normalized_second_hash = normalize_hash(second_hash)
18
+
19
+ hash1 = normalized_first_hash.merge(normalized_second_hash)
20
+ hash2 = normalized_second_hash.merge(normalized_first_hash)
20
21
  hash1 == hash2
21
22
  end
22
23
 
@@ -91,12 +92,12 @@ class ZabbixApi
91
92
 
92
93
  # Merge two hashes into a single new hash
93
94
  #
94
- # @param a [Hash]
95
- # @param b [Hash]
95
+ # @param first_hash [Hash]
96
+ # @param second_hash [Hash]
96
97
  # @return [Hash]
97
- def merge_params(a, b)
98
- new = a.dup
99
- new.merge(b)
98
+ def merge_params(first_hash, second_hash)
99
+ new = first_hash.dup
100
+ new.merge(second_hash)
100
101
  end
101
102
  end
102
103
  end
@@ -22,14 +22,14 @@ class ZabbixApi
22
22
  {}
23
23
  end
24
24
 
25
- # Returns the object's plural id field name (indentify) based on key
25
+ # Returns the object's plural id field name (identify) based on key
26
26
  #
27
27
  # @return [String]
28
28
  def keys
29
29
  key + 's'
30
30
  end
31
31
 
32
- # Returns the object's id field name (indentify) based on method_name + id
32
+ # Returns the object's id field name (identify) based on method_name + id
33
33
  #
34
34
  # @return [String]
35
35
  def key
@@ -38,9 +38,9 @@ class ZabbixApi
38
38
 
39
39
  # Placeholder for inherited objects to provide object-specific id field name
40
40
  #
41
- # @raise [ApiError] Basic object does not directly support indentify
42
- def indentify
43
- raise ApiError.new("Can't call indentify here")
41
+ # @raise [ApiError] Basic object does not directly support identify
42
+ def identify
43
+ raise ApiError.new("Can't call identify here")
44
44
  end
45
45
  end
46
46
  end
@@ -12,13 +12,13 @@ class ZabbixApi
12
12
 
13
13
  data_with_default = default_options.empty? ? data : merge_params(default_options, data)
14
14
  data_create = [data_with_default]
15
- result = @client.api_request(:method => "#{method_name}.create", :params => data_create)
15
+ result = @client.api_request(method: "#{method_name}.create", params: data_create)
16
16
  parse_keys result
17
17
  end
18
18
 
19
19
  # Delete Zabbix object using API
20
20
  #
21
- # @param data [Hash] Should include object's id field name (indentify) and id value
21
+ # @param data [Hash] Should include object's id field name (identify) and id value
22
22
  # @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
23
23
  # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
24
24
  # @return [Integer] The object id if a single object is deleted
@@ -27,13 +27,13 @@ class ZabbixApi
27
27
  log "[DEBUG] Call delete with parameters: #{data.inspect}"
28
28
 
29
29
  data_delete = [data]
30
- result = @client.api_request(:method => "#{method_name}.delete", :params => data_delete)
30
+ result = @client.api_request(method: "#{method_name}.delete", params: data_delete)
31
31
  parse_keys result
32
32
  end
33
33
 
34
34
  # Create or update Zabbix object using API
35
35
  #
36
- # @param data [Hash] Should include object's id field name (indentify) and id value
36
+ # @param data [Hash] Should include object's id field name (identify) and id value
37
37
  # @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
38
38
  # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
39
39
  # @return [Integer] The object id if a single object is created
@@ -41,13 +41,13 @@ class ZabbixApi
41
41
  def create_or_update(data)
42
42
  log "[DEBUG] Call create_or_update with parameters: #{data.inspect}"
43
43
 
44
- id = get_id(indentify.to_sym => data[indentify.to_sym])
44
+ id = get_id(identify.to_sym => data[identify.to_sym])
45
45
  id ? update(data.merge(key.to_sym => id.to_s)) : create(data)
46
46
  end
47
47
 
48
48
  # Update Zabbix object using API
49
49
  #
50
- # @param data [Hash] Should include object's id field name (indentify) and id value
50
+ # @param data [Hash] Should include object's id field name (identify) and id value
51
51
  # @param force [Boolean] Whether to force an object update even if provided data matches Zabbix
52
52
  # @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
53
53
  # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
@@ -64,14 +64,14 @@ class ZabbixApi
64
64
  data[key.to_sym].to_i
65
65
  else
66
66
  data_update = [data]
67
- result = @client.api_request(:method => "#{method_name}.update", :params => data_update)
67
+ result = @client.api_request(method: "#{method_name}.update", params: data_update)
68
68
  parse_keys result
69
69
  end
70
70
  end
71
71
 
72
72
  # Get full/extended Zabbix object data from API
73
73
  #
74
- # @param data [Hash] Should include object's id field name (indentify) and id value
74
+ # @param data [Hash] Should include object's id field name (identify) and id value
75
75
  # @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
76
76
  # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
77
77
  # @return [Hash]
@@ -79,12 +79,12 @@ class ZabbixApi
79
79
  log "[DEBUG] Call get_full_data with parameters: #{data.inspect}"
80
80
 
81
81
  @client.api_request(
82
- :method => "#{method_name}.get",
83
- :params => {
84
- :filter => {
85
- indentify.to_sym => data[indentify.to_sym],
82
+ method: "#{method_name}.get",
83
+ params: {
84
+ filter: {
85
+ identify.to_sym => data[identify.to_sym]
86
86
  },
87
- :output => 'extend',
87
+ output: 'extend'
88
88
  }
89
89
  )
90
90
  end
@@ -99,8 +99,8 @@ class ZabbixApi
99
99
  log "[DEBUG] Call get_raw with parameters: #{data.inspect}"
100
100
 
101
101
  @client.api_request(
102
- :method => "#{method_name}.get",
103
- :params => data
102
+ method: "#{method_name}.get",
103
+ params: data
104
104
  )
105
105
  end
106
106
 
@@ -114,12 +114,12 @@ class ZabbixApi
114
114
  log "[DEBUG] Call dump_by_id with parameters: #{data.inspect}"
115
115
 
116
116
  @client.api_request(
117
- :method => "#{method_name}.get",
118
- :params => {
119
- :filter => {
120
- key.to_sym => data[key.to_sym],
117
+ method: "#{method_name}.get",
118
+ params: {
119
+ filter: {
120
+ key.to_sym => data[key.to_sym]
121
121
  },
122
- :output => 'extend',
122
+ output: 'extend'
123
123
  }
124
124
  )
125
125
  end
@@ -131,8 +131,8 @@ class ZabbixApi
131
131
  # @return [Array<Hash>] Array of matching objects
132
132
  def all
133
133
  result = {}
134
- @client.api_request(:method => "#{method_name}.get", :params => {:output => 'extend'}).each do |item|
135
- result[item[indentify]] = item[key]
134
+ @client.api_request(method: "#{method_name}.get", params: { output: 'extend' }).each do |item|
135
+ result[item[identify]] = item[key]
136
136
  end
137
137
  result
138
138
  end
@@ -140,38 +140,39 @@ class ZabbixApi
140
140
  # Get Zabbix object id from API based on provided data
141
141
  #
142
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).
143
+ # @raise [ApiError] Error returned when there is a problem with the Zabbix API call or missing object's id field name (identify).
144
144
  # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
145
145
  # @return [Integer] Zabbix object id
146
146
  def get_id(data)
147
147
  log "[DEBUG] Call get_id with parameters: #{data.inspect}"
148
148
  # symbolize keys if the user used string keys instead of symbols
149
- data = symbolize_keys(data) if data.key?(indentify)
150
- # raise an error if indentify name was not supplied
151
- name = data[indentify.to_sym]
152
- raise ApiError.new("#{indentify} not supplied in call to get_id") if name.nil?
149
+ data = symbolize_keys(data) if data.key?(identify)
150
+ # raise an error if identify name was not supplied
151
+ name = data[identify.to_sym]
152
+ raise ApiError.new("#{identify} not supplied in call to get_id") if name.nil?
153
+
153
154
  result = @client.api_request(
154
- :method => "#{method_name}.get",
155
- :params => {
156
- :filter => data,
157
- :output => [key, indentify],
155
+ method: "#{method_name}.get",
156
+ params: {
157
+ filter: data,
158
+ output: [key, identify]
158
159
  }
159
160
  )
160
161
  id = nil
161
- result.each { |item| id = item[key].to_i if item[indentify] == data[indentify.to_sym] }
162
+ result.each { |item| id = item[key].to_i if item[identify] == data[identify.to_sym] }
162
163
  id
163
164
  end
164
165
 
165
166
  # Get or Create Zabbix object using API
166
167
  #
167
- # @param data [Hash] Should include object's id field name (indentify) and id value
168
+ # @param data [Hash] Should include object's id field name (identify) and id value
168
169
  # @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
169
170
  # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
170
171
  # @return [Integer] Zabbix object id
171
172
  def get_or_create(data)
172
173
  log "[DEBUG] Call get_or_create with parameters: #{data.inspect}"
173
174
 
174
- unless (id = get_id(indentify.to_sym => data[indentify.to_sym]))
175
+ unless (id = get_id(identify.to_sym => data[identify.to_sym]))
175
176
  id = create(data)
176
177
  end
177
178
  id