Debian Codegraph @

ansible_collections/fortinet/fortimanager/plugins/modules/fmgr_ips_sensor.py

raw symbols SCIP
1 #!/usr/bin/python
2 from __future__ import absolute_import, division, print_function
3 # Copyright 2019-2024 Fortinet, Inc.
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 __metaclass__ = type
7
8 ANSIBLE_METADATA = {'status': ['preview'],
9 'supported_by': 'community',
10 'metadata_version': '1.1'}
11
12 DOCUMENTATION = '''
13 ---
14 module: fmgr_ips_sensor
15 short_description: Configure IPS sensor.
16 version_added: "1.0.0"
17 extends_documentation_fragment:
18 - fortinet.fortimanager.general
19 - fortinet.fortimanager.general.full_crud
20 options:
21 revision_note:
22 description: The change note that can be specified when an object is created or updated.
23 type: str
24 adom:
25 description: The parameter (adom) in requested url.
26 type: str
27 required: true
28 ips_sensor:
29 description: The top level parameters set.
30 required: false
31 type: dict
32 suboptions:
33 block_malicious_url:
34 aliases: ['block-malicious-url']
35 type: str
36 description: Enable/disable malicious URL blocking.
37 choices: ['disable', 'enable']
38 comment:
39 type: str
40 description: Comment.
41 entries:
42 type: list
43 elements: dict
44 description: Entries.
45 suboptions:
46 action:
47 type: str
48 description: Action taken with traffic in which signatures are detected.
49 choices: ['pass', 'block', 'reset', 'default']
50 application:
51 type: raw
52 description: (list) Applications to be protected.
53 exempt_ip:
54 aliases: ['exempt-ip']
55 type: list
56 elements: dict
57 description: Exempt ip.
58 suboptions:
59 dst_ip:
60 aliases: ['dst-ip']
61 type: str
62 description: Destination IP address and netmask.
63 id:
64 type: int
65 description: Exempt IP ID.
66 src_ip:
67 aliases: ['src-ip']
68 type: str
69 description: Source IP address and netmask.
70 id:
71 type: int
72 description: Rule ID in IPS database
73 location:
74 type: raw
75 description: (list) Protect client or server traffic.
76 log:
77 type: str
78 description: Enable/disable logging of signatures included in filter.
79 choices: ['disable', 'enable']
80 log_attack_context:
81 aliases: ['log-attack-context']
82 type: str
83 description: Enable/disable logging of attack context
84 choices: ['disable', 'enable']
85 log_packet:
86 aliases: ['log-packet']
87 type: str
88 description: Enable/disable packet logging.
89 choices: ['disable', 'enable']
90 os:
91 type: raw
92 description: (list) Operating systems to be protected.
93 protocol:
94 type: raw
95 description: (list) Protocols to be examined.
96 quarantine:
97 type: str
98 description: Quarantine method.
99 choices: ['none', 'attacker', 'both', 'interface']
100 quarantine_expiry:
101 aliases: ['quarantine-expiry']
102 type: str
103 description: Duration of quarantine.
104 quarantine_log:
105 aliases: ['quarantine-log']
106 type: str
107 description: Enable/disable quarantine logging.
108 choices: ['disable', 'enable']
109 rate_count:
110 aliases: ['rate-count']
111 type: int
112 description: Count of the rate.
113 rate_duration:
114 aliases: ['rate-duration']
115 type: int
116 description: Duration
117 rate_mode:
118 aliases: ['rate-mode']
119 type: str
120 description: Rate limit mode.
121 choices: ['periodical', 'continuous']
122 rate_track:
123 aliases: ['rate-track']
124 type: str
125 description: Track the packet protocol field.
126 choices: ['none', 'src-ip', 'dest-ip', 'dhcp-client-mac', 'dns-domain']
127 rule:
128 type: raw
129 description: (list or str) Identifies the predefined or custom IPS signatures to add to the sensor.
130 severity:
131 type: raw
132 description: (list) Relative severity of the signature, from info to critical.
133 status:
134 type: str
135 description: Status of the signatures included in filter.
136 choices: ['disable', 'enable', 'default']
137 tags:
138 type: str
139 description: Assign a custom tag filter to the IPS sensor.
140 cve:
141 type: raw
142 description: (list) List of CVE IDs of the signatures to add to the sensor
143 default_action:
144 aliases: ['default-action']
145 type: str
146 description: Signature default action filter.
147 choices: ['block', 'pass', 'all', 'drop']
148 default_status:
149 aliases: ['default-status']
150 type: str
151 description: Signature default status filter.
152 choices: ['disable', 'enable', 'all']
153 last_modified:
154 aliases: ['last-modified']
155 type: raw
156 description: (list or str) Filter by signature last modified date.
157 vuln_type:
158 aliases: ['vuln-type']
159 type: raw
160 description: (list) List of signature vulnerability types to filter by.
161 extended_log:
162 aliases: ['extended-log']
163 type: str
164 description: Enable/disable extended logging.
165 choices: ['disable', 'enable']
166 filter:
167 type: list
168 elements: dict
169 description: Filter.
170 suboptions:
171 action:
172 type: str
173 description: Action of selected rules.
174 choices: ['pass', 'block', 'default', 'reset']
175 application:
176 type: raw
177 description: (list) Vulnerable application filter.
178 location:
179 type: raw
180 description: (list) Vulnerability location filter.
181 log:
182 type: str
183 description: Enable/disable logging of selected rules.
184 choices: ['disable', 'enable', 'default']
185 log_packet:
186 aliases: ['log-packet']
187 type: str
188 description: Enable/disable packet logging of selected rules.
189 choices: ['disable', 'enable', 'default']
190 name:
191 type: str
192 description: Filter name.
193 os:
194 type: raw
195 description: (list) Vulnerable OS filter.
196 protocol:
197 type: raw
198 description: (list) Vulnerable protocol filter.
199 quarantine:
200 type: str
201 description: Quarantine IP or interface.
202 choices: ['none', 'attacker', 'both', 'interface']
203 quarantine_expiry:
204 aliases: ['quarantine-expiry']
205 type: int
206 description: Duration of quarantine in minute.
207 quarantine_log:
208 aliases: ['quarantine-log']
209 type: str
210 description: Enable/disable logging of selected quarantine.
211 choices: ['disable', 'enable']
212 severity:
213 type: raw
214 description: (list) Vulnerability severity filter.
215 status:
216 type: str
217 description: Selected rules status.
218 choices: ['disable', 'enable', 'default']
219 name:
220 type: str
221 description: Sensor name.
222 required: true
223 override:
224 type: list
225 elements: dict
226 description: Override.
227 suboptions:
228 action:
229 type: str
230 description: Action of override rule.
231 choices: ['pass', 'block', 'reset']
232 exempt_ip:
233 aliases: ['exempt-ip']
234 type: list
235 elements: dict
236 description: Exempt ip.
237 suboptions:
238 dst_ip:
239 aliases: ['dst-ip']
240 type: str
241 description: Destination IP address and netmask.
242 id:
243 type: int
244 description: Exempt IP ID.
245 src_ip:
246 aliases: ['src-ip']
247 type: str
248 description: Source IP address and netmask.
249 log:
250 type: str
251 description: Enable/disable logging.
252 choices: ['disable', 'enable']
253 log_packet:
254 aliases: ['log-packet']
255 type: str
256 description: Enable/disable packet logging.
257 choices: ['disable', 'enable']
258 quarantine:
259 type: str
260 description: Quarantine IP or interface.
261 choices: ['none', 'attacker', 'both', 'interface']
262 quarantine_expiry:
263 aliases: ['quarantine-expiry']
264 type: int
265 description: Duration of quarantine in minute.
266 quarantine_log:
267 aliases: ['quarantine-log']
268 type: str
269 description: Enable/disable logging of selected quarantine.
270 choices: ['disable', 'enable']
271 rule_id:
272 aliases: ['rule-id']
273 type: int
274 description: Override rule ID.
275 status:
276 type: str
277 description: Enable/disable status of override rule.
278 choices: ['disable', 'enable']
279 replacemsg_group:
280 aliases: ['replacemsg-group']
281 type: str
282 description: Replacement message group.
283 scan_botnet_connections:
284 aliases: ['scan-botnet-connections']
285 type: str
286 description: Block or monitor connections to Botnet servers, or disable Botnet scanning.
287 choices: ['disable', 'block', 'monitor']
288 _baseline:
289 type: str
290 description: Baseline.
291 '''
292
293 EXAMPLES = '''
294 - name: Example playbook
295 hosts: fortimanagers
296 gather_facts: false
297 connection: httpapi
298 vars:
299 ansible_httpapi_use_ssl: true
300 ansible_httpapi_validate_certs: false
301 ansible_httpapi_port: 443
302 tasks:
303 - name: Configure IPS sensor.
304 fortinet.fortimanager.fmgr_ips_sensor:
305 bypass_validation: false
306 adom: ansible
307 state: present
308 ips_sensor:
309 block_malicious_url: disable
310 comment: "ansible-comment"
311 name: "ansible-test-ipssensor"
312
313 - name: Gathering fortimanager facts
314 hosts: fortimanagers
315 gather_facts: false
316 connection: httpapi
317 vars:
318 ansible_httpapi_use_ssl: true
319 ansible_httpapi_validate_certs: false
320 ansible_httpapi_port: 443
321 tasks:
322 - name: Retrieve all the IPS sensors
323 fortinet.fortimanager.fmgr_fact:
324 facts:
325 selector: "ips_sensor"
326 params:
327 adom: "ansible"
328 sensor: "your_value"
329 '''
330
331 RETURN = '''
332 meta:
333 description: The result of the request.
334 type: dict
335 returned: always
336 contains:
337 request_url:
338 description: The full url requested.
339 returned: always
340 type: str
341 sample: /sys/login/user
342 response_code:
343 description: The status of api request.
344 returned: always
345 type: int
346 sample: 0
347 response_data:
348 description: The api response.
349 type: list
350 returned: always
351 response_message:
352 description: The descriptive message of the api response.
353 type: str
354 returned: always
355 sample: OK.
356 system_information:
357 description: The information of the target system.
358 type: dict
359 returned: always
360 rc:
361 description: The status the request.
362 type: int
363 returned: always
364 sample: 0
365 version_check_warning:
366 description: Warning if the parameters used in the playbook are not supported by the current FortiManager version.
367 type: list
368 returned: complex
369 '''
370 from ansible.module_utils.basic import AnsibleModule
371 from ansible.module_utils.connection import Connection
372 from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass
373 from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec
374
375
376 def main():
377 urls_list = [
378 '/pm/config/adom/{adom}/obj/ips/sensor',
379 '/pm/config/global/obj/ips/sensor',
380 '/pm/config/adom/{adom}/obj/global/ips/sensor',
381 '/pm/config/global/obj/global/ips/sensor'
382 ]
383 module_arg_spec = {
384 'adom': {'required': True, 'type': 'str'},
385 'revision_note': {'type': 'str'},
386 'ips_sensor': {
387 'type': 'dict', 'v_range': [['6.0.0', '']],
388 'options': {
389 'block-malicious-url': {'choices': ['disable', 'enable'], 'type': 'str'},
390 'comment': {'type': 'str'},
391 'entries': {
392 'type': 'list',
393 'options': {
394 'action': {'choices': ['pass', 'block', 'reset', 'default'], 'type': 'str'},
395 'application': {'type': 'raw'},
396 'exempt-ip': {
397 'type': 'list',
398 'options': {'dst-ip': {'type': 'str'}, 'id': {'type': 'int'}, 'src-ip': {'type': 'str'}},
399 'elements': 'dict'
400 },
401 'id': {'type': 'int'},
402 'location': {'type': 'raw'},
403 'log': {'choices': ['disable', 'enable'], 'type': 'str'},
404 'log-attack-context': {'choices': ['disable', 'enable'], 'type': 'str'},
405 'log-packet': {'choices': ['disable', 'enable'], 'type': 'str'},
406 'os': {'type': 'raw'},
407 'protocol': {'type': 'raw'},
408 'quarantine': {'choices': ['none', 'attacker', 'both', 'interface'], 'type': 'str'},
409 'quarantine-expiry': {'type': 'str'},
410 'quarantine-log': {'choices': ['disable', 'enable'], 'type': 'str'},
411 'rate-count': {'type': 'int'},
412 'rate-duration': {'type': 'int'},
413 'rate-mode': {'choices': ['periodical', 'continuous'], 'type': 'str'},
414 'rate-track': {'choices': ['none', 'src-ip', 'dest-ip', 'dhcp-client-mac', 'dns-domain'], 'type': 'str'},
415 'rule': {'type': 'raw'},
416 'severity': {'type': 'raw'},
417 'status': {'choices': ['disable', 'enable', 'default'], 'type': 'str'},
418 'tags': {'v_range': [['6.2.0', '6.4.15'], ['7.4.8', '7.4.10']], 'type': 'str'},
419 'cve': {'v_range': [['6.4.2', '']], 'type': 'raw'},
420 'default-action': {'v_range': [['7.2.0', '']], 'choices': ['block', 'pass', 'all', 'drop'], 'type': 'str'},
421 'default-status': {'v_range': [['7.2.0', '']], 'choices': ['disable', 'enable', 'all'], 'type': 'str'},
422 'last-modified': {'v_range': [['7.2.0', '']], 'type': 'raw'},
423 'vuln-type': {'v_range': [['7.2.0', '']], 'type': 'raw'}
424 },
425 'elements': 'dict'
426 },
427 'extended-log': {'choices': ['disable', 'enable'], 'type': 'str'},
428 'filter': {
429 'v_range': [['6.0.0', '6.2.0']],
430 'type': 'list',
431 'options': {
432 'action': {'v_range': [['6.0.0', '6.2.0']], 'choices': ['pass', 'block', 'default', 'reset'], 'type': 'str'},
433 'application': {'v_range': [['6.0.0', '6.2.0']], 'type': 'raw'},
434 'location': {'v_range': [['6.0.0', '6.2.0']], 'type': 'raw'},
435 'log': {'v_range': [['6.0.0', '6.2.0']], 'choices': ['disable', 'enable', 'default'], 'type': 'str'},
436 'log-packet': {'v_range': [['6.0.0', '6.2.0']], 'choices': ['disable', 'enable', 'default'], 'type': 'str'},
437 'name': {'v_range': [['6.0.0', '6.2.0']], 'type': 'str'},
438 'os': {'v_range': [['6.0.0', '6.2.0']], 'type': 'raw'},
439 'protocol': {'v_range': [['6.0.0', '6.2.0']], 'type': 'raw'},
440 'quarantine': {'v_range': [['6.0.0', '6.2.0']], 'choices': ['none', 'attacker', 'both', 'interface'], 'type': 'str'},
441 'quarantine-expiry': {'v_range': [['6.0.0', '6.2.0']], 'type': 'int'},
442 'quarantine-log': {'v_range': [['6.0.0', '6.2.0']], 'choices': ['disable', 'enable'], 'type': 'str'},
443 'severity': {'v_range': [['6.0.0', '6.2.0']], 'type': 'raw'},
444 'status': {'v_range': [['6.0.0', '6.2.0']], 'choices': ['disable', 'enable', 'default'], 'type': 'str'}
445 },
446 'elements': 'dict'
447 },
448 'name': {'required': True, 'type': 'str'},
449 'override': {
450 'v_range': [['6.0.0', '6.2.0']],
451 'type': 'list',
452 'options': {
453 'action': {'v_range': [['6.0.0', '6.2.0']], 'choices': ['pass', 'block', 'reset'], 'type': 'str'},
454 'exempt-ip': {
455 'v_range': [['6.0.0', '6.2.0']],
456 'type': 'list',
457 'options': {
458 'dst-ip': {'v_range': [['6.0.0', '6.2.0']], 'type': 'str'},
459 'id': {'v_range': [['6.0.0', '6.2.0']], 'type': 'int'},
460 'src-ip': {'v_range': [['6.0.0', '6.2.0']], 'type': 'str'}
461 },
462 'elements': 'dict'
463 },
464 'log': {'v_range': [['6.0.0', '6.2.0']], 'choices': ['disable', 'enable'], 'type': 'str'},
465 'log-packet': {'v_range': [['6.0.0', '6.2.0']], 'choices': ['disable', 'enable'], 'type': 'str'},
466 'quarantine': {'v_range': [['6.0.0', '6.2.0']], 'choices': ['none', 'attacker', 'both', 'interface'], 'type': 'str'},
467 'quarantine-expiry': {'v_range': [['6.0.0', '6.2.0']], 'type': 'int'},
468 'quarantine-log': {'v_range': [['6.0.0', '6.2.0']], 'choices': ['disable', 'enable'], 'type': 'str'},
469 'rule-id': {'v_range': [['6.0.0', '6.2.0']], 'type': 'int'},
470 'status': {'v_range': [['6.0.0', '6.2.0']], 'choices': ['disable', 'enable'], 'type': 'str'}
471 },
472 'elements': 'dict'
473 },
474 'replacemsg-group': {'type': 'str'},
475 'scan-botnet-connections': {'v_range': [['6.2.0', '']], 'choices': ['disable', 'block', 'monitor'], 'type': 'str'},
476 '_baseline': {'v_range': [['7.0.1', '7.0.2']], 'type': 'str'}
477 }
478 }
479 }
480
481 module_option_spec = get_module_arg_spec('full crud')
482 module_arg_spec.update(module_option_spec)
483 check_galaxy_version(module_arg_spec)
484 module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'ips_sensor'),
485 supports_check_mode=True)
486 if not module._socket_path:
487 module.fail_json(msg='MUST RUN IN HTTPAPI MODE')
488 connection = Connection(module._socket_path)
489 fmgr = NAPIManager('full crud', module_arg_spec, urls_list,
490 'name', 'data', module, connection)
491 fmgr.process_crud()
492 module.exit_json(meta=module.params)
493
494
495 if __name__ == '__main__':
496 main()