intellitrend / zabbixapi-php

Zabbix API client for PHP with session cache and SSL management
GNU Lesser General Public License v3.0
56 stars 10 forks source link

down or invalid host does not trigger an exception #3

Closed leo-combes closed 3 years ago

leo-combes commented 4 years ago

Hi! I'm testing your API and is impressive, good work. It seems that if you call login with incorrect, invalid or down host server, it not trigger any exception. Only error is visible in debug messages, but no error catched. Example with non existent server: $zbx->login("http://10.1.1.56/zabbix", "testuser", "test123", $options); Debug messages are:

DBG login(). Using zabUser:testuser, zabUrl:http://10.1.1.56/zabbix/
DBG login(). Using sslVerifyPeer:0 sslVerifyHost:0 useGzip:1 timeout:30 connectTimeout:10
DBG login(). Using sessionDir:/tmp, sessionFileName:zbx_7f21a15109b82247fa66b01edc43d221
DBG readAuthKeyFromSession(). sessionFile not found. sessionFile:/tmp/zbx_7f21a15109b82247fa66b01edc43d221
DBG __login(). Called
DBG executeRequest(). CURL Params: {"method":"user.login","id":1,"params":{"password":"test123","user":"testuser"},"jsonrpc":"2.0"}
{"error":1,"values":null,"errorDetail":"0\nRequest failed with HTTP-Code:0, sslVerifyResult:0. Connection timed out after 10001 milliseconds"}

same behavior with an invalid host, error is not triggered: $zbx->login("xxxxxxx", "testuser", "test123", $options);

DBG login(). Using zabUser:testuser, zabUrl:xxxxxxx/
DBG login(). Using sslVerifyPeer:0 sslVerifyHost:0 useGzip:1 timeout:30 connectTimeout:10
DBG login(). Using sessionDir:/tmp, sessionFileName:zbx_4a776df920e5d23028452550b583ba25
DBG readAuthKeyFromSession(). sessionFile not found. sessionFile:/tmp/zbx_4a776df920e5d23028452550b583ba25
DBG __login(). Called
DBG executeRequest(). CURL Params: {"method":"user.login","id":1,"params":{"password":"test123","user":"testuser"},"jsonrpc":"2.0"}
{"error":1,"values":null,"errorDetail":"0\nRequest failed with HTTP-Code:0, sslVerifyResult:0. Could not resolve host: xxxxxxx"}
intellitrend-team commented 3 years ago

Sorry for the late response. We cannot reproduce this issue. Timeout happens after the default value of 10sec.

Running the default example:

Zabbix API Example
 Connect to API, check certificate/hostname and get number of hosts
=====================================================
==== Exception ===
Errorcode: 0
ErrorMessage: Request failed with HTTP-Code:0, sslVerifyResult:0. Connection timed out after 10015 milliseconds

And when setting timeout to 3 seconds:

$zbx->login($zabUrl, $zabUser, $zabPassword, ['connectTimeout' => 3]);

Output as expected

Zabbix API Example
 Connect to API, check certificate/hostname and get number of hosts
=====================================================
==== Exception ===
Errorcode: 0
ErrorMessage: Request failed with HTTP-Code:0, sslVerifyResult:0. Connection timed out after 3014 milliseconds

Btw.: This code has been part of the first commit:

if ( $httpCode == 0 || $httpCode >= 400) {
            throw new Exception("Request failed with HTTP-Code:$httpCode, sslVerifyResult:$sslVerifyResult. $sslErrorMsg", $httpCode);
        }

Let us know wether this issue still exists.