zabbixapi 4.1.0 → 4.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 487cf74b4af955baf4a18b789b90185235a789a1
4
- data.tar.gz: d19ee4e5b3bf2e5f514795bc83a69cde75d8c29c
2
+ SHA256:
3
+ metadata.gz: 95ee423a594e68d486a453c3bf2136fe8d6977236f09a006014655d7ffcc1e1f
4
+ data.tar.gz: 9bc71cd00aa0e3b01fdbb01bd97d8d01684d033a1720a3f29a78a6a11ca5375f
5
5
  SHA512:
6
- metadata.gz: bc2f217355f205c40eb991469834a45d84e7f89adf7f28a9b9233e64a085c06300fb13d49bb2c96064681ea3f44f986a84fa1952e86416b05b6547e1fcfd1480
7
- data.tar.gz: acc66046eeb21fdccf0404d19c3eedef36bb31fdd49945e8eb3a6f7793e15c0f0d65f2c3128b9591af763b0157f9d0f29b1f06149d853c27798132a5899f9c51
6
+ metadata.gz: 79f32a38cd75e8dde77ece567476a102a2b764cd9aee0e280a2ee07b3fefe9256e2043be06a4ec2cd42fbaa36f3bc718b5e8332d08e437213ae97dff9b8b08bb
7
+ data.tar.gz: c81b84714aa19441c9bb0cc173dacc69d2141afa1ff92cf05724a59aa5d86bbce069186d412d1da68989ba14a4cd62b566b1900d6f65f9ea6c65cb0f5bd55e6a
data/README.md CHANGED
@@ -22,7 +22,7 @@ Simple and lightweight ruby module for working with [Zabbix][Zabbix] via the [Za
22
22
  [examples]: https://github.com/express42/zabbixapi/tree/master/examples
23
23
 
24
24
  ## Version Policy
25
- We support only two last versions of zabbix (3.4 and 4.0), so you should consider all previous versions deprecated.
25
+ We support only two last versions of zabbix (4.0 and 4.2), so you should consider all previous versions deprecated.
26
26
 
27
27
  * Zabbix 1.8.2 (api version 1.2) | zabbixapi 0.6.x | [branch zabbix1.8](https://github.com/express42/zabbixapi/tree/zabbix1.8)
28
28
  * Zabbix 1.8.9 (api version 1.3) | zabbixapi 0.6.x | [branch zabbix1.8](https://github.com/express42/zabbixapi/tree/zabbix1.8)
@@ -52,7 +52,7 @@ class ZabbixApi
52
52
  # @param data [Hash]
53
53
  # @return [Hash]
54
54
  def query(data)
55
- @client.api_request(:method => data[:method], :params => data[:params])
55
+ @client.api_request(method: data[:method], params: data[:params])
56
56
  end
57
57
 
58
58
  # Invalidate current authentication token
@@ -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
@@ -12,7 +12,7 @@ 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
 
@@ -27,7 +27,7 @@ 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
 
@@ -64,7 +64,7 @@ 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
@@ -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
+ indentify.to_sym => data[indentify.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,7 +131,7 @@ 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|
134
+ @client.api_request(method: "#{method_name}.get", params: { output: 'extend' }).each do |item|
135
135
  result[item[indentify]] = item[key]
136
136
  end
137
137
  result
@@ -150,11 +150,12 @@ class ZabbixApi
150
150
  # raise an error if indentify name was not supplied
151
151
  name = data[indentify.to_sym]
152
152
  raise ApiError.new("#{indentify} 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, indentify]
158
159
  }
159
160
  )
160
161
  id = nil
@@ -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
@@ -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
@@ -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
 
@@ -24,12 +24,12 @@ class ZabbixApi
24
24
  log "[DEBUG] Call get_full_data with parametrs: #{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
+ indentify.to_sym => data[indentify.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)
@@ -24,13 +24,13 @@ class ZabbixApi
24
24
  log "[DEBUG] Call dump_by_id with parametrs: #{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
@@ -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
@@ -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: 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: ''
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
@@ -19,15 +19,15 @@ class ZabbixApi
19
19
  # @return [Hash]
20
20
  def default_options
21
21
  {
22
- :description => '', # Name
23
- :type => 0, # 0 - Email, 1 - External script, 2 - SMS, 3 - Jabber, 100 - EzTexting
24
- :smtp_server => '',
25
- :smtp_helo => '',
26
- :smtp_email => '', # Email address of Zabbix server
27
- :exec_path => '', # Name of external script
28
- :gsm_modem => '', # Serial device name of GSM modem
29
- :username => '', # Jabber user name used by Zabbix server
30
- :passwd => '' # Jabber password used by Zabbix server
22
+ description: '', # Name
23
+ type: 0, # 0 - Email, 1 - External script, 2 - SMS, 3 - Jabber, 100 - EzTexting
24
+ smtp_server: '',
25
+ smtp_helo: '',
26
+ smtp_email: '', # Email address of Zabbix server
27
+ exec_path: '', # Name of external script
28
+ gsm_modem: '', # Serial device name of GSM modem
29
+ username: '', # Jabber user name used by Zabbix server
30
+ passwd: '' # Jabber password used by Zabbix server
31
31
  }
32
32
  end
33
33
  end
@@ -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 [Integer] The Proxy object id that was deleted
23
23
  def delete(data)
24
- result = @client.api_request(:method => 'proxy.delete', :params => data)
24
+ result = @client.api_request(method: 'proxy.delete', params: data)
25
25
  result.empty? ? nil : result['proxyids'][0].to_i
26
26
  end
27
27
 
@@ -32,7 +32,7 @@ class ZabbixApi
32
32
  # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
33
33
  # @return [Boolean] Returns true if the given proxies are readable
34
34
  def isreadable(data)
35
- @client.api_request(:method => 'proxy.isreadable', :params => data)
35
+ @client.api_request(method: 'proxy.isreadable', params: data)
36
36
  end
37
37
 
38
38
  # Check if a Proxy object is writable using Zabbix API
@@ -42,7 +42,7 @@ class ZabbixApi
42
42
  # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
43
43
  # @return [Boolean] Returns true if the given proxies are writable
44
44
  def iswritable(data)
45
- @client.api_request(:method => 'proxy.iswritable', :params => data)
45
+ @client.api_request(method: 'proxy.iswritable', params: data)
46
46
  end
47
47
  end
48
48
  end
@@ -40,7 +40,7 @@ class ZabbixApi
40
40
  # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
41
41
  # @return [Integer] Zabbix object id
42
42
  def delete(data)
43
- result = @client.api_request(:method => 'screen.delete', :params => [data])
43
+ result = @client.api_request(method: 'screen.delete', params: [data])
44
44
  result.empty? ? nil : result['screenids'][0].to_i
45
45
  end
46
46
 
@@ -62,29 +62,30 @@ class ZabbixApi
62
62
  height = data[:height] || 320 # default 320
63
63
  width = data[:width] || 200 # default 200
64
64
  vsize = data[:vsize] || [1, (graphids.size / hsize).to_i].max
65
- screenid = get_id(:name => screen_name)
65
+ screenid = get_id(name: screen_name)
66
66
 
67
67
  unless screenid
68
68
  # Create screen
69
69
  graphids.each_with_index do |graphid, index|
70
70
  screenitems << {
71
- :resourcetype => 0,
72
- :resourceid => graphid,
73
- :x => (index % hsize).to_i,
74
- :y => (index % graphids.size / hsize).to_i,
75
- :valign => valign,
76
- :halign => halign,
77
- :rowspan => rowspan,
78
- :colspan => colspan,
79
- :height => height,
80
- :width => width,
71
+ resourcetype: 0,
72
+ resourceid: graphid,
73
+ x: (index % hsize).to_i,
74
+ y: (index % graphids.size / hsize).to_i,
75
+ valign: valign,
76
+ halign: halign,
77
+ rowspan: rowspan,
78
+ colspan: colspan,
79
+ height: height,
80
+ width: width
81
81
  }
82
82
  end
83
+
83
84
  screenid = create(
84
- :name => screen_name,
85
- :hsize => hsize,
86
- :vsize => vsize,
87
- :screenitems => screenitems
85
+ name: screen_name,
86
+ hsize: hsize,
87
+ vsize: vsize,
88
+ screenitems: screenitems
88
89
  )
89
90
  end
90
91
  screenid
@@ -1,27 +1,35 @@
1
1
  class ZabbixApi
2
2
  class Scripts < Basic
3
-
4
3
  def method_name
5
- "script"
4
+ 'script'
6
5
  end
7
6
 
7
+ # The id field name used for identifying specific Screen objects via Zabbix API
8
+ #
9
+ # @return [String]
8
10
  def indentify
9
- "name"
11
+ 'name'
10
12
  end
11
13
 
14
+ # Submits a request to the zabbix api
15
+ # data - A Hash containing the scriptid and hostid
16
+ #
17
+ # Example:
18
+ # execute({ scriptid: '12', hostid: '32 })
19
+ #
20
+ # Returns nothing
12
21
  def execute(data)
13
22
  @client.api_request(
14
- :method => "script.execute",
15
- :params => {
16
- :scriptid => data[:scriptid],
17
- :hostid => data[:hostid]
23
+ method: 'script.execute',
24
+ params: {
25
+ scriptid: data[:scriptid],
26
+ hostid: data[:hostid]
18
27
  }
19
28
  )
20
29
  end
21
30
 
22
31
  def getscriptsbyhost(data)
23
- @client.api_request(:method => "script.getscriptsbyhosts", :params => data)
32
+ @client.api_request(method: 'script.getscriptsbyhosts', params: data)
24
33
  end
25
-
26
34
  end
27
35
  end
@@ -10,7 +10,7 @@ class ZabbixApi
10
10
  # @return [String] Zabbix API version number
11
11
  def initialize(client)
12
12
  @client = client
13
- @version = @client.api_request(:method => 'apiinfo.version', :params => {})
13
+ @api_version = @client.api_request(method: 'apiinfo.version', params: {})
14
14
  end
15
15
  end
16
16
  end
@@ -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 [Integer] The Template object id that was deleted
23
23
  def delete(data)
24
- result = @client.api_request(:method => 'template.delete', :params => [data])
24
+ result = @client.api_request(method: 'template.delete', params: [data])
25
25
  result.empty? ? nil : result['templateids'][0].to_i
26
26
  end
27
27
 
@@ -32,11 +32,9 @@ class ZabbixApi
32
32
  # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
33
33
  # @return [Array] Returns array of Template ids
34
34
  def get_ids_by_host(data)
35
- result = []
36
- @client.api_request(:method => 'template.get', :params => data).each do |tmpl|
37
- result << tmpl['templateid']
35
+ @client.api_request(method: 'template.get', params: data).map do |tmpl|
36
+ tmpl['templateid']
38
37
  end
39
- result
40
38
  end
41
39
 
42
40
  # Get or Create Template object using Zabbix API
@@ -46,7 +44,7 @@ class ZabbixApi
46
44
  # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
47
45
  # @return [Integer] Zabbix object id
48
46
  def get_or_create(data)
49
- unless (templateid = get_id(:host => data[:host]))
47
+ unless (templateid = get_id(host: data[:host]))
50
48
  templateid = create(data)
51
49
  end
52
50
  templateid
@@ -60,10 +58,10 @@ class ZabbixApi
60
58
  # @return [Boolean]
61
59
  def mass_update(data)
62
60
  result = @client.api_request(
63
- :method => 'template.massUpdate',
64
- :params => {
65
- :hosts => data[:hosts_id].map { |t| {:hostid => t} },
66
- :templates => data[:templates_id].map { |t| {:templateid => t} },
61
+ method: 'template.massUpdate',
62
+ params: {
63
+ hosts: data[:hosts_id].map { |t| { hostid: t } },
64
+ templates: data[:templates_id].map { |t| { templateid: t } }
67
65
  }
68
66
  )
69
67
  result.empty? ? false : true
@@ -77,10 +75,10 @@ class ZabbixApi
77
75
  # @return [Boolean]
78
76
  def mass_add(data)
79
77
  result = @client.api_request(
80
- :method => 'template.massAdd',
81
- :params => {
82
- :hosts => data[:hosts_id].map { |t| {:hostid => t} },
83
- :templates => data[:templates_id].map { |t| {:templateid => t} },
78
+ method: 'template.massAdd',
79
+ params: {
80
+ hosts: data[:hosts_id].map { |t| { hostid: t } },
81
+ templates: data[:templates_id].map { |t| { templateid: t } }
84
82
  }
85
83
  )
86
84
  result.empty? ? false : true
@@ -94,12 +92,12 @@ class ZabbixApi
94
92
  # @return [Boolean]
95
93
  def mass_remove(data)
96
94
  result = @client.api_request(
97
- :method => 'template.massRemove',
98
- :params => {
99
- :hostids => data[:hosts_id],
100
- :templateids => data[:templates_id],
101
- :groupids => data[:group_id],
102
- :force => 1,
95
+ method: 'template.massRemove',
96
+ params: {
97
+ hostids: data[:hosts_id],
98
+ templateids: data[:templates_id],
99
+ groupids: data[:group_id],
100
+ force: 1
103
101
  }
104
102
  )
105
103
  result.empty? ? false : true
@@ -24,14 +24,14 @@ class ZabbixApi
24
24
  log "[DEBUG] Call dump_by_id with parametrs: #{data.inspect}"
25
25
 
26
26
  @client.api_request(
27
- :method => 'trigger.get',
28
- :params => {
29
- :filter => {
30
- key.to_sym => data[key.to_sym],
27
+ method: 'trigger.get',
28
+ params: {
29
+ filter: {
30
+ key.to_sym => data[key.to_sym]
31
31
  },
32
- :output => 'extend',
33
- :select_items => 'extend',
34
- :select_functions => 'extend',
32
+ output: 'extend',
33
+ select_items: 'extend',
34
+ select_functions: 'extend'
35
35
  }
36
36
  )
37
37
  end
@@ -68,7 +68,7 @@ class ZabbixApi
68
68
  else
69
69
  data[:expression] = old_expression
70
70
  # disable old trigger
71
- log '[DEBUG] disable :' + @client.api_request(:method => "#{method_name}.update", :params => [{:triggerid => data[:triggerid], :status => '1'}]).inspect
71
+ log '[DEBUG] disable :' + @client.api_request(method: "#{method_name}.update", params: [{ triggerid: data[:triggerid], status: '1' }]).inspect
72
72
  # create new trigger
73
73
  data.delete(:triggerid)
74
74
  create(data)
@@ -84,7 +84,7 @@ class ZabbixApi
84
84
  def get_or_create(data)
85
85
  log "[DEBUG] Call get_or_create with parameters: #{data.inspect}"
86
86
 
87
- unless (id = get_id(:description => data[:description], :hostid => data[:hostid]))
87
+ unless (id = get_id(description: data[:description], hostid: data[:hostid]))
88
88
  id = create(data)
89
89
  end
90
90
  id
@@ -97,8 +97,9 @@ class ZabbixApi
97
97
  # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
98
98
  # @return [Integer] Zabbix object id
99
99
  def create_or_update(data)
100
- triggerid = get_id(:description => data[:description], :hostid => data[:hostid])
101
- triggerid ? update(data.merge(:triggerid => triggerid)) : create(data)
100
+ triggerid = get_id(description: data[:description], hostid: data[:hostid])
101
+
102
+ triggerid ? update(data.merge(triggerid: triggerid)) : create(data)
102
103
  end
103
104
  end
104
105
  end
@@ -27,13 +27,13 @@ class ZabbixApi
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] Zabbix object id (usergroup)
30
- def set_perms(data)
30
+ def permissions(data)
31
31
  permission = data[:permission] || 2
32
32
  result = @client.api_request(
33
- :method => 'usergroup.massAdd',
34
- :params => {
35
- :usrgrpids => [data[:usrgrpid]],
36
- :rights => data[:hostgroupids].map { |t| {:permission => permission, :id => t} },
33
+ method: 'usergroup.massAdd',
34
+ params: {
35
+ usrgrpids: [data[:usrgrpid]],
36
+ rights: data[:hostgroupids].map { |t| { permission: permission, id: t } }
37
37
  }
38
38
  )
39
39
  result ? result['usrgrpids'][0].to_i : nil
@@ -47,10 +47,10 @@ class ZabbixApi
47
47
  # @return [Integer] Zabbix object id (usergroup)
48
48
  def add_user(data)
49
49
  result = @client.api_request(
50
- :method => 'usergroup.massAdd',
51
- :params => {
52
- :usrgrpids => data[:usrgrpids],
53
- :userids => data[:userids],
50
+ method: 'usergroup.massAdd',
51
+ params: {
52
+ usrgrpids: data[:usrgrpids],
53
+ userids: data[:userids]
54
54
  }
55
55
  )
56
56
  result ? result['usrgrpids'][0].to_i : nil
@@ -64,10 +64,10 @@ class ZabbixApi
64
64
  # @return [Integer] Zabbix object id (usergroup)
65
65
  def update_users(data)
66
66
  result = @client.api_request(
67
- :method => 'usergroup.massUpdate',
68
- :params => {
69
- :usrgrpids => data[:usrgrpids],
70
- :userids => data[:userids],
67
+ method: 'usergroup.massUpdate',
68
+ params: {
69
+ usrgrpids: data[:usrgrpids],
70
+ userids: data[:userids]
71
71
  }
72
72
  )
73
73
  result ? result['usrgrpids'][0].to_i : nil
@@ -47,7 +47,7 @@ class ZabbixApi
47
47
  data = symbolize_keys(data) if data.key?(indentify)
48
48
  # raise an error if indentify name was not supplied
49
49
  name = data[indentify.to_sym]
50
- raise ApiError.new("#{indentify} not supplied in call to get_id") if name.nil?
50
+ raise ApiError.new("#{indentify} not supplied in call to get_id_global") if name.nil?
51
51
 
52
52
  result = request(data, 'usermacro.get', 'globalmacroid')
53
53
 
@@ -157,7 +157,7 @@ class ZabbixApi
157
157
  def get_or_create(data)
158
158
  log "[DEBUG] Call get_or_create with parameters: #{data.inspect}"
159
159
 
160
- unless (id = get_id(:macro => data[:macro], :hostid => data[:hostid]))
160
+ unless (id = get_id(macro: data[:macro], hostid: data[:hostid]))
161
161
  id = create(data)
162
162
  end
163
163
  id
@@ -172,7 +172,7 @@ class ZabbixApi
172
172
  def get_or_create_global(data)
173
173
  log "[DEBUG] Call get_or_create_global with parameters: #{data.inspect}"
174
174
 
175
- unless (id = get_id_global(:macro => data[:macro], :hostid => data[:hostid]))
175
+ unless (id = get_id_global(macro: data[:macro], hostid: data[:hostid]))
176
176
  id = create_global(data)
177
177
  end
178
178
  id
@@ -185,8 +185,8 @@ class ZabbixApi
185
185
  # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
186
186
  # @return [Integer] Zabbix object id
187
187
  def create_or_update(data)
188
- hostmacroid = get_id(:macro => data[:macro], :hostid => data[:hostid])
189
- hostmacroid ? update(data.merge(:hostmacroid => hostmacroid)) : create(data)
188
+ hostmacroid = get_id(macro: data[:macro], hostid: data[:hostid])
189
+ hostmacroid ? update(data.merge(hostmacroid: hostmacroid)) : create(data)
190
190
  end
191
191
 
192
192
  # Create or update Global macro object using Zabbix API
@@ -196,8 +196,8 @@ class ZabbixApi
196
196
  # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
197
197
  # @return [Integer] Zabbix object id
198
198
  def create_or_update_global(data)
199
- hostmacroid = get_id_global(:macro => data[:macro], :hostid => data[:hostid])
200
- hostmacroid ? update_global(data.merge(:globalmacroid => globalmacroid)) : create_global(data)
199
+ globalmacroid = get_id_global(macro: data[:macro], hostid: data[:hostid])
200
+ globalmacroid ? update_global(data.merge(globalmacroid: globalmacroid)) : create_global(data)
201
201
  end
202
202
 
203
203
  private
@@ -214,12 +214,12 @@ class ZabbixApi
214
214
  # Zabbix has different result formats for gets vs updates
215
215
  if method.include?('.get')
216
216
  if result_key.include?('global')
217
- @client.api_request(:method => method, :params => {:globalmacro => true, :filter => data})
217
+ @client.api_request(method: method, params: { globalmacro: true, filter: data })
218
218
  else
219
- @client.api_request(:method => method, :params => {:filter => data})
219
+ @client.api_request(method: method, params: { filter: data })
220
220
  end
221
221
  else
222
- result = @client.api_request(:method => method, :params => data)
222
+ result = @client.api_request(method: method, params: data)
223
223
 
224
224
  result.key?(result_key) && !result[result_key].empty? ? result[result_key][0].to_i : nil
225
225
  end
@@ -28,6 +28,17 @@ class ZabbixApi
28
28
  'alias'
29
29
  end
30
30
 
31
+ def medias_helper(data, action)
32
+ result = @client.api_request(
33
+ method: "user.#{action}",
34
+ params: {
35
+ users: data[:userids].map { |t| { userid: t } },
36
+ medias: data[:media]
37
+ }
38
+ )
39
+ result ? result['mediaids'][0].to_i : nil
40
+ end
41
+
31
42
  # Add media to users using Zabbix API
32
43
  #
33
44
  # @param data [Hash] Needs to include userids and media to mass add media to users
@@ -35,14 +46,7 @@ class ZabbixApi
35
46
  # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
36
47
  # @return [Integer] Zabbix object id (media)
37
48
  def add_medias(data)
38
- result = @client.api_request(
39
- :method => 'user.addMedia',
40
- :params => {
41
- :users => data[:userids].map { |t| {:userid => t} },
42
- :medias => data[:media],
43
- }
44
- )
45
- result ? result['mediaids'][0].to_i : nil
49
+ medias_helper(data, 'addMedia')
46
50
  end
47
51
 
48
52
  # Update media for users using Zabbix API
@@ -52,14 +56,7 @@ class ZabbixApi
52
56
  # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
53
57
  # @return [Integer] Zabbix object id (user)
54
58
  def update_medias(data)
55
- result = @client.api_request(
56
- :method => 'user.updateMedia',
57
- :params => {
58
- :users => data[:userids].map { |t| {:userid => t} },
59
- :medias => data[:media],
60
- }
61
- )
62
- result ? result['userids'][0].to_i : nil
59
+ medias_helper(data, 'updateMedia')
63
60
  end
64
61
  end
65
62
  end
@@ -30,7 +30,7 @@ class ZabbixApi
30
30
  def get_or_create(data)
31
31
  log "[DEBUG] Call get_or_create with parameters: #{data.inspect}"
32
32
 
33
- unless (id = get_id(:valuemapids => data[:valuemapids]))
33
+ unless (id = get_id(valuemapids: data[:valuemapids]))
34
34
  id = create(data)
35
35
  end
36
36
  id
@@ -43,8 +43,8 @@ class ZabbixApi
43
43
  # @raise [HttpError] Error raised when HTTP status from Zabbix Server response is not a 200 OK.
44
44
  # @return [Integer] Zabbix object id
45
45
  def create_or_update(data)
46
- valuemapid = get_id(:name => data[:name])
47
- valuemapid ? update(data.merge(:valuemapids => [:valuemapid])) : create(data)
46
+ valuemapid = get_id(name: data[:name])
47
+ valuemapid ? update(data.merge(valuemapids: [:valuemapid])) : create(data)
48
48
  end
49
49
  end
50
50
  end
@@ -1,5 +1,6 @@
1
1
  require 'net/http'
2
2
  require 'json'
3
+ require 'openssl'
3
4
 
4
5
  class ZabbixApi
5
6
  class Client
@@ -16,7 +17,7 @@ class ZabbixApi
16
17
  #
17
18
  # @return [String]
18
19
  def api_version
19
- @version ||= api_request(:method => 'apiinfo.version', :params => {})
20
+ @api_version ||= api_request(method: 'apiinfo.version', params: {})
20
21
  end
21
22
 
22
23
  # Log in to the Zabbix Server and generate an auth token using the API
@@ -24,24 +25,14 @@ class ZabbixApi
24
25
  # @return [Hash]
25
26
  def auth
26
27
  api_request(
27
- :method => 'user.login',
28
- :params => {
29
- :user => @options[:user],
30
- :password => @options[:password],
28
+ method: 'user.login',
29
+ params: {
30
+ user: @options[:user],
31
+ password: @options[:password]
31
32
  }
32
33
  )
33
34
  end
34
35
 
35
- # Log out from the Zabbix Server
36
- #
37
- # @return [Boolean]
38
- def logout
39
- api_request(
40
- :method => 'user.logout',
41
- :params => []
42
- )
43
- end
44
-
45
36
  # Initializes a new Client object
46
37
  #
47
38
  # @param options [Hash]
@@ -61,9 +52,10 @@ class ZabbixApi
61
52
  @proxy_port = @proxy_uri.port
62
53
  @proxy_user, @proxy_pass = @proxy_uri.userinfo.split(/:/) if @proxy_uri.userinfo
63
54
  end
64
- unless api_version =~ /(2\.4|3\.[024]|4\.0)\.\d+/
65
- raise ApiError.new("Zabbix API version: #{api_version} is not support by this version of zabbixapi")
55
+ unless api_version =~ %r{^4.[0|2]\.\d+$}
56
+ log "[WARN] Zabbix API version: #{api_version} is not supported by this version of zabbixapi"
66
57
  end
58
+
67
59
  @auth_hash = auth
68
60
  end
69
61
 
@@ -73,10 +65,10 @@ class ZabbixApi
73
65
  # @return [String]
74
66
  def message_json(body)
75
67
  message = {
76
- :method => body[:method],
77
- :params => body[:params],
78
- :id => id,
79
- :jsonrpc => '2.0',
68
+ method: body[:method],
69
+ params: body[:params],
70
+ id: id,
71
+ jsonrpc: '2.0'
80
72
  }
81
73
 
82
74
  message[:auth] = @auth_hash unless body[:method] == 'apiinfo.version' || body[:method] == 'user.login'
@@ -93,11 +85,12 @@ class ZabbixApi
93
85
  timeout = @options[:timeout].nil? ? 60 : @options[:timeout]
94
86
  puts "[DEBUG] Timeout for request set to #{timeout} seconds" if @options[:debug]
95
87
 
96
- if @proxy_uri
97
- http = Net::HTTP.Proxy(@proxy_host, @proxy_port, @proxy_user, @proxy_pass).new(uri.host, uri.port)
98
- else
99
- http = Net::HTTP.new(uri.host, uri.port)
100
- end
88
+ http =
89
+ if @proxy_uri
90
+ Net::HTTP.Proxy(@proxy_host, @proxy_port, @proxy_user, @proxy_pass).new(uri.host, uri.port)
91
+ else
92
+ Net::HTTP.new(uri.host, uri.port)
93
+ end
101
94
 
102
95
  if uri.scheme == 'https'
103
96
  http.use_ssl = true
@@ -111,6 +104,7 @@ class ZabbixApi
111
104
  request.basic_auth @options[:http_user], @options[:http_password] if @options[:http_user]
112
105
  request.add_field('Content-Type', 'application/json-rpc')
113
106
  request.body = body
107
+
114
108
  response = http.request(request)
115
109
 
116
110
  raise HttpError.new("HTTP Error: #{response.code} on #{@options[:url]}", response) unless response.code == '200'
@@ -125,6 +119,7 @@ class ZabbixApi
125
119
  puts "[DEBUG] Send request: #{body}" if @options[:debug]
126
120
  result = JSON.parse(http_request(body))
127
121
  raise ApiError.new("Server answer API error\n #{JSON.pretty_unparse(result['error'])}\n on request:\n #{pretty_body(body)}", result) if result['error']
122
+
128
123
  result['result']
129
124
  end
130
125
 
@@ -1,3 +1,3 @@
1
1
  class ZabbixApi
2
- VERSION = '4.1.0'.freeze
2
+ VERSION = '4.1.1'.freeze
3
3
  end
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.rubyforge_project = 'zabbixapi'
25
25
 
26
- spec.files = ['.yardopts', 'CHANGELOG.md', 'LICENSE.md', 'README.md', 'zabbixapi.gemspec'] + Dir['lib/**/*.rb']
26
+ spec.files = ['CHANGELOG.md', 'LICENSE.md', 'README.md', 'zabbixapi.gemspec'] + Dir['lib/**/*.rb']
27
27
  spec.require_paths = 'lib'
28
28
  spec.required_ruby_version = '>= 2.0.0'
29
29
  end
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.1.0
4
+ version: 4.1.1
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: 2018-12-25 00:00:00.000000000 Z
12
+ date: 2019-07-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: http
@@ -61,7 +61,6 @@ executables: []
61
61
  extensions: []
62
62
  extra_rdoc_files: []
63
63
  files:
64
- - ".yardopts"
65
64
  - CHANGELOG.md
66
65
  - LICENSE.md
67
66
  - README.md
@@ -115,8 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
114
  - !ruby/object:Gem::Version
116
115
  version: '0'
117
116
  requirements: []
118
- rubyforge_project: zabbixapi
119
- rubygems_version: 2.4.8
117
+ rubygems_version: 3.0.3
120
118
  signing_key:
121
119
  specification_version: 4
122
120
  summary: Simple and lightweight ruby module for working with the Zabbix API
data/.yardopts DELETED
@@ -1,9 +0,0 @@
1
- --no-private
2
- --protected
3
- --tag authentication:"Authentication"
4
- --markup markdown
5
- -
6
- CHANGELOG.md
7
- LICENSE.md
8
- README.md
9
- examples/*.md