Skip to content

Commit

Permalink
zabbix_host: add interface definition error checking / defaults (#35366)
Browse files Browse the repository at this point in the history
* add checking of interfaces, providing defaults or errors if required keys are not defined

* fix so that iteration of interfaces only happens if defined
  • Loading branch information
eikef authored and ansibot committed Jan 27, 2018
1 parent 04d8875 commit eeeea14
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion lib/ansible/modules/monitoring/zabbix/zabbix_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@
interfaces:
description:
- 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
- '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: []
tls_connect:
description:
Expand Down Expand Up @@ -716,7 +718,37 @@ def main():

ip = ""
if interfaces:
# ensure interfaces are well-formed
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:
ip = interface['ip']

Expand Down

0 comments on commit eeeea14

Please sign in to comment.