You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
for information
i found that the pyzabbix project is like your py-zabbix project
creates a pyzabbix library and works with it.
when installing both, api.py is overwritten
I propose to modify to support zabbix 6.4
remove the login from the init function, make it in the login procedure
I attach the source:
import json
import logging
import os
import ssl
import sys
import base64
from packaging.version import Version
For Python 2 and 3 compatibility
try:
import urllib2
except ImportError:
# Since Python 3, urllib2.Request and urlopen were moved to
# the urllib.request.
import urllib.request as urllib2
from .version import version
from .logger import NullHandler, HideSensitiveFilter, HideSensitiveService
class ZabbixAPIObjectClass(object):
"""ZabbixAPI Object class.
:type group: str
:param group: Zabbix API method group name.
Example: `apiinfo.version` method it will be `apiinfo`.
:type parent: :class:`zabbix.api.ZabbixAPI` object
:param parent: ZabbixAPI object to use as parent.
"""
def __init__(self, group, parent):
self.group = group
self.parent = parent
def __getattr__(self, name):
"""Dynamically create a method.
:type name: str
:param name: Zabbix API method name.
Example: `apiinfo.version` method it will be `version`.
"""
def fn(*args, **kwargs):
if args and kwargs:
raise TypeError("Found both args and kwargs")
method = '{0}.{1}'.format(self.group, name)
logger.debug("Call %s method", method)
return self.parent.do_request(
method,
args or kwargs
)['result']
return fn
def ssl_context_compat(func):
def inner(req):
# We should explicitly disable cert verification to support
# self-signed certs with urllib2 since Python 2.7.9 and 3.4.3
default_version = (2, 7, 9)
version = {
2: default_version,
3: (3, 4, 3),
}
python_version = sys.version_info[0]
minimum_version = version.get(python_version, default_version)
if sys.version_info[0:3] >= minimum_version:
# Create default context to skip SSL cert verification.
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
res = func(req, context=ctx)
else:
res = func(req)
return res
return inner
for information
i found that the pyzabbix project is like your py-zabbix project
creates a pyzabbix library and works with it.
when installing both, api.py is overwritten
I propose to modify to support zabbix 6.4
I attach the source:
-- encoding: utf-8 --
Copyright © 2014 Alexey Dubkov
This file is part of py-zabbix.
Py-zabbix is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Py-zabbix is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with py-zabbix. If not, see http://www.gnu.org/licenses/.
import json
import logging
import os
import ssl
import sys
import base64
from packaging.version import Version
For Python 2 and 3 compatibility
try:
import urllib2
except ImportError:
# Since Python 3, urllib2.Request and urlopen were moved to
# the urllib.request.
import urllib.request as urllib2
from .version import version
from .logger import NullHandler, HideSensitiveFilter, HideSensitiveService
null_handler = NullHandler()
logger = logging.getLogger(name)
logger.addHandler(null_handler)
logger.addFilter(HideSensitiveFilter())
class ZabbixAPIException(Exception):
"""ZabbixAPI exception class.
class ZabbixAPIObjectClass(object):
"""ZabbixAPI Object class.
def ssl_context_compat(func):
def inner(req):
# We should explicitly disable cert verification to support
# self-signed certs with urllib2 since Python 2.7.9 and 3.4.3
@ssl_context_compat
def urlopen(*args, **kwargs):
return urllib2.urlopen(*args, **kwargs)
class ZabbixAPI(object):
"""ZabbixAPI class, implement interface to zabbix api.
user = user or os.environ.get('ZABBIX_USER') or 'Admin'
password = password or os.environ.get('ZABBIX_PASSWORD') or 'zabbix'
if self.use_authenticate:
self.auth = self.user.authenticate(user=user, password=password)
else:
self.auth = self.user.login(user=user, password=password)
The text was updated successfully, but these errors were encountered: