From 3b3fa7006318982d3a2546434829113af71f5a17 Mon Sep 17 00:00:00 2001 From: John Schoewe Date: Tue, 6 Jun 2023 11:07:55 -0400 Subject: [PATCH 1/4] Updated user.login method parameter to match updates made in version 6 and removed user.authenticate method that has been deprecated since version 2 --- pyzabbix/api.py | 15 ++------------- pyzabbix/version.py | 2 +- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/pyzabbix/api.py b/pyzabbix/api.py index d1daf26..bb5356c 100644 --- a/pyzabbix/api.py +++ b/pyzabbix/api.py @@ -137,10 +137,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` @@ -165,14 +161,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' @@ -202,12 +196,7 @@ def _login(self, user='', password=''): logger.debug("ZabbixAPI.login({0},{1})".format(user, HideSensitiveService.HIDEMASK)) - self.auth = None - - if self.use_authenticate: - self.auth = self.user.authenticate(user=user, password=password) - else: - self.auth = self.user.login(user=user, password=password) + self.auth = self.user.login(username=user, password=password) def _logout(self): """Do logout from zabbix server.""" diff --git a/pyzabbix/version.py b/pyzabbix/version.py index 9910ac2..f0be139 100644 --- a/pyzabbix/version.py +++ b/pyzabbix/version.py @@ -1 +1 @@ -__version__ = '1.1.7' +__version__ = '1.1.8' From 55f40f4bcc0fcd45fe1ec909abc92c80c30cc2f0 Mon Sep 17 00:00:00 2001 From: John Schoewe Date: Tue, 6 Jun 2023 16:01:23 -0400 Subject: [PATCH 2/4] Added version check so login works with previous versions --- pyzabbix/api.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pyzabbix/api.py b/pyzabbix/api.py index bb5356c..fa92b32 100644 --- a/pyzabbix/api.py +++ b/pyzabbix/api.py @@ -23,6 +23,7 @@ import ssl import sys import base64 +from packaging.version import Version # For Python 2 and 3 compatibility try: @@ -196,7 +197,13 @@ def _login(self, user='', password=''): logger.debug("ZabbixAPI.login({0},{1})".format(user, HideSensitiveService.HIDEMASK)) - self.auth = self.user.login(username=user, password=password) + api_version = Version(self.apiinfo.version()) + + # 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.""" From 1b91cff9849acbabe15fc5ede4e857547dba0680 Mon Sep 17 00:00:00 2001 From: John Schoewe Date: Wed, 8 Nov 2023 14:45:17 -0500 Subject: [PATCH 3/4] Added dependency to install with module --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index e7fc218..159b366 100644 --- a/setup.py +++ b/setup.py @@ -12,6 +12,7 @@ author_email='alexey.dubkov@gmail.com', test_suite='tests', packages=['pyzabbix', 'zabbix'], + install_requires=['packaging'], tests_require=['mock'], classifiers=[ 'Development Status :: 5 - Production/Stable', From 3aa24dee91b6da0cd50aa16f83796792db46e652 Mon Sep 17 00:00:00 2001 From: John Schoewe Date: Wed, 8 Nov 2023 15:12:29 -0500 Subject: [PATCH 4/4] Testing py-zabbix package install --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 159b366..b74d867 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,6 @@ #!/usr/bin/env python +import pip +pip.main(['install', 'packaging']) from setuptools import setup from pyzabbix.version import __version__ @@ -12,7 +14,6 @@ author_email='alexey.dubkov@gmail.com', test_suite='tests', packages=['pyzabbix', 'zabbix'], - install_requires=['packaging'], tests_require=['mock'], classifiers=[ 'Development Status :: 5 - Production/Stable',