py-zabbix icon indicating copy to clipboard operation
py-zabbix copied to clipboard

support to new auth token

Open pariseed opened this issue 3 years ago • 8 comments

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

pariseed avatar Jun 08 '21 15:06 pariseed

+1

anshibanov avatar Jun 29 '21 10:06 anshibanov

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

HuiMi24 avatar Sep 22 '21 01:09 HuiMi24

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

ByteDSM avatar Nov 05 '21 04:11 ByteDSM

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"

HuiMi24 avatar Nov 18 '21 08:11 HuiMi24

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?

xterms013 avatar Jan 10 '22 12:01 xterms013

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)

jnunezgts avatar Feb 18 '22 22:02 jnunezgts

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 avatar Apr 09 '24 10:04 gdeleon23

@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

pariseed avatar Apr 09 '24 14:04 pariseed