zbxapi 0.1.292 → 0.1.294
Sign up to get free protection for your applications and to get access to all the features.
- data/zbxapi.rb +19 -14
- metadata +3 -3
data/zbxapi.rb
CHANGED
@@ -19,8 +19,8 @@
|
|
19
19
|
#--
|
20
20
|
##########################################
|
21
21
|
# Subversion information
|
22
|
-
# $Id: zbxapi.rb
|
23
|
-
# $Revision:
|
22
|
+
# $Id: zbxapi.rb 294 2011-07-08 08:27:45Z nelsonab $
|
23
|
+
# $Revision: 294 $
|
24
24
|
##########################################
|
25
25
|
#++
|
26
26
|
|
@@ -144,8 +144,6 @@ class ZabbixAPI
|
|
144
144
|
# 1. The url used to create the class was bad
|
145
145
|
# 1. The connection to the server was refused
|
146
146
|
def login(user='',password='',save=true)
|
147
|
-
# p user.class
|
148
|
-
# p password.class
|
149
147
|
if user.class!=String or password.class!=String
|
150
148
|
raise ZbxAPI_ExceptionBadAuth.new,'Login called with non-string values'
|
151
149
|
end
|
@@ -159,35 +157,42 @@ class ZabbixAPI
|
|
159
157
|
elsif (@user_name!='' and @password!='') then
|
160
158
|
l_user = @user_name
|
161
159
|
l_password = @password
|
162
|
-
else
|
163
|
-
|
164
160
|
end
|
165
161
|
|
162
|
+
#Somewhere in the 1.8.x cycle it was decided to do deprecate with user.authenticate
|
163
|
+
#however it was not documented well, so we will try uer.login first, and fall
|
164
|
+
#back to user.authenticate as user.login does not exist in 1.8.3
|
165
|
+
login_methods=["user.login","user.authenticate"]
|
166
|
+
|
166
167
|
begin
|
167
|
-
result = do_request(json_obj(
|
168
|
+
result = do_request(json_obj(login_methods.first,{'user'=>l_user,'password'=>l_password}))
|
168
169
|
@auth=result['result']
|
169
170
|
|
170
171
|
#setup the version variables
|
171
172
|
@major,@minor=do_request(json_obj('APIInfo.version',{}))['result'].split('.')
|
172
173
|
@major=@major.to_i
|
173
174
|
@minor=@minor.to_i
|
174
|
-
|
175
|
+
rescue ZbxAPI_ExceptionLoginPermission => e
|
176
|
+
login_methods.delete_at(0)
|
177
|
+
if !login_methods.empty?
|
178
|
+
retry
|
179
|
+
else
|
180
|
+
raise e
|
181
|
+
end
|
175
182
|
rescue SocketError
|
176
183
|
raise ZbxAPI_ExceptionBadServerUrl
|
177
184
|
rescue JSON::ParserError
|
178
185
|
raise ZbxAPI_ExceptionBadServerUrl
|
179
186
|
rescue Errno::ECONNREFUSED
|
180
187
|
raise ZbxAPI_ExceptionBadServerUrl
|
181
|
-
rescue ZbxAPI_GeneralError => e
|
182
|
-
if e.message["code"]==-32602
|
183
|
-
raise ZbxAPI_ExceptionBadAuth,'Bad username and/or password'
|
184
|
-
else
|
185
|
-
raise e
|
186
|
-
end
|
187
188
|
end
|
188
189
|
|
189
190
|
end
|
190
191
|
|
192
|
+
def logout
|
193
|
+
do_request(json_obj('user.logout'))
|
194
|
+
end
|
195
|
+
|
191
196
|
# Tests to determine if the login information is still valid
|
192
197
|
# returns: true if it is valid or false if it is not.
|
193
198
|
def test_login
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zbxapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 599
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 294
|
10
|
+
version: 0.1.294
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- A. Nelson
|