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
@@ -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 indentify
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,7 +10,7 @@ class ZabbixApi
10
10
  # The id field name used for identifying specific Application objects via Zabbix API
11
11
  #
12
12
  # @return [String]
13
- def indentify
13
+ def identify
14
14
  'name'
15
15
  end
16
16
 
@@ -23,7 +23,7 @@ class ZabbixApi
23
23
  def get_or_create(data)
24
24
  log "[DEBUG] Call get_or_create with parameters: #{data.inspect}"
25
25
 
26
- unless (id = get_id(:name => data[:name], :hostid => data[:hostid]))
26
+ unless (id = get_id(name: data[:name], hostid: data[:hostid]))
27
27
  id = create(data)
28
28
  end
29
29
  id
@@ -36,8 +36,8 @@ class ZabbixApi
36
36
  # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
37
37
  # @return [Integer] Zabbix object id
38
38
  def create_or_update(data)
39
- applicationid = get_id(:name => data[:name], :hostid => data[:hostid])
40
- applicationid ? update(data.merge(:applicationid => applicationid)) : create(data)
39
+ applicationid = get_id(name: data[:name], hostid: data[:hostid])
40
+ applicationid ? update(data.merge(applicationid: applicationid)) : create(data)
41
41
  end
42
42
  end
43
43
  end
@@ -15,7 +15,7 @@ class ZabbixApi
15
15
  # The id field name used for identifying specific Configuration objects via Zabbix API
16
16
  #
17
17
  # @return [String]
18
- def indentify
18
+ def identify
19
19
  'host'
20
20
  end
21
21
 
@@ -26,7 +26,7 @@ class ZabbixApi
26
26
  # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
27
27
  # @return [Hash]
28
28
  def export(data)
29
- @client.api_request(:method => 'configuration.export', :params => data)
29
+ @client.api_request(method: 'configuration.export', params: data)
30
30
  end
31
31
 
32
32
  # Import configuration data using Zabbix API
@@ -36,7 +36,7 @@ class ZabbixApi
36
36
  # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
37
37
  # @return [Hash]
38
38
  def import(data)
39
- @client.api_request(:method => 'configuration.import', :params => data)
39
+ @client.api_request(method: 'configuration.import', params: data)
40
40
  end
41
41
  end
42
42
  end
@@ -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
@@ -12,8 +12,11 @@ class ZabbixApi
12
12
  private
13
13
 
14
14
  def set_error!
15
- @error = @response['error'] rescue nil
16
- @error_message = "#{@error['message']}: #{@error['data']}" rescue nil
15
+ @error = @response['error']
16
+ @error_message = "#{@error['message']}: #{@error['data']}"
17
+ rescue StandardError
18
+ @error = nil
19
+ @error_message = nil
17
20
  end
18
21
  end
19
22
 
@@ -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
@@ -10,26 +10,26 @@ 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 indentify
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 (indentify) and id value
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 parametrs: #{data.inspect}"
24
+ log "[DEBUG] Call get_full_data with parameters: #{data.inspect}"
25
25
 
