zabbixapi_mgx 5.0.0.pre.alpha1

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 (39) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +58 -0
  3. data/LICENSE.md +20 -0
  4. data/README.md +98 -0
  5. data/lib/zabbixapi/basic/basic_alias.rb +37 -0
  6. data/lib/zabbixapi/basic/basic_func.rb +103 -0
  7. data/lib/zabbixapi/basic/basic_init.rb +46 -0
  8. data/lib/zabbixapi/basic/basic_logic.rb +181 -0
  9. data/lib/zabbixapi/classes/actions.rb +41 -0
  10. data/lib/zabbixapi/classes/applications.rb +43 -0
  11. data/lib/zabbixapi/classes/configurations.rb +42 -0
  12. data/lib/zabbixapi/classes/drules.rb +55 -0
  13. data/lib/zabbixapi/classes/errors.rb +28 -0
  14. data/lib/zabbixapi/classes/events.rb +17 -0
  15. data/lib/zabbixapi/classes/graphs.rb +111 -0
  16. data/lib/zabbixapi/classes/hostgroups.rb +24 -0
  17. data/lib/zabbixapi/classes/hosts.rb +80 -0
  18. data/lib/zabbixapi/classes/httptests.rb +54 -0
  19. data/lib/zabbixapi/classes/items.rb +83 -0
  20. data/lib/zabbixapi/classes/maintenance.rb +17 -0
  21. data/lib/zabbixapi/classes/mediatypes.rb +109 -0
  22. data/lib/zabbixapi/classes/problems.rb +101 -0
  23. data/lib/zabbixapi/classes/proxies.rb +48 -0
  24. data/lib/zabbixapi/classes/roles.rb +114 -0
  25. data/lib/zabbixapi/classes/screens.rb +94 -0
  26. data/lib/zabbixapi/classes/scripts.rb +35 -0
  27. data/lib/zabbixapi/classes/server.rb +16 -0
  28. data/lib/zabbixapi/classes/templates.rb +106 -0
  29. data/lib/zabbixapi/classes/triggers.rb +105 -0
  30. data/lib/zabbixapi/classes/unusable.rb +8 -0
  31. data/lib/zabbixapi/classes/usergroups.rb +73 -0
  32. data/lib/zabbixapi/classes/usermacros.rb +228 -0
  33. data/lib/zabbixapi/classes/users.rb +64 -0
  34. data/lib/zabbixapi/classes/valuemaps.rb +50 -0
  35. data/lib/zabbixapi/client.rb +167 -0
  36. data/lib/zabbixapi/version.rb +3 -0
  37. data/lib/zabbixapi.rb +194 -0
  38. data/zabbixapi.gemspec +29 -0
  39. metadata +124 -0
