zabbixapi 4.2.0 → 5.0.0.pre.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +27 -11
- data/lib/zabbixapi.rb +12 -0
- data/lib/zabbixapi/basic/basic_alias.rb +2 -2
- data/lib/zabbixapi/basic/basic_init.rb +5 -5
- data/lib/zabbixapi/basic/basic_logic.rb +16 -16
- data/lib/zabbixapi/classes/actions.rb +25 -1
- data/lib/zabbixapi/classes/applications.rb +1 -1
- data/lib/zabbixapi/classes/configurations.rb +1 -1
- data/lib/zabbixapi/classes/drules.rb +1 -1
- data/lib/zabbixapi/classes/events.rb +1 -1
- data/lib/zabbixapi/classes/graphs.rb +4 -4
- data/lib/zabbixapi/classes/hostgroups.rb +1 -1
- data/lib/zabbixapi/classes/hosts.rb +2 -2
- data/lib/zabbixapi/classes/httptests.rb +1 -1
- data/lib/zabbixapi/classes/items.rb +1 -1
- data/lib/zabbixapi/classes/maintenance.rb +1 -1
- data/lib/zabbixapi/classes/mediatypes.rb +78 -3
- data/lib/zabbixapi/classes/problems.rb +101 -0
- data/lib/zabbixapi/classes/proxies.rb +1 -1
- data/lib/zabbixapi/classes/roles.rb +114 -0
- data/lib/zabbixapi/classes/screens.rb +1 -1
- data/lib/zabbixapi/classes/scripts.rb +1 -1
- data/lib/zabbixapi/classes/templates.rb +1 -1
- data/lib/zabbixapi/classes/triggers.rb +2 -2
- data/lib/zabbixapi/classes/unusable.rb +1 -1
- data/lib/zabbixapi/classes/usergroups.rb +1 -1
- data/lib/zabbixapi/classes/usermacros.rb +15 -15
- data/lib/zabbixapi/classes/users.rb +1 -1
- data/lib/zabbixapi/classes/valuemaps.rb +1 -1
- data/lib/zabbixapi/client.rb +6 -2
- data/lib/zabbixapi/version.rb +1 -1
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 872ce78b417080b9ad0affdf398753332f6c88fb3cfac7b5db991413711e2b65
|
4
|
+
data.tar.gz: 077a81ef6f1d562091f61ab58b973192f12b4d1579c9683d8421779c907e6e33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c818c7285117d51cc70dc770ba43c75ae5c8cab4ded5e553b2ffcb5a1256b1578da4720faeec57cdc086c02dbc152ccc540c620aba27b02a0426ed0eefedd289
|
7
|
+
data.tar.gz: ba45247a6463b805aa8fbcd3c1bf8ec2d9531e6a3e5db9bf82805ba29fc9c6a972bf8a0f8cb8f063c69b7429337bd89b1a7fe30d9e0054cbd73e1ca64ff7ada3
|
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](
|
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
|
-
[
|
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
|
-
|
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
|
-
|
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,15 +39,18 @@ We support only two last versions of zabbix (4.0 and 4.2), 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.
|
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][
|
48
|
+
This library aims to support and is [tested against][github-ci] the following Ruby
|
37
49
|
versions:
|
38
50
|
|
39
|
-
* Ruby 2.4
|
40
51
|
* Ruby 2.5
|
41
52
|
* Ruby 2.6
|
53
|
+
* Ruby 2.7
|
42
54
|
* JRuby 9.2.10.0
|
43
55
|
|
44
56
|
If something doesn't work on one of these versions, it's a bug.
|
@@ -62,6 +74,7 @@ dropped.
|
|
62
74
|
## Contributing
|
63
75
|
|
64
76
|
* Fork the project.
|
77
|
+
* Base your work on the master branch.
|
65
78
|
* Make your feature addition or bug fix, write tests, write documentation/examples.
|
66
79
|
* Commit, do not mess with rakefile, version.
|
67
80
|
* Make a pull request.
|
@@ -72,11 +85,14 @@ dropped.
|
|
72
85
|
* [Zabbix API docs][Zabbix API]
|
73
86
|
|
74
87
|
[Zabbix]: https://www.zabbix.com
|
75
|
-
[Zabbix API]: https://www.zabbix.com/documentation/
|
88
|
+
[Zabbix API]: https://www.zabbix.com/documentation/5.2/manual/api
|
76
89
|
|
77
90
|
## Copyright
|
78
|
-
Copyright (c) 2015-2018 Express 42
|
79
91
|
|
80
|
-
|
92
|
+
- Copyright (c) 2021 [contributors]
|
93
|
+
- Copyright (c) 2015-2018 Express 42 and [contributors]
|
94
|
+
|
95
|
+
See [LICENSE] for details.
|
81
96
|
|
82
|
-
[
|
97
|
+
[LICENSE]: LICENSE.md
|
98
|
+
[contributors]: https://github.com/express42/zabbixapi/graphs/contributors
|
data/lib/zabbixapi.rb
CHANGED
@@ -19,6 +19,8 @@ require 'zabbixapi/classes/items'
|
|
19
19
|
require 'zabbixapi/classes/maintenance'
|
20
20
|
require 'zabbixapi/classes/mediatypes'
|
21
21
|
require 'zabbixapi/classes/proxies'
|
22
|
+
require 'zabbixapi/classes/problems'
|
23
|
+
require 'zabbixapi/classes/roles'
|
22
24
|
require 'zabbixapi/classes/screens'
|
23
25
|
require 'zabbixapi/classes/scripts'
|
24
26
|
require 'zabbixapi/classes/server'
|
@@ -125,11 +127,21 @@ class ZabbixApi
|
|
125
127
|
@mediatypes ||= Mediatypes.new(@client)
|
126
128
|
end
|
127
129
|
|
130
|
+
# @return [ZabbixApi::Problems]
|
131
|
+
def problems
|
132
|
+
@problems ||= Problems.new(@client)
|
133
|
+
end
|
134
|
+
|
128
135
|
# @return [ZabbixApi::Proxies]
|
129
136
|
def proxies
|
130
137
|
@proxies ||= Proxies.new(@client)
|
131
138
|
end
|
132
139
|
|
140
|
+
# @return [ZabbixApi::Roles]
|
141
|
+
def roles
|
142
|
+
@roles ||= Roles.new(@client)
|
143
|
+
end
|
144
|
+
|
133
145
|
# @return [ZabbixApi::Screens]
|
134
146
|
def screens
|
135
147
|
@screens ||= Screens.new(@client)
|
@@ -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 (
|
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 (
|
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
|
@@ -22,14 +22,14 @@ class ZabbixApi
|
|
22
22
|
{}
|
23
23
|
end
|
24
24
|
|
25
|
-
# Returns the object's plural id field name (
|
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 (
|
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
|
42
|
-
def
|
43
|
-
raise ApiError.new("Can't call
|
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
|
@@ -18,7 +18,7 @@ class ZabbixApi
|
|
18
18
|
|
19
19
|
# Delete Zabbix object using API
|
20
20
|
#
|
21
|
-
# @param data [Hash] Should include object's id field name (
|
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
|
@@ -33,7 +33,7 @@ class ZabbixApi
|
|
33
33
|
|
34
34
|
# Create or update Zabbix object using API
|
35
35
|
#
|
36
|
-
# @param data [Hash] Should include object's id field name (
|
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(
|
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 (
|
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.
|
@@ -71,7 +71,7 @@ class ZabbixApi
|
|
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 (
|
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]
|
@@ -82,7 +82,7 @@ class ZabbixApi
|
|
82
82
|
method: "#{method_name}.get",
|
83
83
|
params: {
|
84
84
|
filter: {
|
85
|
-
|
85
|
+
identify.to_sym => data[identify.to_sym]
|
86
86
|
},
|
87
87
|
output: 'extend'
|
88
88
|
}
|
@@ -132,7 +132,7 @@ class ZabbixApi
|
|
132
132
|
def all
|
133
133
|
result = {}
|
134
134
|
@client.api_request(method: "#{method_name}.get", params: { output: 'extend' }).each do |item|
|
135
|
-
result[item[
|
135
|
+
result[item[identify]] = item[key]
|
136
136
|
end
|
137
137
|
result
|
138
138
|
end
|
@@ -140,39 +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 (
|
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?(
|
150
|
-
# raise an error if
|
151
|
-
name = data[
|
152
|
-
raise ApiError.new("#{
|
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
154
|
result = @client.api_request(
|
155
155
|
method: "#{method_name}.get",
|
156
156
|
params: {
|
157
157
|
filter: data,
|
158
|
-
output: [key,
|
158
|
+
output: [key, identify]
|
159
159
|
}
|
160
160
|
)
|
161
161
|
id = nil
|
162
|
-
result.each { |item| id = item[key].to_i if item[
|
162
|
+
result.each { |item| id = item[key].to_i if item[identify] == data[identify.to_sym] }
|
163
163
|
id
|
164
164
|
end
|
165
165
|
|
166
166
|
# Get or Create Zabbix object using API
|
167
167
|
#
|
168
|
-
# @param data [Hash] Should include object's id field name (
|
168
|
+
# @param data [Hash] Should include object's id field name (identify) and id value
|
169
169
|
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
|
170
170
|
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
171
171
|
# @return [Integer] Zabbix object id
|
172
172
|
def get_or_create(data)
|
173
173
|
log "[DEBUG] Call get_or_create with parameters: #{data.inspect}"
|
174
174
|
|
175
|
-
unless (id = get_id(
|
175
|
+
unless (id = get_id(identify.to_sym => data[identify.to_sym]))
|
176
176
|
id = create(data)
|
177
177
|
end
|
178
178
|
id
|
@@ -10,8 +10,32 @@ class ZabbixApi
|
|
10
10
|
# The id field name used for identifying specific Action objects via Zabbix API
|
11
11
|
#
|
12
12
|
# @return [String]
|
13
|
-
def
|
13
|
+
def identify
|
14
14
|
'name'
|
15
15
|
end
|
16
|
+
|
17
|
+
# Get full/extended Action object data from API
|
18
|
+
#
|
19
|
+
# @param data [Hash] Should include object's id field name (identify) and id value
|
20
|
+
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
|
21
|
+
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
22
|
+
# @return [Hash]
|
23
|
+
def get_full_data(data)
|
24
|
+
log "[DEBUG] Call get_full_data with parameters: #{data.inspect}"
|
25
|
+
|
26
|
+
@client.api_request(
|
27
|
+
method: "#{method_name}.get",
|
28
|
+
params: {
|
29
|
+
filter: {
|
30
|
+
identify.to_sym => data[identify.to_sym]
|
31
|
+
},
|
32
|
+
output: 'extend',
|
33
|
+
selectOperations: "extend",
|
34
|
+
selectRecoveryOperations: "extend",
|
35
|
+
selectAcknowledgeOperations: "extend",
|
36
|
+
selectFilter: "extend",
|
37
|
+
}
|
38
|
+
)
|
39
|
+
end
|
16
40
|
end
|
17
41
|
end
|
@@ -10,24 +10,24 @@ class ZabbixApi
|
|
10
10
|
# The id field name used for identifying specific Graph objects via Zabbix API
|
11
11
|
#
|
12
12
|
# @return [String]
|
13
|
-
def
|
13
|
+
def identify
|
14
14
|
'name'
|
15
15
|
end
|
16
16
|
|
17
17
|
# Get full/extended Graph data from Zabbix API
|
18
18
|
#
|
19
|
-
# @param data [Hash] Should include object's id field name (
|
19
|
+
# @param data [Hash] Should include object's id field name (identify) and id value
|
20
20
|
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
|
21
21
|
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
22
22
|
# @return [Hash]
|
23
23
|
def get_full_data(data)
|
24
|
-
log "[DEBUG] Call get_full_data with
|
24
|
+
log "[DEBUG] Call get_full_data with parameters: #{data.inspect}"
|
25
25
|
|
26
26
|
@client.api_request(
|
27
27
|
method: "#{method_name}.get",
|
28
28
|
params: {
|
29
29
|
search: {
|
30
|
-
|
30
|
+
identify.to_sym => data[identify.to_sym]
|
31
31
|
},
|
32
32
|
output: 'extend'
|
33
33
|
}
|
@@ -10,7 +10,7 @@ class ZabbixApi
|
|
10
10
|
# The id field name used for identifying specific Host objects via Zabbix API
|
11
11
|
#
|
12
12
|
# @return [String]
|
13
|
-
def
|
13
|
+
def identify
|
14
14
|
'host'
|
15
15
|
end
|
16
16
|
|
@@ -21,7 +21,7 @@ class ZabbixApi
|
|
21
21
|
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
22
22
|
# @return [Hash]
|
23
23
|
def dump_by_id(data)
|
24
|
-
log "[DEBUG] Call dump_by_id with
|
24
|
+
log "[DEBUG] Call dump_by_id with parameters: #{data.inspect}"
|
25
25
|
|
26
26
|
@client.api_request(
|
27
27
|
method: 'host.get',
|
@@ -10,8 +10,8 @@ class ZabbixApi
|
|
10
10
|
# The id field name used for identifying specific MediaType objects via Zabbix API
|
11
11
|
#
|
12
12
|
# @return [String]
|
13
|
-
def
|
14
|
-
'
|
13
|
+
def identify
|
14
|
+
'name'
|
15
15
|
end
|
16
16
|
|
17
17
|
# The default options used when creating MediaType objects via Zabbix API
|
@@ -19,7 +19,8 @@ class ZabbixApi
|
|
19
19
|
# @return [Hash]
|
20
20
|
def default_options
|
21
21
|
{
|
22
|
-
|
22
|
+
name: '', # Name
|
23
|
+
description: '', # Description
|
23
24
|
type: 0, # 0 - Email, 1 - External script, 2 - SMS, 3 - Jabber, 100 - EzTexting
|
24
25
|
smtp_server: '',
|
25
26
|
smtp_helo: '',
|
@@ -30,5 +31,79 @@ class ZabbixApi
|
|
30
31
|
passwd: '' # Jabber password used by Zabbix server
|
31
32
|
}
|
32
33
|
end
|
34
|
+
|
35
|
+
# def log(message)
|
36
|
+
# STDERR.puts
|
37
|
+
# STDERR.puts message.to_s
|
38
|
+
# STDERR.puts
|
39
|
+
# end
|
40
|
+
|
41
|
+
# Update MediaType object using API
|
42
|
+
#
|
43
|
+
# @param data [Hash] Should include object's id field name (identify) and id value
|
44
|
+
# @param force [Boolean] Whether to force an object update even if provided data matches Zabbix
|
45
|
+
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
|
46
|
+
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
47
|
+
# @return [Integer] The object id if a single object is created
|
48
|
+
# @return [Boolean] True/False if multiple objects are created
|
49
|
+
def update(data, force = false)
|
50
|
+
log "[DEBUG] Call update with parameters: #{data.inspect}"
|
51
|
+
if data[key.to_sym].nil?
|
52
|
+
data[key.to_sym] = get_id(data)
|
53
|
+
log "[DEBUG] Enriched data with id: #{data.inspect}"
|
54
|
+
end
|
55
|
+
dump = {}
|
56
|
+
dump_by_id(key.to_sym => data[key.to_sym]).each do |item|
|
57
|
+
dump = symbolize_keys(item) if item[key].to_i == data[key.to_sym].to_i
|
58
|
+
end
|
59
|
+
if hash_equals?(dump, data) && !force
|
60
|
+
log "[DEBUG] Equal keys #{dump} and #{data}, skip update"
|
61
|
+
data[key.to_sym].to_i
|
62
|
+
else
|
63
|
+
data_update = [data]
|
64
|
+
result = @client.api_request(method: "#{method_name}.update", params: data_update)
|
65
|
+
parse_keys result
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# Get MediaType object id from API based on provided data
|
70
|
+
#
|
71
|
+
# @param data [Hash]
|
72
|
+
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call or missing object's id field name (identify).
|
73
|
+
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
74
|
+
# @return [Integer] Zabbix object id
|
75
|
+
def get_id(data)
|
76
|
+
log "[DEBUG] Call get_id with parameters: #{data.inspect}"
|
77
|
+
# symbolize keys if the user used string keys instead of symbols
|
78
|
+
data = symbolize_keys(data) if data.key?(identify)
|
79
|
+
# raise an error if identify name was not supplied
|
80
|
+
name = data[identify.to_sym]
|
81
|
+
raise ApiError.new("#{identify} not supplied in call to get_id, #{data} (#{method_name})") if name.nil?
|
82
|
+
|
83
|
+
result = @client.api_request(
|
84
|
+
method: "#{method_name}.get",
|
85
|
+
params: {
|
86
|
+
filter: {name: name},
|
87
|
+
output: [key, identify]
|
88
|
+
}
|
89
|
+
)
|
90
|
+
id = nil
|
91
|
+
result.each { |item| id = item[key].to_i if item[identify] == data[identify.to_sym] }
|
92
|
+
id
|
93
|
+
end
|
94
|
+
|
95
|
+
# Create or update MediaType object using API
|
96
|
+
#
|
97
|
+
# @param data [Hash] Should include object's id field name (identify) and id value
|
98
|
+
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
|
99
|
+
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
100
|
+
# @return [Integer] The object id if a single object is created
|
101
|
+
# @return [Boolean] True/False if multiple objects are created
|
102
|
+
def create_or_update(data)
|
103
|
+
log "[DEBUG] Call create_or_update with parameters: #{data.inspect}"
|
104
|
+
|
105
|
+
id = get_id(identify.to_sym => data[identify.to_sym])
|
106
|
+
id ? update(data.merge(key.to_sym => id.to_s)) : create(data)
|
107
|
+
end
|
33
108
|
end
|
34
109
|
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
class ZabbixApi
|
2
|
+
class Problems < Basic
|
3
|
+
# The method name used for interacting with Hosts via Zabbix API
|
4
|
+
#
|
5
|
+
# @return [String]
|
6
|
+
def method_name
|
7
|
+
'problem'
|
8
|
+
end
|
9
|
+
|
10
|
+
# The id field name used for identifying specific Problem objects via Zabbix API
|
11
|
+
#
|
12
|
+
# @return [String]
|
13
|
+
def identify
|
14
|
+
'name'
|
15
|
+
end
|
16
|
+
|
17
|
+
# The key field name used for Problem objects via Zabbix API
|
18
|
+
# However, Problem object does not have a unique identifier
|
19
|
+
#
|
20
|
+
# @return [String]
|
21
|
+
def key
|
22
|
+
'problemid'
|
23
|
+
end
|
24
|
+
|
25
|
+
# Returns the object's plural id field name (identify) based on key
|
26
|
+
# However, Problem object does not have a unique identifier
|
27
|
+
#
|
28
|
+
# @return [String]
|
29
|
+
def keys
|
30
|
+
'problemids'
|
31
|
+
end
|
32
|
+
|
33
|
+
# Dump Problem object data by key from Zabbix API
|
34
|
+
#
|
35
|
+
# @param data [Hash] Should include desired object's key and value
|
36
|
+
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
|
37
|
+
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
38
|
+
# @return [Hash]
|
39
|
+
def dump_by_id(data)
|
40
|
+
log "[DEBUG] Call dump_by_id with parameters: #{data.inspect}"
|
41
|
+
|
42
|
+
@client.api_request(
|
43
|
+
method: 'problem.get',
|
44
|
+
params: {
|
45
|
+
filter: {
|
46
|
+
identify.to_sym => data[identify.to_sym]
|
47
|
+
},
|
48
|
+
output: 'extend'
|
49
|
+
}
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Get full/extended Problem data from Zabbix API
|
54
|
+
#
|
55
|
+
# @param data [Hash] Should include object's id field name (identify) and id value
|
56
|
+
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
|
57
|
+
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
58
|
+
# @return [Hash]
|
59
|
+
def get_full_data(data)
|
60
|
+
log "[DEBUG] Call get_full_data with parameters: #{data.inspect}"
|
61
|
+
|
62
|
+
data = symbolize_keys(data)
|
63
|
+
|
64
|
+
@client.api_request(
|
65
|
+
method: "#{method_name}.get",
|
66
|
+
params: {
|
67
|
+
filter: {
|
68
|
+
identify.to_sym => data[identify.to_sym]
|
69
|
+
},
|
70
|
+
eventids: data[:eventids] || nil,
|
71
|
+
groupids: data[:groupids] || nil,
|
72
|
+
hostids: data[:hostids] || nil,
|
73
|
+
objectids: data[:objectids] || nil,
|
74
|
+
applicationids: data[:applicationids] || nil,
|
75
|
+
tags: data[:tags] || nil,
|
76
|
+
time_from: data[:time_from] || nil,
|
77
|
+
time_till: data[:time_till] || nil,
|
78
|
+
eventid_from: data[:eventid_from] || nil,
|
79
|
+
eventid_till: data[:eventid_till] || nil,
|
80
|
+
recent: data[:recent] || false,
|
81
|
+
sortfield: data[:sortfield] || ['eventid'],
|
82
|
+
sortorder: data[:sortorder] || 'DESC',
|
83
|
+
countOutput: data[:countOutput] || nil,
|
84
|
+
output: 'extend',
|
85
|
+
selectAcknowledges: 'extend',
|
86
|
+
selectTags: 'extend',
|
87
|
+
selectSuppressionData: 'extend'
|
88
|
+
}
|
89
|
+
)
|
90
|
+
end
|
91
|
+
|
92
|
+
# Get full/extended Zabbix data for Problem objects from API
|
93
|
+
#
|
94
|
+
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
|
95
|
+
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
96
|
+
# @return [Array<Hash>] Array of matching objects
|
97
|
+
def all
|
98
|
+
get_full_data({})
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
class ZabbixApi
|
2
|
+
class Roles < Basic
|
3
|
+
# The method name used for interacting with Role via Zabbix API
|
4
|
+
#
|
5
|
+
# @return [String]
|
6
|
+
def method_name
|
7
|
+
'role'
|
8
|
+
end
|
9
|
+
|
10
|
+
# The key field name used for Role objects via Zabbix API
|
11
|
+
#
|
12
|
+
# @return [String]
|
13
|
+
def key
|
14
|
+
'roleid'
|
15
|
+
end
|
16
|
+
|
17
|
+
# The id field name used for identifying specific Role objects via Zabbix API
|
18
|
+
#
|
19
|
+
# @return [String]
|
20
|
+
def identify
|
21
|
+
'name'
|
22
|
+
end
|
23
|
+
|
24
|
+
# Set permissions for usergroup using Zabbix API
|
25
|
+
#
|
26
|
+
# @param data [Hash] Needs to include usrgrpids and hostgroupids along with permissions to set
|
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] Zabbix object id (usergroup)
|
30
|
+
def rules(data)
|
31
|
+
rules = data[:rules] || 2
|
32
|
+
result = @client.api_request(
|
33
|
+
method: 'role.update',
|
34
|
+
params: {
|
35
|
+
roleid: data[:roleid],
|
36
|
+
rules: data[:hostgroupids].map { |t| { permission: permission, id: t } }
|
37
|
+
}
|
38
|
+
)
|
39
|
+
result ? result['usrgrpids'][0].to_i : nil
|
40
|
+
end
|
41
|
+
|
42
|
+
# Add users to usergroup using Zabbix API
|
43
|
+
#
|
44
|
+
# @deprecated Zabbix has removed massAdd in favor of update.
|
45
|
+
# @param data [Hash] Needs to include userids and usrgrpids to mass add users to groups
|
46
|
+
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
|
47
|
+
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
48
|
+
# @return [Integer] Zabbix object id (usergroup)
|
49
|
+
def add_user(data)
|
50
|
+
update_users(data)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Dump Role object data by key from Zabbix API
|
54
|
+
#
|
55
|
+
# @param data [Hash] Should include desired object's key and value
|
56
|
+
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
|
57
|
+
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
58
|
+
# @return [Hash]
|
59
|
+
def dump_by_id(data)
|
60
|
+
log "[DEBUG] Call dump_by_id with parameters: #{data.inspect}"
|
61
|
+
|
62
|
+
@client.api_request(
|
63
|
+
method: 'role.get',
|
64
|
+
params: {
|
65
|
+
output: 'extend',
|
66
|
+
selectRules: 'extend',
|
67
|
+
roleids: data[:id]
|
68
|
+
}
|
69
|
+
)
|
70
|
+
end
|
71
|
+
|
72
|
+
# Get Role ids by Role Name from Zabbix API
|
73
|
+
#
|
74
|
+
# @param data [Hash] Should include host value to query for matching graphs
|
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 [Array] Returns array of Graph ids
|
78
|
+
def get_ids_by_name(data)
|
79
|
+
result = @client.api_request(
|
80
|
+
method: 'role.get',
|
81
|
+
params: {
|
82
|
+
filter: {
|
83
|
+
name: data[:name]
|
84
|
+
},
|
85
|
+
output: 'extend'
|
86
|
+
}
|
87
|
+
)
|
88
|
+
|
89
|
+
result.map do |rule|
|
90
|
+
rule['roleid']
|
91
|
+
end.compact
|
92
|
+
end
|
93
|
+
|
94
|
+
# Update users in Userroles using Zabbix API
|
95
|
+
#
|
96
|
+
# @param data [Hash] Needs to include userids and usrgrpids to mass update users in groups
|
97
|
+
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
|
98
|
+
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
99
|
+
# @return [Integer] Zabbix object id (usergroup)
|
100
|
+
def update_users(data)
|
101
|
+
user_groups = data[:usrgrpids].map do |t|
|
102
|
+
{
|
103
|
+
usrgrpid: t,
|
104
|
+
userids: data[:userids],
|
105
|
+
}
|
106
|
+
end
|
107
|
+
result = @client.api_request(
|
108
|
+
method: 'usergroup.update',
|
109
|
+
params: user_groups,
|
110
|
+
)
|
111
|
+
result ? result['usrgrpids'][0].to_i : nil
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -10,7 +10,7 @@ class ZabbixApi
|
|
10
10
|
# The id field name used for identifying specific Trigger objects via Zabbix API
|
11
11
|
#
|
12
12
|
# @return [String]
|
13
|
-
def
|
13
|
+
def identify
|
14
14
|
'description'
|
15
15
|
end
|
16
16
|
|
@@ -21,7 +21,7 @@ class ZabbixApi
|
|
21
21
|
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
22
22
|
# @return [Hash]
|
23
23
|
def dump_by_id(data)
|
24
|
-
log "[DEBUG] Call dump_by_id with
|
24
|
+
log "[DEBUG] Call dump_by_id with parameters: #{data.inspect}"
|
25
25
|
|
26
26
|
@client.api_request(
|
27
27
|
method: 'trigger.get',
|
@@ -3,7 +3,7 @@ class ZabbixApi
|
|
3
3
|
# The id field name used for identifying specific User macro objects via Zabbix API
|
4
4
|
#
|
5
5
|
# @return [String]
|
6
|
-
def
|
6
|
+
def identify
|
7
7
|
'macro'
|
8
8
|
end
|
9
9
|
|
@@ -17,17 +17,17 @@ class ZabbixApi
|
|
17
17
|
# Get User macro object id from Zabbix API based on provided data
|
18
18
|
#
|
19
19
|
# @param data [Hash] Needs to include macro to properly identify user macros via Zabbix API
|
20
|
-
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call or missing object's id field name (
|
20
|
+
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call or missing object's id field name (identify).
|
21
21
|
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
22
22
|
# @return [Integer] Zabbix object id
|
23
23
|
def get_id(data)
|
24
24
|
log "[DEBUG] Call get_id with parameters: #{data.inspect}"
|
25
25
|
|
26
26
|
# symbolize keys if the user used string keys instead of symbols
|
27
|
-
data = symbolize_keys(data) if data.key?(
|
28
|
-
# raise an error if
|
29
|
-
name = data[
|
30
|
-
raise ApiError.new("#{
|
27
|
+
data = symbolize_keys(data) if data.key?(identify)
|
28
|
+
# raise an error if identify name was not supplied
|
29
|
+
name = data[identify.to_sym]
|
30
|
+
raise ApiError.new("#{identify} not supplied in call to get_id") if name.nil?
|
31
31
|
|
32
32
|
result = request(data, 'usermacro.get', 'hostmacroid')
|
33
33
|
|
@@ -37,17 +37,17 @@ class ZabbixApi
|
|
37
37
|
# Get Global macro object id from Zabbix API based on provided data
|
38
38
|
#
|
39
39
|
# @param data [Hash] Needs to include macro to properly identify global macros via Zabbix API
|
40
|
-
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call or missing object's id field name (
|
40
|
+
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call or missing object's id field name (identify).
|
41
41
|
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
42
42
|
# @return [Integer] Zabbix object id
|
43
43
|
def get_id_global(data)
|
44
44
|
log "[DEBUG] Call get_id_global with parameters: #{data.inspect}"
|
45
45
|
|
46
46
|
# symbolize keys if the user used string keys instead of symbols
|
47
|
-
data = symbolize_keys(data) if data.key?(
|
48
|
-
# raise an error if
|
49
|
-
name = data[
|
50
|
-
raise ApiError.new("#{
|
47
|
+
data = symbolize_keys(data) if data.key?(identify)
|
48
|
+
# raise an error if identify name was not supplied
|
49
|
+
name = data[identify.to_sym]
|
50
|
+
raise ApiError.new("#{identify} not supplied in call to get_id_global") if name.nil?
|
51
51
|
|
52
52
|
result = request(data, 'usermacro.get', 'globalmacroid')
|
53
53
|
|
@@ -56,7 +56,7 @@ class ZabbixApi
|
|
56
56
|
|
57
57
|
# Get full/extended User macro data from Zabbix API
|
58
58
|
#
|
59
|
-
# @param data [Hash] Should include object's id field name (
|
59
|
+
# @param data [Hash] Should include object's id field name (identify) and id value
|
60
60
|
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
|
61
61
|
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
62
62
|
# @return [Hash]
|
@@ -68,7 +68,7 @@ class ZabbixApi
|
|
68
68
|
|
69
69
|
# Get full/extended Global macro data from Zabbix API
|
70
70
|
#
|
71
|
-
# @param data [Hash] Should include object's id field name (
|
71
|
+
# @param data [Hash] Should include object's id field name (identify) and id value
|
72
72
|
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
|
73
73
|
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
74
74
|
# @return [Hash]
|
@@ -126,7 +126,7 @@ class ZabbixApi
|
|
126
126
|
|
127
127
|
# Update User macro object using Zabbix API
|
128
128
|
#
|
129
|
-
# @param data [Hash] Should include object's id field name (
|
129
|
+
# @param data [Hash] Should include object's id field name (identify), id value, and fields to update
|
130
130
|
# @param force [Boolean] Whether to force an object update even if provided data matches Zabbix
|
131
131
|
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
|
132
132
|
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
@@ -138,7 +138,7 @@ class ZabbixApi
|
|
138
138
|
|
139
139
|
# Update Global macro object using Zabbix API
|
140
140
|
#
|
141
|
-
# @param data [Hash] Should include object's id field name (
|
141
|
+
# @param data [Hash] Should include object's id field name (identify), id value, and fields to update
|
142
142
|
# @param force [Boolean] Whether to force an object update even if provided data matches Zabbix
|
143
143
|
# @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
|
144
144
|
# @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
|
data/lib/zabbixapi/client.rb
CHANGED
@@ -60,9 +60,13 @@ class ZabbixApi
|
|
60
60
|
@proxy_port = @proxy_uri.port
|
61
61
|
@proxy_user, @proxy_pass = @proxy_uri.userinfo.split(/:/) if @proxy_uri.userinfo
|
62
62
|
end
|
63
|
-
unless api_version =~ %r{^
|
63
|
+
unless api_version =~ %r{^5.[0|2]\.\d+$}
|
64
64
|
message = "Zabbix API version: #{api_version} is not supported by this version of zabbixapi"
|
65
|
-
|
65
|
+
if @options[:ignore_version]
|
66
|
+
puts "[WARNING] #{message}" if @options[:debug]
|
67
|
+
else
|
68
|
+
raise ZabbixApi::ApiError.new(message)
|
69
|
+
end
|
66
70
|
end
|
67
71
|
|
68
72
|
@auth_hash = auth
|
data/lib/zabbixapi/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zabbixapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.0.0.pre.alpha1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vasiliev D.V.
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-01-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: http
|
@@ -82,7 +82,9 @@ files:
|
|
82
82
|
- lib/zabbixapi/classes/items.rb
|
83
83
|
- lib/zabbixapi/classes/maintenance.rb
|
84
84
|
- lib/zabbixapi/classes/mediatypes.rb
|
85
|
+
- lib/zabbixapi/classes/problems.rb
|
85
86
|
- lib/zabbixapi/classes/proxies.rb
|
87
|
+
- lib/zabbixapi/classes/roles.rb
|
86
88
|
- lib/zabbixapi/classes/screens.rb
|
87
89
|
- lib/zabbixapi/classes/scripts.rb
|
88
90
|
- lib/zabbixapi/classes/server.rb
|
@@ -111,11 +113,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
111
113
|
version: 2.0.0
|
112
114
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
115
|
requirements:
|
114
|
-
- - "
|
116
|
+
- - ">"
|
115
117
|
- !ruby/object:Gem::Version
|
116
|
-
version:
|
118
|
+
version: 1.3.1
|
117
119
|
requirements: []
|
118
|
-
rubygems_version: 3.1
|
120
|
+
rubygems_version: 3.0.1
|
119
121
|
signing_key:
|
120
122
|
specification_version: 4
|
121
123
|
summary: Simple and lightweight ruby module for working with the Zabbix API
|