zabbix: add validate certs param (#31739)

This commit is contained in:
Werner Dijkerman 2017-10-16 15:42:28 +02:00 committed by René Moser
parent 2087dc7384
commit 6984eecdb9
6 changed files with 74 additions and 10 deletions

View file

@ -70,6 +70,10 @@ options:
- List of host groups to create or delete. - List of host groups to create or delete.
required: true required: true
aliases: [ "host_group" ] aliases: [ "host_group" ]
extends_documentation_fragment:
- zabbix
notes: notes:
- Too many concurrent updates to the same group may cause Zabbix to return errors, see examples for a workaround if needed. - Too many concurrent updates to the same group may cause Zabbix to return errors, see examples for a workaround if needed.
''' '''
@ -163,6 +167,7 @@ def main():
login_password=dict(type='str', required=True, no_log=True), login_password=dict(type='str', required=True, no_log=True),
http_login_user=dict(type='str',required=False, default=None), http_login_user=dict(type='str',required=False, default=None),
http_login_password=dict(type='str',required=False, default=None, no_log=True), http_login_password=dict(type='str',required=False, default=None, no_log=True),
validate_certs=dict(type='bool',required=False, default=True),
host_groups=dict(type='list', required=True, aliases=['host_group']), host_groups=dict(type='list', required=True, aliases=['host_group']),
state=dict(default="present", choices=['present','absent']), state=dict(default="present", choices=['present','absent']),
timeout=dict(type='int', default=10) timeout=dict(type='int', default=10)
@ -178,6 +183,7 @@ def main():
login_password = module.params['login_password'] login_password = module.params['login_password']
http_login_user = module.params['http_login_user'] http_login_user = module.params['http_login_user']
http_login_password = module.params['http_login_password'] http_login_password = module.params['http_login_password']
validate_certs = module.params['validate_certs']
host_groups = module.params['host_groups'] host_groups = module.params['host_groups']
state = module.params['state'] state = module.params['state']
timeout = module.params['timeout'] timeout = module.params['timeout']
@ -186,7 +192,8 @@ def main():
# login to zabbix # login to zabbix
try: try:
zbx = ZabbixAPI(server_url, timeout=timeout, user=http_login_user, passwd=http_login_password) zbx = ZabbixAPI(server_url, timeout=timeout, user=http_login_user, passwd=http_login_password,
validate_certs=validate_certs)
zbx.login(login_user, login_password) zbx.login(login_user, login_password)
except Exception as e: except Exception as e:
module.fail_json(msg="Failed to connect to Zabbix server: %s" % e) module.fail_json(msg="Failed to connect to Zabbix server: %s" % e)

View file

@ -27,7 +27,7 @@ author:
- "Werner Dijkerman" - "Werner Dijkerman"
requirements: requirements:
- "python >= 2.6" - "python >= 2.6"
- zabbix-api - "zabbix-api >= 0.5.3"
options: options:
server_url: server_url:
description: description:
@ -166,6 +166,9 @@ options:
default: "yes" default: "yes"
choices: [ "yes", "no" ] choices: [ "yes", "no" ]
version_added: "2.0" version_added: "2.0"
extends_documentation_fragment:
- zabbix
''' '''
EXAMPLES = ''' EXAMPLES = '''
@ -231,8 +234,8 @@ try:
class ZabbixAPIExtends(ZabbixAPI): class ZabbixAPIExtends(ZabbixAPI):
hostinterface = None hostinterface = None
def __init__(self, server, timeout, user, passwd, **kwargs): def __init__(self, server, timeout, user, passwd, validate_certs, **kwargs):
ZabbixAPI.__init__(self, server, timeout=timeout, user=user, passwd=passwd) ZabbixAPI.__init__(self, server, timeout=timeout, user=user, passwd=passwd, validate_certs=validate_certs)
self.hostinterface = ZabbixAPISubClass(self, dict({"prefix": "hostinterface"}, **kwargs)) self.hostinterface = ZabbixAPISubClass(self, dict({"prefix": "hostinterface"}, **kwargs))
@ -538,6 +541,7 @@ def main():
host_name=dict(type='str', required=True), host_name=dict(type='str', required=True),
http_login_user=dict(type='str', required=False, default=None), http_login_user=dict(type='str', required=False, default=None),
http_login_password=dict(type='str', required=False, default=None, no_log=True), http_login_password=dict(type='str', required=False, default=None, no_log=True),
validate_certs=dict(type='bool', required=False, default=True),
host_groups=dict(type='list', required=False), host_groups=dict(type='list', required=False),
link_templates=dict(type='list', required=False), link_templates=dict(type='list', required=False),
status=dict(default="enabled", choices=['enabled', 'disabled']), status=dict(default="enabled", choices=['enabled', 'disabled']),
@ -567,6 +571,7 @@ def main():
login_password = module.params['login_password'] login_password = module.params['login_password']
http_login_user = module.params['http_login_user'] http_login_user = module.params['http_login_user']
http_login_password = module.params['http_login_password'] http_login_password = module.params['http_login_password']
validate_certs = module.params['validate_certs']
host_name = module.params['host_name'] host_name = module.params['host_name']
visible_name = module.params['visible_name'] visible_name = module.params['visible_name']
description = module.params['description'] description = module.params['description']
@ -592,7 +597,8 @@ def main():
zbx = None zbx = None
# login to zabbix # login to zabbix
try: try:
zbx = ZabbixAPIExtends(server_url, timeout=timeout, user=http_login_user, passwd=http_login_password) zbx = ZabbixAPIExtends(server_url, timeout=timeout, user=http_login_user, passwd=http_login_password,
validate_certs=validate_certs)
zbx.login(login_user, login_password) zbx.login(login_user, login_password)
except Exception as e: except Exception as e:
module.fail_json(msg="Failed to connect to Zabbix server: %s" % e) module.fail_json(msg="Failed to connect to Zabbix server: %s" % e)

View file

@ -76,6 +76,9 @@ options:
description: description:
- The timeout of API request (seconds). - The timeout of API request (seconds).
default: 10 default: 10
extends_documentation_fragment:
- zabbix
''' '''
EXAMPLES = ''' EXAMPLES = '''
@ -177,6 +180,7 @@ def main():
login_password=dict(type='str', required=True, no_log=True), login_password=dict(type='str', required=True, no_log=True),
http_login_user=dict(type='str', required=False, default=None), http_login_user=dict(type='str', required=False, default=None),
http_login_password=dict(type='str', required=False, default=None, no_log=True), http_login_password=dict(type='str', required=False, default=None, no_log=True),
validate_certs=dict(type='bool', required=False, default=True),
host_name=dict(type='str', required=True), host_name=dict(type='str', required=True),
macro_name=dict(type='str', required=True), macro_name=dict(type='str', required=True),
macro_value=dict(type='str', required=True), macro_value=dict(type='str', required=True),
@ -194,6 +198,7 @@ def main():
login_password = module.params['login_password'] login_password = module.params['login_password']
http_login_user = module.params['http_login_user'] http_login_user = module.params['http_login_user']
http_login_password = module.params['http_login_password'] http_login_password = module.params['http_login_password']
validate_certs = module.params['validate_certs']
host_name = module.params['host_name'] host_name = module.params['host_name']
macro_name = (module.params['macro_name']).upper() macro_name = (module.params['macro_name']).upper()
macro_value = module.params['macro_value'] macro_value = module.params['macro_value']
@ -203,7 +208,8 @@ def main():
zbx = None zbx = None
# login to zabbix # login to zabbix
try: try:
zbx = ZabbixAPIExtends(server_url, timeout=timeout, user=http_login_user, passwd=http_login_password) zbx = ZabbixAPIExtends(server_url, timeout=timeout, user=http_login_user, passwd=http_login_password,
validate_certs=validate_certs)
zbx.login(login_user, login_password) zbx.login(login_user, login_password)
except Exception as e: except Exception as e:
module.fail_json(msg="Failed to connect to Zabbix server: %s" % e) module.fail_json(msg="Failed to connect to Zabbix server: %s" % e)

View file

@ -103,6 +103,10 @@ options:
default: 10 default: 10
version_added: "2.1" version_added: "2.1"
required: false required: false
extends_documentation_fragment:
- zabbix
notes: notes:
- Useful for setting hosts in maintenance mode before big update, - Useful for setting hosts in maintenance mode before big update,
and removing maintenance window after update. and removing maintenance window after update.
@ -305,6 +309,7 @@ def main():
host_groups=dict(type='list', required=False, default=None, aliases=['host_group']), host_groups=dict(type='list', required=False, default=None, aliases=['host_group']),
login_user=dict(type='str', required=True), login_user=dict(type='str', required=True),
login_password=dict(type='str', required=True, no_log=True), login_password=dict(type='str', required=True, no_log=True),
validate_certs=dict(type='bool', required=False, default=True),
http_login_user=dict(type='str', required=False, default=None), http_login_user=dict(type='str', required=False, default=None),
http_login_password=dict(type='str', required=False, default=None, no_log=True), http_login_password=dict(type='str', required=False, default=None, no_log=True),
name=dict(type='str', required=True), name=dict(type='str', required=True),
@ -325,6 +330,7 @@ def main():
login_password = module.params['login_password'] login_password = module.params['login_password']
http_login_user = module.params['http_login_user'] http_login_user = module.params['http_login_user']
http_login_password = module.params['http_login_password'] http_login_password = module.params['http_login_password']
validate_certs = module.params['validate_certs']
minutes = module.params['minutes'] minutes = module.params['minutes']
name = module.params['name'] name = module.params['name']
desc = module.params['desc'] desc = module.params['desc']
@ -338,7 +344,8 @@ def main():
maintenance_type = 1 maintenance_type = 1
try: try:
zbx = ZabbixAPI(server_url, timeout=timeout, user=http_login_user, passwd=http_login_password) zbx = ZabbixAPI(server_url, timeout=timeout, user=http_login_user, passwd=http_login_password,
validate_certs=validate_certs)
zbx.login(login_user, login_password) zbx.login(login_user, login_password)
except BaseException as e: except BaseException as e:
module.fail_json(msg="Failed to connect to Zabbix server: %s" % e) module.fail_json(msg="Failed to connect to Zabbix server: %s" % e)

View file

@ -68,6 +68,10 @@ options:
The available states are: C(present) (default) and C(absent). If the screen(s) already exists, and the state is not C(absent), the screen(s) The available states are: C(present) (default) and C(absent). If the screen(s) already exists, and the state is not C(absent), the screen(s)
will just be updated as needed. will just be updated as needed.
required: true required: true
extends_documentation_fragment:
- zabbix
notes: notes:
- Too many concurrent updates to the same screen may cause Zabbix to return errors, see examples for a workaround if needed. - Too many concurrent updates to the same screen may cause Zabbix to return errors, see examples for a workaround if needed.
''' '''
@ -146,8 +150,8 @@ try:
class ZabbixAPIExtends(ZabbixAPI): class ZabbixAPIExtends(ZabbixAPI):
screenitem = None screenitem = None
def __init__(self, server, timeout, user, passwd, **kwargs): def __init__(self, server, timeout, user, passwd, validate_certs, **kwargs):
ZabbixAPI.__init__(self, server, timeout=timeout, user=user, passwd=passwd) ZabbixAPI.__init__(self, server, timeout=timeout, user=user, passwd=passwd, validate_certs=validate_certs)
self.screenitem = ZabbixAPISubClass(self, dict({"prefix": "screenitem"}, **kwargs)) self.screenitem = ZabbixAPISubClass(self, dict({"prefix": "screenitem"}, **kwargs))
HAS_ZABBIX_API = True HAS_ZABBIX_API = True
@ -330,6 +334,7 @@ def main():
login_password=dict(type='str', required=True, no_log=True), login_password=dict(type='str', required=True, no_log=True),
http_login_user=dict(type='str', required=False, default=None), http_login_user=dict(type='str', required=False, default=None),
http_login_password=dict(type='str', required=False, default=None, no_log=True), http_login_password=dict(type='str', required=False, default=None, no_log=True),
validate_certs=dict(type='bool', required=False, default=True),
timeout=dict(type='int', default=10), timeout=dict(type='int', default=10),
screens=dict(type='list', required=True) screens=dict(type='list', required=True)
), ),
@ -344,13 +349,15 @@ def main():
login_password = module.params['login_password'] login_password = module.params['login_password']
http_login_user = module.params['http_login_user'] http_login_user = module.params['http_login_user']
http_login_password = module.params['http_login_password'] http_login_password = module.params['http_login_password']
validate_certs = module.params['validate_certs']
timeout = module.params['timeout'] timeout = module.params['timeout']
screens = module.params['screens'] screens = module.params['screens']
zbx = None zbx = None
# login to zabbix # login to zabbix
try: try:
zbx = ZabbixAPIExtends(server_url, timeout=timeout, user=http_login_user, passwd=http_login_password) zbx = ZabbixAPIExtends(server_url, timeout=timeout, user=http_login_user, passwd=http_login_password,
validate_certs=validate_certs)
zbx.login(login_user, login_password) zbx.login(login_user, login_password)
except Exception as e: except Exception as e:
module.fail_json(msg="Failed to connect to Zabbix server: %s" % e) module.fail_json(msg="Failed to connect to Zabbix server: %s" % e)

View file

@ -0,0 +1,31 @@
# Copyright (c) 2017 Ansible, Inc
#
# This file is part of Ansible
#
# Ansible 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.
#
# Ansible 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 Ansible. If not, see <http://www.gnu.org/licenses/>.
class ModuleDocFragment(object):
# Standard documentation fragment
DOCUMENTATION = '''
options:
validate_certs:
required: false
description:
- If set to False, SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates.
default: true
choices: ['true', 'false']
version_added: "2.5"
'''