| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
from __future__ import absolute_import, division, print_function |
| 7 |
__metaclass__ = type |
| 8 |
|
| 9 |
DOCUMENTATION = ''' |
| 10 |
--- |
| 11 |
module: nios_dtc_monitor_snmp |
| 12 |
author: "Joachim Buyse (@jbisabel)" |
| 13 |
version_added: "1.6.0" |
| 14 |
short_description: Configure Infoblox NIOS DTC SNMP monitors |
| 15 |
description: |
| 16 |
- Adds and/or removes instances of DTC SNMP monitor objects from Infoblox NIOS |
| 17 |
servers. This module manages C(dtc:monitor:snmp) objects using the Infoblox |
| 18 |
WAPI interface over REST. |
| 19 |
requirements: |
| 20 |
- infoblox-client |
| 21 |
extends_documentation_fragment: infoblox.nios_modules.nios |
| 22 |
notes: |
| 23 |
- This module supports C(check_mode). |
| 24 |
options: |
| 25 |
name: |
| 26 |
description: |
| 27 |
- Configures the display name for this DTC monitor. Values with leading |
| 28 |
or trailing white space are not valid for this field. |
| 29 |
required: true |
| 30 |
type: str |
| 31 |
port: |
| 32 |
description: |
| 33 |
- Configures the port value for SNMP requests. |
| 34 |
type: int |
| 35 |
default: 161 |
| 36 |
version: |
| 37 |
description: |
| 38 |
- Configures the SNMP protocol version for the SNMP health check. |
| 39 |
type: str |
| 40 |
choices: |
| 41 |
- V1 |
| 42 |
- V2C |
| 43 |
- V3 |
| 44 |
default: V2C |
| 45 |
community: |
| 46 |
description: |
| 47 |
- Configures the SNMP community string for SNMP authentication. |
| 48 |
type: str |
| 49 |
default: public |
| 50 |
user: |
| 51 |
description: |
| 52 |
- Configures the SNMPv3 user setting. |
| 53 |
type: str |
| 54 |
context: |
| 55 |
description: |
| 56 |
- Configures the SNMPv3 context. Values with leading or trailing white |
| 57 |
space are not valid for this field. |
| 58 |
type: str |
| 59 |
engine_id: |
| 60 |
description: |
| 61 |
- Configures the SNMPv3 engine identifier. Values with leading or |
| 62 |
trailing white space are not valid for this field. |
| 63 |
type: str |
| 64 |
oids: |
| 65 |
description: |
| 66 |
- Configures the list of OIDs for SNMP monitoring. |
| 67 |
type: list |
| 68 |
elements: dict |
| 69 |
suboptions: |
| 70 |
comment: |
| 71 |
description: |
| 72 |
- Configures a text string comment to be associated with the instance |
| 73 |
of this object. The provided text string will be configured on the |
| 74 |
object instance. |
| 75 |
type: str |
| 76 |
condition: |
| 77 |
description: |
| 78 |
- Configures the condition of the validation result for the SNMP |
| 79 |
health check. |
| 80 |
type: str |
| 81 |
choices: |
| 82 |
- ANY |
| 83 |
- EXACT |
| 84 |
- GEQ |
| 85 |
- LEQ |
| 86 |
- RANGE |
| 87 |
default: ANY |
| 88 |
first: |
| 89 |
description: |
| 90 |
- Configures the condition's first term to match against the SNMP |
| 91 |
health check result. |
| 92 |
type: str |
| 93 |
last: |
| 94 |
description: |
| 95 |
- Configures the condition's second term to match against the SNMP |
| 96 |
health check result with 'RANGE' condition. |
| 97 |
type: str |
| 98 |
oid: |
| 99 |
description: |
| 100 |
- Configures the SNMP OID value for DTC SNMP Monitor health checks. |
| 101 |
- This field is required on creation |
| 102 |
required: true |
| 103 |
type: str |
| 104 |
type: |
| 105 |
description: |
| 106 |
- Configures the condition type for DTC SNMP Monitor health checks |
| 107 |
results. |
| 108 |
type: str |
| 109 |
choices: |
| 110 |
- INTEGER |
| 111 |
- STRING |
| 112 |
default: STRING |
| 113 |
interval: |
| 114 |
description: |
| 115 |
- Configures the interval for SNMP health check. |
| 116 |
type: int |
| 117 |
default: 5 |
| 118 |
retry_down: |
| 119 |
description: |
| 120 |
- Configures the value of how many times the server should appear as |
| 121 |
down to be treated as dead after it was alive. |
| 122 |
type: int |
| 123 |
default: 1 |
| 124 |
retry_up: |
| 125 |
description: |
| 126 |
- Configures the value of how many times the server should appear as up |
| 127 |
to be treated as alive after it was dead. |
| 128 |
type: int |
| 129 |
default: 1 |
| 130 |
timeout: |
| 131 |
description: |
| 132 |
- Configures the timeout for SNMP health check in seconds. |
| 133 |
type: int |
| 134 |
default: 15 |
| 135 |
extattrs: |
| 136 |
description: |
| 137 |
- Allows for the configuration of Extensible Attributes on the |
| 138 |
instance of the object. This argument accepts a set of key / value |
| 139 |
pairs for configuration. |
| 140 |
type: dict |
| 141 |
comment: |
| 142 |
description: |
| 143 |
- Configures a text string comment to be associated with the instance |
| 144 |
of this object. The provided text string will be configured on the |
| 145 |
object instance. |
| 146 |
type: str |
| 147 |
state: |
| 148 |
description: |
| 149 |
- Configures the intended state of the instance of the object on |
| 150 |
the NIOS server. When this value is set to C(present), the object |
| 151 |
is configured on the device and when this value is set to C(absent) |
| 152 |
the value is removed (if necessary) from the device. |
| 153 |
default: present |
| 154 |
choices: |
| 155 |
- present |
| 156 |
- absent |
| 157 |
type: str |
| 158 |
''' |
| 159 |
|
| 160 |
EXAMPLES = ''' |
| 161 |
- name: Configure a DTC SNMP monitor |
| 162 |
infoblox.nios_modules.nios_dtc_monitor_snmp: |
| 163 |
name: snmp_monitor |
| 164 |
port: 8080 |
| 165 |
state: present |
| 166 |
provider: |
| 167 |
host: "{{ inventory_hostname_short }}" |
| 168 |
username: admin |
| 169 |
password: admin |
| 170 |
connection: local |
| 171 |
|
| 172 |
- name: Add a comment to an existing DTC SNMP monitor |
| 173 |
infoblox.nios_modules.nios_dtc_monitor_snmp: |
| 174 |
name: snmp_monitor |
| 175 |
comment: this is a test comment |
| 176 |
state: present |
| 177 |
provider: |
| 178 |
host: "{{ inventory_hostname_short }}" |
| 179 |
username: admin |
| 180 |
password: admin |
| 181 |
connection: local |
| 182 |
|
| 183 |
- name: Remove a DTC SNMP monitor from the system |
| 184 |
infoblox.nios_modules.nios_dtc_monitor_snmp: |
| 185 |
name: snmp_monitor |
| 186 |
state: absent |
| 187 |
provider: |
| 188 |
host: "{{ inventory_hostname_short }}" |
| 189 |
username: admin |
| 190 |
password: admin |
| 191 |
connection: local |
| 192 |
''' |
| 193 |
|
| 194 |
RETURN = ''' # ''' |
| 195 |
|
| 196 |
from ansible.module_utils.basic import AnsibleModule |
| 197 |
from ..module_utils.api import WapiModule |
| 198 |
from ..module_utils.api import NIOS_DTC_MONITOR_SNMP |
| 199 |
from ..module_utils.api import normalize_ib_spec |
| 200 |
|
| 201 |
|
| 202 |
def oids(module): |
| 203 |
''' Transform the module argument into a valid WAPI struct |
| 204 |
This function will transform the oids argument into a structure that is a |
| 205 |
valid WAPI structure in the format of: |
| 206 |
{ |
| 207 |
comment: <value>, |
| 208 |
condition: <value>, |
| 209 |
first: <value>, |
| 210 |
last: <value>, |
| 211 |
oid: <value>, |
| 212 |
type: <value>, |
| 213 |
} |
| 214 |
It will remove any options that are set to None since WAPI will error on |
| 215 |
that condition. |
| 216 |
The remainder of the value validation is performed by WAPI |
| 217 |
''' |
| 218 |
if not module.params.get('oids'): |
| 219 |
return None |
| 220 |
|
| 221 |
oids = list() |
| 222 |
for item in module.params['oids']: |
| 223 |
oid = dict([(k, v) for k, v in item.items() if v is not None]) |
| 224 |
if 'oid' not in oid: |
| 225 |
module.fail_json(msg='oid is required for oid value') |
| 226 |
oids.append(oid) |
| 227 |
return oids |
| 228 |
|
| 229 |
|
| 230 |
def main(): |
| 231 |
''' Main entry point for module execution |
| 232 |
''' |
| 233 |
|
| 234 |
oid_spec = dict( |
| 235 |
comment=dict(type='str'), |
| 236 |
condition=dict(default='ANY', choices=['ANY', 'EXACT', 'GEQ', 'LEQ', 'RANGE']), |
| 237 |
first=dict(type='str'), |
| 238 |
last=dict(type='str'), |
| 239 |
oid=dict(type='str', required=True), |
| 240 |
type=dict(default='STRING', choices=['INTEGER', 'STRING']) |
| 241 |
) |
| 242 |
|
| 243 |
ib_spec = dict( |
| 244 |
name=dict(required=True, ib_req=True), |
| 245 |
|
| 246 |
port=dict(type='int', default=161), |
| 247 |
version=dict(default='V2C', choices=['V1', 'V2C', 'V3']), |
| 248 |
community=dict(type='str', default='public'), |
| 249 |
user=dict(type='str'), |
| 250 |
context=dict(type='str'), |
| 251 |
engine_id=dict(type='str'), |
| 252 |
oids=dict(type='list', elements='dict', options=oid_spec, transform=oids), |
| 253 |
interval=dict(type='int', default=5), |
| 254 |
retry_down=dict(type='int', default=1), |
| 255 |
retry_up=dict(type='int', default=1), |
| 256 |
timeout=dict(type='int', default=15), |
| 257 |
|
| 258 |
extattrs=dict(type='dict'), |
| 259 |
comment=dict(), |
| 260 |
) |
| 261 |
|
| 262 |
argument_spec = dict( |
| 263 |
provider=dict(required=True), |
| 264 |
state=dict(default='present', choices=['present', 'absent']) |
| 265 |
) |
| 266 |
|
| 267 |
argument_spec.update(normalize_ib_spec(ib_spec)) |
| 268 |
argument_spec.update(WapiModule.provider_spec) |
| 269 |
|
| 270 |
module = AnsibleModule(argument_spec=argument_spec, |
| 271 |
supports_check_mode=True) |
| 272 |
|
| 273 |
wapi = WapiModule(module) |
| 274 |
result = wapi.run(NIOS_DTC_MONITOR_SNMP, ib_spec) |
| 275 |
|
| 276 |
module.exit_json(**result) |
| 277 |
|
| 278 |
|
| 279 |
if __name__ == '__main__': |
| 280 |
main() |