mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-07 08:54:01 -07:00
Add option to use ZabbixApi via auth basic protection
This commit is contained in:
parent
5f9d5c1403
commit
5d68e4fe06
5 changed files with 97 additions and 9 deletions
|
@ -48,6 +48,18 @@ options:
|
|||
description:
|
||||
- Zabbix user password.
|
||||
required: true
|
||||
http_login_user:
|
||||
description:
|
||||
- Basic Auth login
|
||||
required: false
|
||||
default: None
|
||||
version_added: "2.1"
|
||||
http_login_password:
|
||||
description:
|
||||
- Basic Auth password
|
||||
required: false
|
||||
default: None
|
||||
version_added: "2.1"
|
||||
timeout:
|
||||
description:
|
||||
- The timeout of API request (seconds).
|
||||
|
@ -142,8 +154,8 @@ except ImportError:
|
|||
class ZabbixAPIExtends(ZabbixAPI):
|
||||
screenitem = None
|
||||
|
||||
def __init__(self, server, timeout, **kwargs):
|
||||
ZabbixAPI.__init__(self, server, timeout=timeout)
|
||||
def __init__(self, server, timeout, user, passwd, **kwargs):
|
||||
ZabbixAPI.__init__(self, server, timeout=timeout, user=user, passwd=passwd)
|
||||
self.screenitem = ZabbixAPISubClass(self, dict({"prefix": "screenitem"}, **kwargs))
|
||||
|
||||
|
||||
|
@ -318,6 +330,8 @@ def main():
|
|||
server_url=dict(type='str', required=True, aliases=['url']),
|
||||
login_user=dict(type='str', required=True),
|
||||
login_password=dict(type='str', required=True, no_log=True),
|
||||
http_login_user=dict(type='str', required=False, default=None),
|
||||
http_login_password=dict(type='str', required=False, default=None, no_log=True),
|
||||
timeout=dict(type='int', default=10),
|
||||
screens=dict(type='list', required=True)
|
||||
),
|
||||
|
@ -330,13 +344,15 @@ def main():
|
|||
server_url = module.params['server_url']
|
||||
login_user = module.params['login_user']
|
||||
login_password = module.params['login_password']
|
||||
http_login_user = module.params['http_login_user']
|
||||
http_login_password = module.params['http_login_password']
|
||||
timeout = module.params['timeout']
|
||||
screens = module.params['screens']
|
||||
|
||||
zbx = None
|
||||
# login to zabbix
|
||||
try:
|
||||
zbx = ZabbixAPIExtends(server_url, timeout=timeout)
|
||||
zbx = ZabbixAPIExtends(server_url, timeout=timeout, user=http_login_user, passwd=http_login_password)
|
||||
zbx.login(login_user, login_password)
|
||||
except Exception, e:
|
||||
module.fail_json(msg="Failed to connect to Zabbix server: %s" % e)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue