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

update/zabbix-api-params-changed-in-v6 #155

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
18 changes: 7 additions & 11 deletions pyzabbix/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import ssl
import sys
import base64
from packaging.version import Version

# For Python 2 and 3 compatibility
try:
Expand Down Expand Up @@ -137,10 +138,6 @@ class ZabbixAPI(object):
:param url: URL to zabbix api. Default: `ZABBIX_URL` or
`https://localhost/zabbix`

:type use_authenticate: bool
:param use_authenticate: Use `user.authenticate` method if `True` else
`user.login`.

:type use_basic_auth: bool
:param use_basic_auth: Using basic auth if `True`

Expand All @@ -165,14 +162,12 @@ class ZabbixAPI(object):
>>> z.do_request('host.getobjects', {'status': 1})
"""

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

url = url or os.environ.get('ZABBIX_URL') or 'https://localhost/zabbix'
user = user or os.environ.get('ZABBIX_USER') or 'Admin'
password = password or os.environ.get('ZABBIX_PASSWORD') or 'zabbix'

self.use_authenticate = use_authenticate
self.use_basic_auth = use_basic_auth
self.auth = None
self.url = url + '/api_jsonrpc.php'
Expand Down Expand Up @@ -202,12 +197,13 @@ def _login(self, user='', password=''):

logger.debug("ZabbixAPI.login({0},{1})".format(user, HideSensitiveService.HIDEMASK))

self.auth = None
api_version = Version(self.apiinfo.version())

if self.use_authenticate:
self.auth = self.user.authenticate(user=user, password=password)
else:
# 5.4.0 was the first version of Zabbix to change the user param in the login method
if api_version and api_version < Version("5.4.0"):
self.auth = self.user.login(user=user, password=password)
else:
self.auth = self.user.login(username=user, password=password)

def _logout(self):
"""Do logout from zabbix server."""
Expand Down
2 changes: 1 addition & 1 deletion pyzabbix/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.1.7'
__version__ = '1.1.8'
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env python
import pip
pip.main(['install', 'packaging'])
from setuptools import setup
from pyzabbix.version import __version__

Expand Down