Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize with authtoken #133

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pyzabbix/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ class ZabbixAPI(object):
:param password: Zabbix user password. Default `ZABBIX_PASSWORD` or
`zabbix`.

:type authtoken: str
:param authtoken: Zabbix authtoken - pre-generated from user/password

>>> from pyzabbix import ZabbixAPI
>>> z = ZabbixAPI('https://zabbix.server', user='Admin', password='zabbix')
>>> # Get API Version
Expand All @@ -166,7 +169,7 @@ class ZabbixAPI(object):
"""

def __init__(self, url=None, use_authenticate=False, use_basic_auth=False, user=None,
password=None):
password=None, authtoken=None):

url = url or os.environ.get('ZABBIX_URL') or 'https://localhost/zabbix'
user = user or os.environ.get('ZABBIX_USER') or 'Admin'
Expand All @@ -177,7 +180,10 @@ def __init__(self, url=None, use_authenticate=False, use_basic_auth=False, user=
self.auth = None
self.url = url + '/api_jsonrpc.php'
self.base64_cred = self.cred_to_base64(user, password) if self.use_basic_auth else None
self._login(user, password)
if authtoken:
self.auth = authtoken
else:
self._login(user, password)
logger.debug("JSON-PRC Server: %s", self.url)

def __getattr__(self, name):
Expand Down