Add Zabbix API token authentication support

ZABBIX_API_TOKEN env var can now be used instead of ZABBIX_USER +
ZABBIX_PASSWORD. When set, the token is passed directly as the auth
value in JSON-RPC calls and no login/logout session is created.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-17 10:07:41 +02:00
parent 7d18f20bf1
commit 2695379589
3 changed files with 14 additions and 4 deletions

View File

@@ -10,7 +10,7 @@ Each Yodeck player becomes a Zabbix host with:
import logging
import requests
from app.config import (
ZABBIX_URL, ZABBIX_USER, ZABBIX_PASSWORD,
ZABBIX_URL, ZABBIX_API_TOKEN, ZABBIX_USER, ZABBIX_PASSWORD,
ZABBIX_HOST_GROUP, ZABBIX_SNMP_COMMUNITY,
APP_HOST, ENTERPRISE_OID,
)
@@ -47,9 +47,14 @@ class ZabbixClient:
return body['result']
def login(self):
self._auth = self._call('user.login', {'user': ZABBIX_USER, 'password': ZABBIX_PASSWORD})
if ZABBIX_API_TOKEN:
self._auth = ZABBIX_API_TOKEN # API token used directly — no session needed
else:
self._auth = self._call('user.login', {'user': ZABBIX_USER, 'password': ZABBIX_PASSWORD})
def logout(self):
if ZABBIX_API_TOKEN:
return # API tokens have no session to invalidate
try:
self._call('user.logout', [])
except Exception: