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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user