mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
zabbix_host: add interface definition error checking / defaults (#35366)
* add checking of interfaces, providing defaults or errors if required keys are not defined * fix so that iteration of interfaces only happens if defined
This commit is contained in:
parent
04d88755d5
commit
eeeea1406b
1 changed files with 33 additions and 1 deletions
|
@ -81,9 +81,11 @@ options:
|
||||||
interfaces:
|
interfaces:
|
||||||
description:
|
description:
|
||||||
- List of interfaces to be created for the host (see example below).
|
- List of interfaces to be created for the host (see example below).
|
||||||
- 'Available values are: dns, ip, main, port, type and useip.'
|
- 'Available keys are: I(dns), I(ip), I(main), I(port), I(type), I(useip), and I(bulk).'
|
||||||
- Please review the interface documentation for more information on the supported properties
|
- Please review the interface documentation for more information on the supported properties
|
||||||
- 'https://www.zabbix.com/documentation/2.0/manual/appendix/api/hostinterface/definitions#host_interface'
|
- 'https://www.zabbix.com/documentation/2.0/manual/appendix/api/hostinterface/definitions#host_interface'
|
||||||
|
- If an interface definition is incomplete, this module will attempt to fill in sensible values.
|
||||||
|
- I(type) can also be C(agent), C(snmp), C(ipmi), or C(jmx) instead of its numerical value.
|
||||||
default: []
|
default: []
|
||||||
tls_connect:
|
tls_connect:
|
||||||
description:
|
description:
|
||||||
|
@ -716,7 +718,37 @@ def main():
|
||||||
|
|
||||||
ip = ""
|
ip = ""
|
||||||
if interfaces:
|
if interfaces:
|
||||||
|
# ensure interfaces are well-formed
|
||||||
for interface in interfaces:
|
for interface in interfaces:
|
||||||
|
if 'type' not in interface:
|
||||||
|
module.fail_json(msg="(interface) type needs to be specified for interface '%s'." % interface)
|
||||||
|
interfacetypes = {'agent': 1, 'snmp': 2, 'ipmi': 3, 'jmx': 4}
|
||||||
|
if interface['type'] in interfacetypes.keys():
|
||||||
|
interface['type'] = interfacetypes[interface['type']]
|
||||||
|
if interface['type'] < 1 or interface['type'] > 4:
|
||||||
|
module.fail_json(msg="Interface type can only be 1-4 for interface '%s'." % interface)
|
||||||
|
if 'useip' not in interface:
|
||||||
|
interface['useip'] = 0
|
||||||
|
if 'dns' not in interface:
|
||||||
|
if interface['useip'] == 0:
|
||||||
|
module.fail_json(msg="dns needs to be set if useip is 0 on interface '%s'." % interface)
|
||||||
|
interface['dns'] = ''
|
||||||
|
if 'ip' not in interface:
|
||||||
|
if interface['useip'] == 1:
|
||||||
|
module.fail_json(msg="ip needs to be set if useip is 1 on interface '%s'." % interface)
|
||||||
|
interface['ip'] = ''
|
||||||
|
if 'main' not in interface:
|
||||||
|
interface['main'] = 0
|
||||||
|
if 'port' not in interface:
|
||||||
|
if interface['type'] == 1:
|
||||||
|
interface['port'] = "10050"
|
||||||
|
elif interface['type'] == 2:
|
||||||
|
interface['port'] = "161"
|
||||||
|
elif interface['type'] == 3:
|
||||||
|
interface['port'] = "623"
|
||||||
|
elif interface['type'] == 4:
|
||||||
|
interface['port'] = "12345"
|
||||||
|
|
||||||
if interface['type'] == 1:
|
if interface['type'] == 1:
|
||||||
ip = interface['ip']
|
ip = interface['ip']
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue