Closed bilbolodz closed 1 year ago
I think the current api of pyzabbix is a bit misleading, there a a few methods/properties to check whether you are authenticated, but they always return True if you use an api token, which I think can be misleading.
You can try to call this endpoint with your token to check whether your token is valid: https://www.zabbix.com/documentation/current/en/manual/api/reference/user/checkauthentication
As an (ugly) workaround, I did my implementations like this:
success = False
try:
with ZabbixAPI(zabbixurl) as zapi:
zapi.login(zabbixuser, zabbixpw)
print("Connected and logged in to Zabbix API Version %s" % zapi.api_version())
...
success = True
except Exception as e:
sys.stderr.write("%s\n" % e)
...
finally:
if not success:
sys.stderr.write("Errror (probably Zabbiy auth error)\n")
...
How to detect that provided credentials used to login to API are wrong? It looks that:
zapi.login(api_token=zabbix_api_token)
always return None regardless credentials are good or wrong