Created
March 27, 2012 09:58
-
-
Save Farzy/2214522 to your computer and use it in GitHub Desktop.
zbx_api/zabcon gruik code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Somewhere in the 1.8.x cycle it was decided to do deprecate with user.authenticate | |
#however it was not documented well, so we will try uer.login first, and fall | |
#back to user.authenticate as user.login does not exist in 1.8.3 | |
login_methods=["user.login","user.authenticate"] | |
begin | |
result = do_request(json_obj(login_methods.first,{'user'=>l_user,'password'=>l_password})) | |
@auth=result['result'] | |
#setup the version variables | |
@major,@minor=do_request(json_obj('APIInfo.version',{}))['result'].split('.') | |
@[email protected]_i | |
@[email protected]_i | |
rescue ZbxAPI_ExceptionLoginPermission => e | |
login_methods.delete_at(0) | |
if !login_methods.empty? | |
retry | |
else | |
raise ZbxAPI_ExceptionBadAuth.new('Invalid User or Password',:error_code=>e.error_code) | |
end | |
rescue SocketError | |
raise ZbxAPI_ExceptionBadServerUrl | |
rescue JSON::ParserError | |
raise ZbxAPI_ExceptionBadServerUrl | |
rescue Errno::ECONNREFUSED | |
raise ZbxAPI_ExceptionBadServerUrl | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment