adubkov/py-zabbix

support to new auth token

pariseed opened this issue · 8 comments

as zabbix 5.4 introduced support for auth token, is planned to integrate this feature in this python module ?

zapi.login(api_token="xxx")
it could work with this parameter.

zapi.login(api_token="xxx")
it do not work
v. 5.4.7

zapi.login(api_token="xxx") it do not work v. 5.4.7

I'm using 5.4.4. The token generated at "Administration -> General -> API token"

Hi all! I not found support for api tokens in "/usr/local/lib/python3.8/dist-packages/pyzabbix/api.py". It seems like api tokens not supprorted now. Is planned to integrate this feature in this python module ?

Or am I wrong?

Is not supported. Actually this feature would be super useful as it will save the cost of authenticating with user and password, when you can just persist your session and reuse it (if it expired the log in again and get a new one)

Hi, i think this is fixed, i can use a token with pyzabbix in version 6.0.19
module python pyzabbix: pyzabbix==1.3.1

code of script:

import urllib3

URL='https://zabbix.xxxx.xxx'
TOKEN='xxxxxxx'

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

zapi = pyzabbix.ZabbixAPI(URL)
zapi.session.verify = False
zapi.timeout = 5.1

# check token
print("Zabbix version ( not need authentication): ", zapi.api_version())
try:
    print(zapi.user.checkAuthentication(token=TOKEN))
except ZabbixAPIException as error:
    print("Login error %s" % error)
    exit(1)
print("Login OK")
# do Login
zapi.login(api_token=TOKEN)
print(zapi.host.get(host="Zabbix server", output="host"))

Execution:

> python3 test_zabbix_token.py

Zabbix version ( not need authentication):  6.0.19

{'userid': '1', 'username': 'Admin', 'name': 'Zabbix', 'surname': 'Administrator', 'url': '', 'autologin': '1', 'autologout': '0', 'lang': 'en_US', 'refresh': '30s', 'theme': 'default', 'attempt_failed': '0', 'attempt_ip': '192.168.128.1', 'attempt_clock': '1708981804', 'rows_per_page': '50', 'timezone': 'system', 'roleid': '3', 'type': 3, 'userip': '172.31.0.1', 'debug_mode': 0, 'gui_access': 0}

Login OK

[{'hostid': '10084'}, {'hostid': '10700'}, {'hostid': '10704'}]

@gdeleon23 hey man now there's the official python module from Zabbix, no more need to use third party modules, check it out at github.com/zabbix/python-zabbix-utils