diff options
author | Julien Recurt <julien@recurt.fr> | 2016-03-25 19:00:17 +0100 |
---|---|---|
committer | Julien Recurt <julien@recurt.fr> | 2016-03-25 19:00:17 +0100 |
commit | cd1114a2bd005d0f4bd0b5e9b90d68da509553be (patch) | |
tree | 370e56f39160fd32e3657963378408f1d4adf99e /monitoring | |
parent | 6978984244bff9c2e74b0e79d8c2bf6493c9fede (diff) | |
download | ansible-modules-extras-cd1114a2bd005d0f4bd0b5e9b90d68da509553be.tar.gz |
Add option to use ZabbixApi via auth basic protection
Diffstat (limited to 'monitoring')
-rw-r--r-- | monitoring/zabbix_group.py | 18 | ||||
-rw-r--r-- | monitoring/zabbix_host.py | 22 | ||||
-rw-r--r-- | monitoring/zabbix_hostmacro.py | 18 | ||||
-rw-r--r-- | monitoring/zabbix_maintenance.py | 26 | ||||
-rw-r--r-- | monitoring/zabbix_screen.py | 22 |
5 files changed, 97 insertions, 9 deletions
diff --git a/monitoring/zabbix_group.py b/monitoring/zabbix_group.py index 4fc9631a..a19c4979 100644 --- a/monitoring/zabbix_group.py +++ b/monitoring/zabbix_group.py @@ -49,6 +49,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" state: description: - Create or delete host group. @@ -153,6 +165,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), host_groups=dict(type='list', required=True, aliases=['host_group']), state=dict(default="present", choices=['present','absent']), timeout=dict(type='int', default=10) @@ -166,6 +180,8 @@ 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'] host_groups = module.params['host_groups'] state = module.params['state'] timeout = module.params['timeout'] @@ -174,7 +190,7 @@ def main(): # login to zabbix try: - zbx = ZabbixAPI(server_url, timeout=timeout) + zbx = ZabbixAPI(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) diff --git a/monitoring/zabbix_host.py b/monitoring/zabbix_host.py index cded12b9..70d32313 100644 --- a/monitoring/zabbix_host.py +++ b/monitoring/zabbix_host.py @@ -47,6 +47,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" host_name: description: - Name of the host in Zabbix. @@ -158,8 +170,8 @@ except ImportError: class ZabbixAPIExtends(ZabbixAPI): hostinterface = 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.hostinterface = ZabbixAPISubClass(self, dict({"prefix": "hostinterface"}, **kwargs)) @@ -405,6 +417,8 @@ def main(): login_user=dict(rtype='str', equired=True), login_password=dict(type='str', required=True, no_log=True), host_name=dict(type='str', required=True), + http_login_user=dict(type='str', required=False, default=None), + http_login_password=dict(type='str', required=False, default=None, no_log=True), host_groups=dict(type='list', required=False), link_templates=dict(type='list', required=False), status=dict(default="enabled", choices=['enabled', 'disabled']), @@ -424,6 +438,8 @@ 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'] host_name = module.params['host_name'] host_groups = module.params['host_groups'] link_templates = module.params['link_templates'] @@ -441,7 +457,7 @@ def main(): 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) diff --git a/monitoring/zabbix_hostmacro.py b/monitoring/zabbix_hostmacro.py index c0b497a9..144e3d30 100644 --- a/monitoring/zabbix_hostmacro.py +++ b/monitoring/zabbix_hostmacro.py @@ -46,6 +46,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" host_name: description: - Name of the host. @@ -171,6 +183,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), host_name=dict(type='str', required=True), macro_name=dict(type='str', required=True), macro_value=dict(type='str', required=True), @@ -186,6 +200,8 @@ 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'] host_name = module.params['host_name'] macro_name = (module.params['macro_name']).upper() macro_value = module.params['macro_value'] @@ -195,7 +211,7 @@ def main(): 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) diff --git a/monitoring/zabbix_maintenance.py b/monitoring/zabbix_maintenance.py index fe26bd14..1d7caad3 100644 --- a/monitoring/zabbix_maintenance.py +++ b/monitoring/zabbix_maintenance.py @@ -52,6 +52,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" host_names: description: - Hosts to manage maintenance window for. @@ -91,6 +103,11 @@ options: - Type of maintenance. With data collection, or without. required: false default: "true" + timeout: + description: + - The timeout of API request (seconds). + default: 10 + version_added: "2.1" notes: - Useful for setting hosts in maintenance mode before big update, and removing maintenance window after update. @@ -260,9 +277,12 @@ def main(): host_groups=dict(type='list', required=False, default=None, aliases=['host_group']), 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), name=dict(type='str', required=True), desc=dict(type='str', required=False, default="Created by Ansible"), collect_data=dict(type='bool', required=False, default=True), + timeout=dict(type='int', default=10), ), supports_check_mode=True, ) @@ -275,18 +295,22 @@ def main(): state = module.params['state'] 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'] minutes = module.params['minutes'] name = module.params['name'] desc = module.params['desc'] server_url = module.params['server_url'] collect_data = module.params['collect_data'] + timeout = module.params['timeout'] + if collect_data: maintenance_type = 0 else: maintenance_type = 1 try: - zbx = ZabbixAPI(server_url) + zbx = ZabbixAPI(server_url, timeout=timeout, user=http_login_user, passwd=http_login_password) zbx.login(login_user, login_password) except BaseException as e: module.fail_json(msg="Failed to connect to Zabbix server: %s" % e) diff --git a/monitoring/zabbix_screen.py b/monitoring/zabbix_screen.py index f904c550..ffdcb21b 100644 --- a/monitoring/zabbix_screen.py +++ b/monitoring/zabbix_screen.py @@ -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) |