zabbixapi 2.4.4 → 2.4.5

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
2
  SHA1:
3
- metadata.gz: d196f3e01ddbffa49332172c445ceb140d4f3c52
4
- data.tar.gz: 340e897f40f1349a9c0da756e1b25c584061c96a
3
+ metadata.gz: 25ba28c4faff22b396e0e768792448a75ca4e637
4
+ data.tar.gz: 788a52dbb357ab631f7a2029a6485c41d0d49ca1
5
5
  SHA512:
6
- metadata.gz: 7e8650a501039e28ca6e45a8bcf61ce81fd368b1a622c84c95e83240d25fec3d52e890e5d5c1b33f9039f103c374d3e4765bd3a998f0851e0bfe278a6381fe3a
7
- data.tar.gz: ab4dc190196e5584faf2c54b8f55b5873608f0484eff14f3a0db159b4339de79d25456330734e2b90c5bb65095528dd327bd4264eb6fdb326d967e20c5786bce
6
+ metadata.gz: 78dd6e98b5a32bb724259b3e34c29e509cbba0fcb5c9decbdc8a9aeca25adf1f3a3692d661de57ce76c3be2c3d4607624d3addf346c123a911a9a8c4b3b629df
7
+ data.tar.gz: 0b5ff259f158b439285c080de706336847e52c554e3dd4f4a214fc02ce877b178717c81e99b038fcd64b1bb589698b82698c447f18060af5abf58a45d47f0b1e
@@ -1,3 +1,7 @@
1
+ ## 2.4.5
2
+
3
+ [PR #33](https://github.com/express42/zabbixapi/issues/33) Typed exceptions
4
+
1
5
  ## 2.4.4
2
6
 
3
7
  [Issue #32](https://github.com/express42/zabbixapi/issues/32): Force update of objects in zabbix
data/README.md CHANGED
@@ -147,6 +147,25 @@ zbx.hosts.update(
147
147
  )
148
148
  #You can check host:
149
149
  puts zbx.hosts.get_full_data(:host => "hostname")
150
+
151
+ # Zabbixapi checks that new object differ from one in zabbix. But if you
152
+ # want to update nested arguments (like interfaces), you should use second argument.
153
+ # For example:
154
+
155
+ zbx.hosts.update({
156
+ :hostid => zbx.hosts.get_id(:host => "hostname"),
157
+ :interfaces => [
158
+ {
159
+ :type => 1,
160
+ :main => 1,
161
+ :ip => '10.0.0.1',
162
+ :dns => 'server.example.org',
163
+ :port => 10050,
164
+ :useip => 0
165
+ }
166
+ ]}, true)
167
+
168
+
150
169
  ```
151
170
 
152
171
 
@@ -105,5 +105,3 @@ class ZabbixApi
105
105
  end
106
106
 
107
107
  end
108
-
109
-
@@ -14,7 +14,6 @@ class ZabbixApi
14
14
  end
15
15
 
16
16
  def method_name
17
-
18
17
  end
19
18
 
20
19
  end
@@ -6,7 +6,7 @@ class ZabbixApi
6
6
  end
7
7
 
8
8
  def method_name
9
- raise "Can't call method_name here"
9
+ raise ApiError.new("Can't call method_name here")
10
10
  end
11
11
 
12
12
  def default_options
@@ -22,7 +22,7 @@ class ZabbixApi
22
22
  end
23
23
 
24
24
  def indentify
25
- raise "Can't call indentify here"
25
+ raise ApiError.new("Can't call indentify here")
26
26
  end
27
27
 
28
28
  end
@@ -1,6 +1,21 @@
1
1
  class ZabbixApi
2
2
 
3
3
  class BaseError < RuntimeError
4
+ attr_accessor :response, :error, :error_message
5
+
6
+ def initialize(message, response = nil)
7
+ super(message)
8
+ @response = response
9
+
10
+ set_error! if @response
11
+ end
12
+
13
+ private
14
+
15
+ def set_error!
16
+ @error = @response["error"] rescue nil
17
+ @error_message = "#{@error['message']}: #{@error['data']}" rescue nil
18
+ end
4
19
  end
5
20
 
6
21
  class ApiError < BaseError
@@ -9,7 +24,4 @@ class ZabbixApi
9
24
  class HttpError < BaseError
10
25
  end
11
26
 
12
- class SocketError < BaseError
13
- end
14
-
15
- end
27
+ end
@@ -9,17 +9,17 @@ class ZabbixApi
9
9
  "description"
10
10
  end
11
11
 
12
- def default_options
12
+ def default_options
13
13
  {
14
14
  :description => "", #Name
15
- :type => 0, #0 - Email, 1 - External script, 2 - SMS, 3 - Jabber, 100 - EzTexting
16
- :smtp_server => "",
15
+ :type => 0, #0 - Email, 1 - External script, 2 - SMS, 3 - Jabber, 100 - EzTexting
16
+ :smtp_server => "",
17
17
  :smtp_helo => "",
18
18
  :smtp_email => "", #Email address of Zabbix server
19
- :exec_path => "", #Name of external script
20
- :gsm_modem => "", #Serial device name of GSM modem
21
- :username => "", #Jabber user name used by Zabbix server
22
- :passwd => "" #Jabber password used by Zabbix server
19
+ :exec_path => "", #Name of external script
20
+ :gsm_modem => "", #Serial device name of GSM modem
21
+ :username => "", #Jabber user name used by Zabbix server
22
+ :passwd => "" #Jabber password used by Zabbix server
23
23
  }
24
24
  end
25
25
 
@@ -17,7 +17,7 @@ class ZabbixApi
17
17
  def isreadable(data)
18
18
  result = @client.api_request(:method => "proxy.isreadable", :params => data)
19
19
  end
20
-
20
+
21
21
  def iswritable(data)
22
22
  result = @client.api_request(:method => "proxy.iswritable", :params => data)
23
23
  end
@@ -21,8 +21,8 @@ class ZabbixApi
21
21
  result.empty? ? nil : result['templateids'][0].to_i
22
22
  end
23
23
 
24
- # Return templateids linked with host
25
- #
24
+ # Return templateids linked with host
25
+ #
26
26
  # * *Args* :
27
27
  # - +data+ -> Hash with :hostids => [hostid]
28
28
  # * *Returns* :
@@ -36,7 +36,7 @@ class ZabbixApi
36
36
  end
37
37
 
38
38
  # Return templateid
39
- #
39
+ #
40
40
  # * *Args* :
41
41
  # - +data+ -> Hash with :host => "Template_Name" and :groups => array with hostgroup ids
42
42
  # * *Returns* :
@@ -46,17 +46,17 @@ class ZabbixApi
46
46
  templateid = create(data)
47
47
  end
48
48
  templateid
49
- end
49
+ end
50
50
 
51
51
  # Analog Zabbix api call massUpdate
52
- #
52
+ #
53
53
  # * *Args* :
54
54
  # - +data+ -> Hash with :hosts_id => [hostid1, hostid2 ...], and :templates_id => [templateid1, templateid2 ...]
55
55
  # * *Returns* :
56
56
  # - True or False
57
57
  def mass_update(data)
58
58
  result = @client.api_request(
59
- :method => "template.massUpdate",
59
+ :method => "template.massUpdate",
60
60
  :params => {
61
61
  :hosts => data[:hosts_id].map { |t| {:hostid => t} },
62
62
  :templates => data[:templates_id].map { |t| {:templateid => t} }
@@ -65,15 +65,15 @@ class ZabbixApi
65
65
  result.empty? ? false : true
66
66
  end
67
67
 
68
- # Analog Zabbix api call massAdd
69
- #
68
+ # Analog Zabbix api call massAdd
69
+ #
70
70
  # * *Args* :
71
71
  # - +data+ -> Hash with :hosts_id => [hostid1, hostid2 ...], and :templates_id => [templateid1, templateid2 ...]
72
72
  # * *Returns* :
73
73
  # - True or False
74
74
  def mass_add(data)
75
75
  result = @client.api_request(
76
- :method => "template.massAdd",
76
+ :method => "template.massAdd",
77
77
  :params => {
78
78
  :hosts => data[:hosts_id].map { |t| {:hostid => t} },
79
79
  :templates => data[:templates_id].map { |t| {:templateid => t} }
@@ -14,7 +14,7 @@ class ZabbixApi
14
14
  end
15
15
 
16
16
  # Return usrgrpid
17
- #
17
+ #
18
18
  # * *Args* :
19
19
  # - +data+ -> Hash with :name => "UserGroup"
20
20
  # * *Returns* :
@@ -28,15 +28,15 @@ class ZabbixApi
28
28
  end
29
29
 
30
30
  # Set permission for usrgrp on some hostgroup
31
- #
31
+ #
32
32
  # * *Args* :
33
33
  # - +data+ -> Hash with :usrgrpids => id, :hostgroupids => [], :permission => 2,3 (read and read write)
34
34
  # * *Returns* :
35
35
  # - Integer
36
36
  def set_perms(data)
37
- permission = data[:permission] || 2
37
+ permission = data[:permission] || 2
38
38
  result = @client.api_request(
39
- :method => "usergroup.massAdd",
39
+ :method => "usergroup.massAdd",
40
40
  :params => {
41
41
  :usrgrpids => [data[:usrgrpid]],
42
42
  :rights => data[:hostgroupids].map { |t| {:permission => permission, :id => t} }
@@ -46,14 +46,14 @@ class ZabbixApi
46
46
  end
47
47
 
48
48
  # Update usergroup, add user
49
- #
49
+ #
50
50
  # * *Args* :
51
51
  # - +data+ -> Hash with :usrgrpids => id, :userids => []
52
52
  # * *Returns* :
53
53
  # - Integer
54
54
  def add_user(data)
55
55
  result = @client.api_request(
56
- :method => "usergroup.massAdd",
56
+ :method => "usergroup.massAdd",
57
57
  :params => {
58
58
  :usrgrpids => data[:usrgrpids],
59
59
  :userids => data[:userids]
@@ -63,14 +63,14 @@ class ZabbixApi
63
63
  end
64
64
 
65
65
  # Update usergroup, modify users
66
- #
66
+ #
67
67
  # * *Args* :
68
68
  # - +data+ -> Hash with :usrgrpids => id, :userids => []
69
69
  # * *Returns* :
70
70
  # - Integer
71
71
  def update_users(data)
72
72
  result = @client.api_request(
73
- :method => "usergroup.massUpdate",
73
+ :method => "usergroup.massUpdate",
74
74
  :params => {
75
75
  :usrgrpids => data[:usrgrpids],
76
76
  :userids => data[:userids]
@@ -9,7 +9,7 @@ class ZabbixApi
9
9
  "userids"
10
10
  end
11
11
 
12
- def key
12
+ def key
13
13
  "userid"
14
14
  end
15
15
 
@@ -19,8 +19,8 @@ class ZabbixApi
19
19
  api_request(
20
20
  :method => 'user.login',
21
21
  :params => {
22
- :user => @options[:user],
23
- :password => @options[:password],
22
+ :user => @options[:user],
23
+ :password => @options[:password],
24
24
  }
25
25
  )
26
26
  end
@@ -34,7 +34,7 @@ class ZabbixApi
34
34
  @proxy_user, @proxy_pass = @proxy_uri.userinfo.split(/:/) if @proxy_uri.userinfo
35
35
  end
36
36
  unless api_version =~ /2\.4\.\d+/
37
- raise "Zabbix API version: #{api_version} is not support by this version of zabbixapi"
37
+ raise ApiError.new("Zabbix API version: #{api_version} is not support by this version of zabbixapi")
38
38
  end
39
39
  @auth_hash = auth
40
40
  end
@@ -55,7 +55,7 @@ class ZabbixApi
55
55
  def http_request(body)
56
56
  uri = URI.parse(@options[:url])
57
57
  # set the time out the default (60) or to what the user passed
58
- @options[:timeout] == nil ? timeout = 60 : timeout = @options[:timeout]
58
+ @options[:timeout] == nil ? timeout = 60 : timeout = @options[:timeout]
59
59
  puts "[DEBUG] Timeout for request set to #{timeout} seconds" if @options[:debug]
60
60
 
61
61
  unless @proxy_uri.nil?
@@ -79,7 +79,7 @@ class ZabbixApi
79
79
  request.add_field('Content-Type', 'application/json-rpc')
80
80
  request.body = body
81
81
  response = http.request(request)
82
- raise "HTTP Error: #{response.code} on #{@options[:url]}" unless response.code == "200"
82
+ raise HttpError.new("HTTP Error: #{response.code} on #{@options[:url]}", response) unless response.code == '200'
83
83
  puts "[DEBUG] Get answer: #{response.body}" if @options[:debug]
84
84
  response.body
85
85
  end
@@ -87,7 +87,7 @@ class ZabbixApi
87
87
  def _request(body)
88
88
  puts "[DEBUG] Send request: #{body}" if @options[:debug]
89
89
  result = JSON.parse(http_request(body))
90
- raise "Server answer API error:\n #{JSON.pretty_unparse(result['error'])}\n on request:\n #{JSON.pretty_unparse(JSON.parse(body))}" if result['error']
90
+ raise ApiError.new("Server answer API error\n #{JSON.pretty_unparse(result['error'])}\n on request:\n #{JSON.pretty_unparse(JSON.parse(body))}", result) if result['error']
91
91
  result['result']
92
92
  end
93
93
 
@@ -97,4 +97,3 @@ class ZabbixApi
97
97
 
98
98
  end
99
99
  end
100
-
@@ -1,3 +1,3 @@
1
1
  class ZabbixApi
2
- VERSION = "2.4.4"
2
+ VERSION = "2.4.5"
3
3
  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: 2.4.4
4
+ version: 2.4.5
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: 2015-06-23 00:00:00.000000000 Z
12
+ date: 2015-09-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json