summaryrefslogtreecommitdiffstats
path: root/ansible_collections/community/zabbix/plugins/module_utils
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-18 05:52:22 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-18 05:52:22 +0000
commit38b7c80217c4e72b1d8988eb1e60bb6e77334114 (patch)
tree356e9fd3762877d07cde52d21e77070aeff7e789 /ansible_collections/community/zabbix/plugins/module_utils
parentAdding upstream version 7.7.0+dfsg. (diff)
downloadansible-38b7c80217c4e72b1d8988eb1e60bb6e77334114.tar.xz
ansible-38b7c80217c4e72b1d8988eb1e60bb6e77334114.zip
Adding upstream version 9.4.0+dfsg.upstream/9.4.0+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ansible_collections/community/zabbix/plugins/module_utils')
-rw-r--r--ansible_collections/community/zabbix/plugins/module_utils/api_request.py2
-rw-r--r--ansible_collections/community/zabbix/plugins/module_utils/base.py17
-rw-r--r--ansible_collections/community/zabbix/plugins/module_utils/helpers.py35
-rw-r--r--ansible_collections/community/zabbix/plugins/module_utils/wrappers.py84
4 files changed, 4 insertions, 134 deletions
diff --git a/ansible_collections/community/zabbix/plugins/module_utils/api_request.py b/ansible_collections/community/zabbix/plugins/module_utils/api_request.py
index a29f492de..18b588e17 100644
--- a/ansible_collections/community/zabbix/plugins/module_utils/api_request.py
+++ b/ansible_collections/community/zabbix/plugins/module_utils/api_request.py
@@ -12,7 +12,7 @@ __metaclass__ = type
from uuid import uuid4
-from ansible.module_utils.urls import CertificateError
+from ssl import CertificateError
from ansible.module_utils.connection import ConnectionError
from ansible.module_utils.connection import Connection
from ansible.module_utils._text import to_text
diff --git a/ansible_collections/community/zabbix/plugins/module_utils/base.py b/ansible_collections/community/zabbix/plugins/module_utils/base.py
index 8858a02e1..a1c73291e 100644
--- a/ansible_collections/community/zabbix/plugins/module_utils/base.py
+++ b/ansible_collections/community/zabbix/plugins/module_utils/base.py
@@ -7,7 +7,6 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type
-from ansible_collections.community.zabbix.plugins.module_utils.wrappers import ZapiWrapper
from ansible_collections.community.zabbix.plugins.module_utils.api_request import ZabbixApiRequest
@@ -17,17 +16,5 @@ class ZabbixBase(object):
"""
def __init__(self, module, zbx=None, zapi_wrapper=None):
self._module = module
-
- if module._socket_path is None:
- # ansible_connection = local
- if zapi_wrapper is None:
- self._zapi_wrapper = ZapiWrapper(module, zbx)
- else:
- self._zapi_wrapper = zapi_wrapper
-
- self._zapi = self._zapi_wrapper._zapi
- self._zbx_api_version = self._zapi_wrapper._zbx_api_version
- else:
- # ansible_connection = httpapi
- self._zapi = ZabbixApiRequest(module)
- self._zbx_api_version = self._zapi.api_version()
+ self._zapi = ZabbixApiRequest(module)
+ self._zbx_api_version = self._zapi.api_version()
diff --git a/ansible_collections/community/zabbix/plugins/module_utils/helpers.py b/ansible_collections/community/zabbix/plugins/module_utils/helpers.py
index 6c9c0fca5..87e0c0925 100644
--- a/ansible_collections/community/zabbix/plugins/module_utils/helpers.py
+++ b/ansible_collections/community/zabbix/plugins/module_utils/helpers.py
@@ -7,15 +7,6 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type
-from ansible.module_utils.basic import env_fallback
-
-
-def require_creds_params(module):
- if module._socket_path is None:
- # ansible_connection = local
- if ((not module.params.get('server_url', None)) or (not module.params.get('login_user', None)) or (not module.params.get('login_password', None))):
- module.fail_json(msg="server_url, login_user, login_password are mandatory parameters when httpapi connection is not used")
-
def zabbix_common_argument_spec():
"""
@@ -23,22 +14,6 @@ def zabbix_common_argument_spec():
The options are commonly used by most of Zabbix modules.
"""
return dict(
- server_url=dict(
- type='str',
- required=False,
- aliases=['url'],
- fallback=(env_fallback, ['ZABBIX_SERVER'])
- ),
- login_user=dict(
- type='str', required=False,
- fallback=(env_fallback, ['ZABBIX_USERNAME'])
- ),
- login_password=dict(
- type='str',
- required=False,
- no_log=True,
- fallback=(env_fallback, ['ZABBIX_PASSWORD'])
- ),
http_login_user=dict(
type='str',
required=False,
@@ -49,15 +24,7 @@ def zabbix_common_argument_spec():
required=False,
default=None,
no_log=True
- ),
- timeout=dict(
- type='int'
- ),
- validate_certs=dict(
- type='bool',
- required=False,
- fallback=(env_fallback, ['ZABBIX_VALIDATE_CERTS'])
- ),
+ )
)
diff --git a/ansible_collections/community/zabbix/plugins/module_utils/wrappers.py b/ansible_collections/community/zabbix/plugins/module_utils/wrappers.py
deleted file mode 100644
index a982108f8..000000000
--- a/ansible_collections/community/zabbix/plugins/module_utils/wrappers.py
+++ /dev/null
@@ -1,84 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
-
-from __future__ import absolute_import, division, print_function
-__metaclass__ = type
-
-import atexit
-import traceback
-
-from ansible.module_utils.basic import missing_required_lib
-
-try:
- from zabbix_api import ZabbixAPI, Already_Exists, ZabbixAPIException
-
- HAS_ZABBIX_API = True
- ZBX_IMP_ERR = Exception()
-except ImportError:
- ZBX_IMP_ERR = traceback.format_exc()
- HAS_ZABBIX_API = False
-
-
-class ZapiWrapper(object):
- """
- A simple wrapper over the Zabbix API
- """
- def __init__(self, module, zbx=None):
- self._module = module
-
- if not HAS_ZABBIX_API:
- module.fail_json(msg=missing_required_lib('zabbix-api', url='https://pypi.org/project/zabbix-api/'), exception=ZBX_IMP_ERR)
-
- # check if zbx is already instantiated or not
- if zbx is not None and isinstance(zbx, ZabbixAPI):
- self._zapi = zbx
- else:
- server_url = module.params['server_url']
-
- if module.params['validate_certs'] is None:
- validate_certs = True
- else:
- validate_certs = module.params['validate_certs']
-
- if module.params['timeout'] is None:
- timeout = 10
- else:
- timeout = module.params['timeout']
-
- self._zapi = ZabbixAPI(server_url, timeout=timeout, validate_certs=validate_certs)
-
- self.login()
-
- self._zbx_api_version = self._zapi.api_version()
-
- def login(self):
- # check if api already logged in
- if not self._zapi.auth != '':
- try:
- login_user = self._module.params['login_user']
- login_password = self._module.params['login_password']
- self._zapi.login(login_user, login_password)
- atexit.register(self._zapi.logout)
- except Exception as e:
- self._module.fail_json(msg="Failed to connect to Zabbix server: %s" % e)
-
-
-class ScreenItem(object):
- @staticmethod
- def create(zapi_wrapper, data, ignoreExists=False):
- try:
- zapi_wrapper._zapi.screenitem.create(data)
- except Already_Exists as ex:
- if not ignoreExists:
- raise ex
-
- @staticmethod
- def delete(zapi_wrapper, id_list=None):
- try:
- if id_list is None:
- id_list = []
- zapi_wrapper._zapi.screenitem.delete(id_list)
- except ZabbixAPIException as ex:
- raise ex