@@ -0,0 +1,55 @@
1
+ class ZabbixApi
2
+ class Drules < Basic
3
+ # The method name used for interacting with Drules via Zabbix API
4
+ #
5
+ # @return [String]
6
+ def method_name
7
+ 'drule'
8
+ end
9
+
10
+ # The id field name used for identifying specific Drule objects via Zabbix API
11
+ #
12
+ # @return [String]
13
+ def identify
14
+ 'name'
15
+ end
16
+
17
+ # The default options used when creating Drule objects via Zabbix API
18
+ #
19
+ # @return [Hash]
20
+ def default_options
21
+ {
22
+ name: nil,
23
+ iprange: nil,
24
+ delay: 3600,
25
+ status: 0,
26
+ }
27
+ end
28
+
29
+ # Get or Create Drule object using Zabbix API
30
+ #
31
+ # @param data [Hash] Needs to include name to properly identify Drule via Zabbix API
32
+ # @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
33
+ # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
34
+ # @return [Integer] Zabbix object id
35
+ def get_or_create(data)
36
+ log "[DEBUG] Call get_or_create with parameters: #{data.inspect}"
37
+
38
+ unless (id = get_id(name: data[:name]))
39
+ id = create(data)
40
+ end
41
+ id
42
+ end
43
+
44
+ # Create or update Drule object using Zabbix API
45
+ #
46
+ # @param data [Hash] Needs to include name to properly identify Drules via Zabbix API
47
+ # @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
48
+ # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
49
+ # @return [Integer] Zabbix object id
50
+ def create_or_update(data)
51
+ druleid = get_id(name: data[:name])
52
+ druleid ? update(data.merge(druleid: druleid)) : create(data)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,28 @@
1
+ class ZabbixApi
2
+ class BaseError < RuntimeError
3
+ attr_accessor :response, :error, :error_message
4
+
5
+ def initialize(message, response = nil)
6
+ super(message)
7
+ @response = response
8
+
9
+ set_error! if @response
10
+ end
11
+
12
+ private
13
+
14
+ def set_error!
15
+ @error = @response['error']
16
+ @error_message = "#{@error['message']}: #{@error['data']}"
17
+ rescue StandardError
18
+ @error = nil
19
+ @error_message = nil
20
+ end
21
+ end
22
+
23
+ class ApiError < BaseError
24
+ end
25
+
26
+ class HttpError < BaseError
27
+ end
28
+ end
@@ -0,0 +1,17 @@
1
+ class ZabbixApi
2
+ class Events < Basic
3
+ # The method name used for interacting with Events via Zabbix API
4
+ #
5
+ # @return [String]
6
+ def method_name
7
+ 'event'
8
+ end
9
+
10
+ # The id field name used for identifying specific Event objects via Zabbix API
11
+ #
12
+ # @return [String]
13
+ def identify
14
+ 'name'
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,111 @@
1
+ class ZabbixApi
2
+ class Graphs < Basic
3
+ # The method name used for interacting with Graphs via Zabbix API
4
+ #
5
+ # @return [String]
6
+ def method_name
7
+ 'graph'
8
+ end
9
+
10
+ # The id field name used for identifying specific Graph objects via Zabbix API
11
+ #
12
+ # @return [String]
13
+ def identify
14
+ 'name'
15
+ end
16
+
17
+ # Get full/extended Graph data from Zabbix 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
+ search: {
30
+ identify.to_sym => data[identify.to_sym]
31
+ },
32
+ output: 'extend'
33
+ }
34
+ )
35
+ end
36
+
37
+ # Get Graph ids for Host from Zabbix API
38
+ #
39
+ # @param data [Hash] Should include host value to query for matching graphs
40
+ # @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
41
+ # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
42
+ # @return [Array] Returns array of Graph ids
43
+ def get_ids_by_host(data)
44
+ result = @client.api_request(
45
+ method: 'graph.get',
46
+ params: {
47
+ filter: {
48
+ host: data[:host]
49
+ },
50
+ output: 'extend'
51
+ }
52
+ )
53
+
54
+ result.map do |graph|
55
+ num = graph['graphid']
56
+ name = graph['name']
57
+ filter = data[:filter]
58
+
59
+ num if filter.nil? || /#{filter}/ =~ name
60
+ end.compact
61
+ end
62
+
63
+ # Get Graph Item object using Zabbix API
64
+ #
65
+ # @param data [Hash] Needs to include graphids to properly identify Graph Items via Zabbix API
66
+ # @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
67
+ # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
68
+ # @return [Hash]
69
+ def get_items(data)
70
+ @client.api_request(
71
+ method: 'graphitem.get',
72
+ params: {
73
+ graphids: [data],
74
+ output: 'extend'
75
+ }
76
+ )
77
+ end
78
+
79
+ # Get or Create Graph object using Zabbix API
80
+ #
81
+ # @param data [Hash] Needs to include name and templateid to properly identify Graphs via Zabbix API
82
+ # @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
83
+ # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
84
+ # @return [Integer] Zabbix object id
85
+ def get_or_create(data)
86
+ log "[DEBUG] Call get_or_create with parameters: #{data.inspect}"
87
+
88
+ unless (id = get_id(name: data[:name], templateid: data[:templateid]))
89
+ id = create(data)
90
+ end
91
+
92
+ id
93
+ end
94
+
95
+ # Create or update Graph object using Zabbix API
96
+ #
97
+ # @param data [Hash] Needs to include name and templateid to properly identify Graphs via Zabbix API
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] Zabbix object id
101
+ def create_or_update(data)
102
+ graphid = get_id(name: data[:name], templateid: data[:templateid])
103
+ graphid ? _update(data.merge(graphid: graphid)) : create(data)
104
+ end
105
+
106
+ def _update(data)
107
+ data.delete(:name)
108
+ update(data)
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,24 @@
1
+ class ZabbixApi
2
+ class HostGroups < Basic
3
+ # The method name used for interacting with HostGroups via Zabbix API
4
+ #
5
+ # @return [String]
6
+ def method_name
7
+ 'hostgroup'
8
+ end
9
+
10
+ # The id field name used for identifying specific HostGroup objects via Zabbix API
11
+ #
12
+ # @return [String]
13
+ def identify
14
+ 'name'
15
+ end
16
+
17
+ # The key field name used for HostGroup objects via Zabbix API
18
+ #
19
+ # @return [String]
20
+ def key
21
+ 'groupid'
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,80 @@
1
+ class ZabbixApi
2
+ class Hosts < Basic
3
+ # The method name used for interacting with Hosts via Zabbix API
4
+ #
5
+ # @return [String]
6
+ def method_name
7
+ 'host'
8
+ end
9
+
10
+ # The id field name used for identifying specific Host objects via Zabbix API
11
+ #
12
+ # @return [String]
13
+ def identify
14
+ 'host'
15
+ end
16
+
17
+ # Dump Host object data by key from Zabbix API
18
+ #
19
+ # @param data [Hash] Should include desired object's key and 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 dump_by_id(data)
24
+ log "[DEBUG] Call dump_by_id with parameters: #{data.inspect}"
25
+
26
+ @client.api_request(
27
+ method: 'host.get',
28
+ params: {
29
+ filter: {
30
+ key.to_sym => data[key.to_sym]
31
+ },
32
+ output: 'extend',
33
+ selectGroups: 'extend'
34
+ }
35
+ )
36
+ end
37
+
38
+ # The default options used when creating Host objects via Zabbix API
39
+ #
40
+ # @return [Hash]
41
+ def default_options
42
+ {
43
+ host: nil,
44
+ interfaces: [],
45
+ status: 0,
46
+ available: 1,
47
+ groups: [],
48
+ proxy_hostid: nil
49
+ }
50
+ end
51
+
52
+ # Unlink/Remove Templates from Hosts using Zabbix API
53
+ #
54
+ # @param data [Hash] Should include hosts_id array and templates_id array
55
+ # @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
56
+ # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
57
+ # @return [Boolean]
58
+ def unlink_templates(data)
59
+ result = @client.api_request(
60
+ method: 'host.massRemove',
61
+ params: {
62
+ hostids: data[:hosts_id],
63
+ templates: data[:templates_id]
64
+ }
65
+ )
66
+ result.empty? ? false : true
67
+ end
68
+
69
+ # Create or update Host object using Zabbix API
70
+ #
71
+ # @param data [Hash] Needs to include host to properly identify Hosts via Zabbix API
72
+ # @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
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 create_or_update(data)
76
+ hostid = get_id(host: data[:host])
77
+ hostid ? update(data.merge(hostid: hostid)) : create(data)
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,54 @@
1
+ class ZabbixApi
2
+ class HttpTests < Basic
3
+ # The method name used for interacting with HttpTests via Zabbix API
4
+ #
5
+ # @return [String]
6
+ def method_name
7
+ 'httptest'
8
+ end
9
+
10
+ # The id field name used for identifying specific HttpTest objects via Zabbix API
11
+ #
12
+ # @return [String]
13
+ def identify
14
+ 'name'
15
+ end
16
+
17
+ # The default options used when creating HttpTest objects via Zabbix API
18
+ #
19
+ # @return [Hash]
20
+ def default_options
21
+ {
22
+ hostid: nil,
23
+ name: nil,
24
+ steps: []
25
+ }
26
+ end
27
+
28
+ # Get or Create HttpTest object using Zabbix API
29
+ #
30
+ # @param data [Hash] Needs to include name and hostid to properly identify HttpTests via Zabbix API
31
+ # @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
32
+ # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
33
+ # @return [Integer] Zabbix object id
34
+ def get_or_create(data)
35
+ log "[DEBUG] Call get_or_create with parameters: #{data.inspect}"
36
+
37
+ unless (id = get_id(name: data[:name], hostid: data[:hostid]))
38
+ id = create(data)
39
+ end
40
+ id
41
+ end
42
+
43
+ # Create or update HttpTest object using Zabbix API
44
+ #
45
+ # @param data [Hash] Needs to include name and hostid to properly identify HttpTests via Zabbix API
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
49
+ def create_or_update(data)
50
+ httptestid = get_id(name: data[:name], hostid: data[:hostid])
51
+ httptestid ? update(data.merge(httptestid: httptestid)) : create(data)
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,83 @@
1
+ class ZabbixApi
2
+ class Items < Basic
3
+ # The method name used for interacting with Items via Zabbix API
4
+ #
5
+ # @return [String]
6
+ def method_name
7
+ 'item'
8
+ end
9
+
10
+ # The id field name used for identifying specific Item objects via Zabbix API
11
+ #
12
+ # @return [String]
13
+ def identify
14
+ 'name'
15
+ end
16
+
17
+ # The default options used when creating Item objects via Zabbix API
18
+ #
19
+ # @return [Hash]
20
+ def default_options
21
+ {
22
+ name: nil,
23
+ key_: nil,
24
+ hostid: nil,
25
+ delay: 60,
26
+ history: 3600,
27
+ status: 0,
28
+ type: 7,
29
+ snmp_community: '',
30
+ snmp_oid: '',
31
+ value_type: 3,
32
+ data_type: 0,
33
+ trapper_hosts: 'localhost',
34
+ snmp_port: 161,
35
+ units: '',
36
+ multiplier: 0,
37
+ delta: 0,
38
+ snmpv3_securityname: '',
39
+ snmpv3_securitylevel: 0,
40
+ snmpv3_authpassphrase: '',
41
+ snmpv3_privpassphrase: '',
42
+ formula: 0,
43
+ trends: 86400,
44
+ logtimefmt: '',
45
+ valuemapid: 0,
46
+ delay_flex: '',
47
+ authtype: 0,
48
+ username: '',
49
+ password: '',
50
+ publickey: '',
51
+ privatekey: '',
52
+ params: '',
53
+ ipmi_sensor: ''
54
+ }
55
+ end
56
+
57
+ # Get or Create Item object using Zabbix API
58
+ #
59
+ # @param data [Hash] Needs to include name and hostid to properly identify Items via Zabbix API
60
+ # @raise [ApiError] Error returned when there is a problem with the Zabbix API call.
61
+ # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
62
+ # @return [Integer] Zabbix object id
63
+ def get_or_create(data)
64
+ log "[DEBUG] Call get_or_create with parameters: #{data.inspect}"
65
+
66
+ unless (id = get_id(name: data[:name], hostid: data[:hostid]))
67
+ id = create(data)
68
+ end
69
+ id
70
+ end
71
+
72
+ # Create or update Item object using Zabbix API
73
+ #
74
+ # @param data [Hash] Needs to include name and hostid to properly identify Items via Zabbix API
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 [Integer] Zabbix object id
78
+ def create_or_update(data)
79
+ itemid = get_id(name: data[:name], hostid: data[:hostid])
80
+ itemid ? update(data.merge(itemid: itemid)) : create(data)
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,17 @@
1
+ class ZabbixApi
2
+ class Maintenance < Basic
3
+ # The method name used for interacting with Maintenances via Zabbix API
4
+ #
5
+ # @return [String]
6
+ def method_name
7
+ 'maintenance'
8
+ end
9
+
10
+ # The id field name used for identifying specific Maintenance objects via Zabbix API
11
+ #
12
+ # @return [String]
13
+ def identify
14
+ 'name'
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,109 @@
1
+ class ZabbixApi
2
+ class Mediatypes < Basic
3
+ # The method name used for interacting with MediaTypes via Zabbix API
4
+ #
5
+ # @return [String]
6
+ def method_name
7
+ 'mediatype'
8
+ end
9
+
10
+ # The id field name used for identifying specific MediaType objects via Zabbix API
11
+ #
12
+ # @return [String]
13
+ def identify
14
+ 'name'
15
+ end
16
+
17
+ # The default options used when creating MediaType objects via Zabbix API
18
+ #
19
+ # @return [Hash]
20
+ def default_options
21
+ {
22
+ name: '', # Name
23
+ description: '', # Description
24
+ type: 0, # 0 - Email, 1 - External script, 2 - SMS, 3 - Jabber, 100 - EzTexting
25
+ smtp_server: '',
26
+ smtp_helo: '',
27
+ smtp_email: '', # Email address of Zabbix server
28
+ exec_path: '', # Name of external script
29
+ gsm_modem: '', # Serial device name of GSM modem
30
+ username: '', # Jabber user name used by Zabbix server
31
+ passwd: '' # Jabber password used by Zabbix server
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
108
+ end
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