26
26
  @client.api_request(
27
- :method => "#{method_name}.get",
28
- :params => {
29
- :search => {
30
- indentify.to_sym => data[indentify.to_sym],
27
+ method: "#{method_name}.get",
28
+ params: {
29
+ search: {
30
+ identify.to_sym => data[identify.to_sym]
31
31
  },
32
- :output => 'extend',
32
+ output: 'extend'
33
33
  }
34
34
  )
35
35
  end
@@ -41,33 +41,23 @@ class ZabbixApi
41
41
  # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
42
42
  # @return [Array] Returns array of Graph ids
43
43
  def get_ids_by_host(data)
44
- ids = []
45
- graphs = {}
46
-
47
44
  result = @client.api_request(
48
- :method => 'graph.get',
49
- :params => {
50
- :filter => {
51
- :host => data[:host],
45
+ method: 'graph.get',
46
+ params: {
47
+ filter: {
48
+ host: data[:host]
52
49
  },
53
- :output => 'extend',
50
+ output: 'extend'
54
51
  }
55
52
  )
56
53
 
57
- result.each do |graph|
54
+ result.map do |graph|
58
55
  num = graph['graphid']
59
56
  name = graph['name']
60
- graphs[name] = num
61
57
  filter = data[:filter]
62
58
 
63
- if filter.nil?
64
- ids.push(graphs[name])
65
- elsif /#{filter}/ =~ name
66
- ids.push(graphs[name])
67
- end
68
- end
69
-
70
- ids
59
+ num if filter.nil? || /#{filter}/ =~ name
60
+ end.compact
71
61
  end
72
62
 
73
63
  # Get Graph Item object using Zabbix API
@@ -78,10 +68,10 @@ class ZabbixApi
78
68
  # @return [Hash]
79
69
  def get_items(data)
80
70
  @client.api_request(
81
- :method => 'graphitem.get',
82
- :params => {
83
- :graphids => [data],
84
- :output => 'extend',
71
+ method: 'graphitem.get',
72
+ params: {
73
+ graphids: [data],
74
+ output: 'extend'
85
75
  }
86
76
  )
87
77
  end
@@ -95,7 +85,7 @@ class ZabbixApi
95
85
  def get_or_create(data)
96
86
  log "[DEBUG] Call get_or_create with parameters: #{data.inspect}"
97
87
 
98
- unless (id = get_id(:name => data[:name], :templateid => data[:templateid]))
88
+ unless (id = get_id(name: data[:name], templateid: data[:templateid]))
99
89
  id = create(data)
100
90
  end
101
91
 
@@ -109,8 +99,8 @@ class ZabbixApi
109
99
  # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
110
100
  # @return [Integer] Zabbix object id
111
101
  def create_or_update(data)
112
- graphid = get_id(:name => data[:name], :templateid => data[:templateid])
113
- graphid ? _update(data.merge(:graphid => graphid)) : create(data)
102
+ graphid = get_id(name: data[:name], templateid: data[:templateid])
103
+ graphid ? _update(data.merge(graphid: graphid)) : create(data)
114
104
  end
115
105
 
116
106
  def _update(data)
@@ -10,7 +10,7 @@ class ZabbixApi
10
10
  # The id field name used for identifying specific HostGroup objects via Zabbix API
11
11
  #
12
12
  # @return [String]
13
- def indentify
13
+ def identify
14
14
  'name'
15
15
  end
16
16
 
@@ -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 indentify
13
+ def identify
14
14
  'host'
15
15
  end
16
16
 
@@ -21,16 +21,16 @@ 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 parametrs: #{data.inspect}"
24
+ log "[DEBUG] Call dump_by_id with parameters: #{data.inspect}"
25
25
 
26
26
  @client.api_request(
27
- :method => 'host.get',
28
- :params => {
29
- :filter => {
30
- key.to_sym => data[key.to_sym],
27
+ method: 'host.get',
28
+ params: {
29
+ filter: {
30
+ key.to_sym => data[key.to_sym]
31
31
  },
32
- :output => 'extend',
33
- :selectGroups => 'shorten',
32
+ output: 'extend',
33
+ selectGroups: 'shorten'
34
34
  }
35
35
  )
36
36
  end
@@ -40,12 +40,12 @@ class ZabbixApi
40
40
  # @return [Hash]
41
41
  def default_options
42
42
  {
43
- :host => nil,
44
- :interfaces => [],
45
- :status => 0,
46
- :available => 1,
47
- :groups => [],
48
- :proxy_hostid => nil,
43
+ host: nil,
44
+ interfaces: [],
45
+ status: 0,
46
+ available: 1,
47
+ groups: [],
48
+ proxy_hostid: nil
49
49
  }
50
50
  end
51
51
 
@@ -57,10 +57,10 @@ class ZabbixApi
57
57
  # @return [Boolean]
58
58
  def unlink_templates(data)
59
59
  result = @client.api_request(
60
- :method => 'host.massRemove',
61
- :params => {
62
- :hostids => data[:hosts_id],
63
- :templates => data[:templates_id],
60
+ method: 'host.massRemove',
61
+ params: {
62
+ hostids: data[:hosts_id],
63
+ templates: data[:templates_id]
64
64
  }
65
65
  )
66
66
  result.empty? ? false : true
@@ -73,8 +73,8 @@ class ZabbixApi
73
73
  # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
74
74
  # @return [Integer] Zabbix object id
75
75
  def create_or_update(data)
76
- hostid = get_id(:host => data[:host])
77
- hostid ? update(data.merge(:hostid => hostid)) : create(data)
76
+ hostid = get_id(host: data[:host])
77
+ hostid ? update(data.merge(hostid: hostid)) : create(data)
78
78
  end
79
79
  end
80
80
  end
@@ -10,7 +10,7 @@ class ZabbixApi
10
10
  # The id field name used for identifying specific HttpTest objects via Zabbix API
11
11
  #
12
12
  # @return [String]
13
- def indentify
13
+ def identify
14
14
  'name'
15
15
  end
16
16
 
@@ -19,9 +19,9 @@ class ZabbixApi
19
19
  # @return [Hash]
20
20
  def default_options
21
21
  {
22
- :hostid => nil,
23
- :name => nil,
24
- :steps => [],
22
+ hostid: nil,
23
+ name: nil,
24
+ steps: []
25
25
  }
26
26
  end
27
27
 
@@ -34,7 +34,7 @@ class ZabbixApi
34
34
  def get_or_create(data)
35
35
  log "[DEBUG] Call get_or_create with parameters: #{data.inspect}"
36
36
 
37
- unless (id = get_id(:name => data[:name], :hostid => data[:hostid]))
37
+ unless (id = get_id(name: data[:name], hostid: data[:hostid]))
38
38
  id = create(data)
39
39
  end
40
40
  id
@@ -47,8 +47,8 @@ class ZabbixApi
47
47
  # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
48
48
  # @return [Integer] Zabbix object id
49
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)
50
+ httptestid = get_id(name: data[:name], hostid: data[:hostid])
51
+ httptestid ? update(data.merge(httptestid: httptestid)) : create(data)
52
52
  end
53
53
  end
54
54
  end
@@ -10,7 +10,7 @@ class ZabbixApi
10
10
  # The id field name used for identifying specific Item objects via Zabbix API
11
11
  #
12
12
  # @return [String]
13
- def indentify
13
+ def identify
14
14
  'name'
15
15
  end
16
16
 
@@ -19,38 +19,38 @@ class ZabbixApi
19
19
  # @return [Hash]
20
20
  def default_options
21
21
  {
22
- :name => nil,
23
- :key_ => nil,
24
- :hostid => nil,
25
- :delay => 60,
26
- :history => 60,
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 => 365,
44
- :logtimefmt => '',
45
- :valuemapid => 0,
46
- :delay_flex => '',
47
- :authtype => 0,
48
- :username => '',
49
- :password => '',
50
- :publickey => '',
51
- :privatekey => '',
52
- :params => '',
53
- :ipmi_sensor => '',
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
54
  }
55
55
  end
56
56
 
@@ -63,7 +63,7 @@ class ZabbixApi
63
63
  def get_or_create(data)
64
64
  log "[DEBUG] Call get_or_create with parameters: #{data.inspect}"
65
65
 
66
- unless (id = get_id(:name => data[:name], :hostid => data[:hostid]))
66
+ unless (id = get_id(name: data[:name], hostid: data[:hostid]))
67
67
  id = create(data)
68
68
  end
69
69
  id
@@ -76,8 +76,8 @@ class ZabbixApi
76
76
  # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
77
77
  # @return [Integer] Zabbix object id
78
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)
79
+ itemid = get_id(name: data[:name], hostid: data[:hostid])
80
+ itemid ? update(data.merge(itemid: itemid)) : create(data)
81
81
  end
82
82
  end
83
83
  end