Debian Codegraph @

ansible_collections/fortinet/fortios/plugins/modules/fortios_log_setting.py

raw symbols SCIP
1 #!/usr/bin/python
2 from __future__ import absolute_import, division, print_function
3
4 # Copyright: (c) 2022 Fortinet
5 # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11
12 __metaclass__ = type
13
14 ANSIBLE_METADATA = {
15 "status": ["preview"],
16 "supported_by": "community",
17 "metadata_version": "1.1",
18 }
19
20 DOCUMENTATION = """
21 ---
22 module: fortios_log_setting
23 short_description: Configure general log settings in Fortinet's FortiOS and FortiGate.
24 description:
25 - This module is able to configure a FortiGate or FortiOS (FOS) device by allowing the
26 user to set and modify log feature and setting category.
27 Examples include all parameters and values need to be adjusted to datasources before usage.
28 Tested with FOS v6.0.0
29 version_added: "2.0.0"
30 author:
31 - Link Zheng (@chillancezen)
32 - Jie Xue (@JieX19)
33 - Hongbin Lu (@fgtdev-hblu)
34 - Frank Shen (@frankshen01)
35 - Miguel Angel Munoz (@mamunozgonzalez)
36 - Nicolas Thomas (@thomnico)
37 notes:
38 - Legacy fortiosapi has been deprecated, httpapi is the preferred way to run playbooks
39
40 - The module supports check_mode.
41
42 requirements:
43 - ansible>=2.16
44 options:
45 access_token:
46 description:
47 - Token-based authentication.
48 Generated from GUI of Fortigate.
49 type: str
50 required: false
51 enable_log:
52 description:
53 - Enable/Disable logging for task.
54 type: bool
55 required: false
56 default: false
57 vdom:
58 description:
59 - Virtual domain, among those defined previously. A vdom is a
60 virtual instance of the FortiGate that can be configured and
61 used as a different unit.
62 type: str
63 default: root
64 member_path:
65 type: str
66 description:
67 - Member attribute path to operate on.
68 - Delimited by a slash character if there are more than one attribute.
69 - Parameter marked with member_path is legitimate for doing member operation.
70 member_state:
71 type: str
72 description:
73 - Add or delete a member under specified attribute path.
74 - When member_state is specified, the state option is ignored.
75 choices:
76 - 'present'
77 - 'absent'
78
79 log_setting:
80 description:
81 - Configure general log settings.
82 default: null
83 type: dict
84 suboptions:
85 anonymization_hash:
86 description:
87 - User name anonymization hash salt.
88 type: str
89 brief_traffic_format:
90 description:
91 - Enable/disable brief format traffic logging.
92 type: str
93 choices:
94 - 'enable'
95 - 'disable'
96 custom_log_fields:
97 description:
98 - Custom fields to append to all log messages.
99 type: list
100 elements: dict
101 suboptions:
102 field_id:
103 description:
104 - Custom log field. Source log.custom-field.id.
105 required: true
106 type: str
107 daemon_log:
108 description:
109 - Enable/disable daemon logging.
110 type: str
111 choices:
112 - 'enable'
113 - 'disable'
114 expolicy_implicit_log:
115 description:
116 - Enable/disable proxy firewall implicit policy logging.
117 type: str
118 choices:
119 - 'enable'
120 - 'disable'
121 extended_log:
122 description:
123 - Enable/disable extended traffic logging.
124 type: str
125 choices:
126 - 'enable'
127 - 'disable'
128 extended_utm_log:
129 description:
130 - Enable/disable extended UTM logging.
131 type: str
132 choices:
133 - 'enable'
134 - 'disable'
135 faz_override:
136 description:
137 - Enable/disable override FortiAnalyzer settings.
138 type: str
139 choices:
140 - 'enable'
141 - 'disable'
142 fortiview_weekly_data:
143 description:
144 - Enable/disable FortiView weekly data.
145 type: str
146 choices:
147 - 'enable'
148 - 'disable'
149 fwpolicy_implicit_log:
150 description:
151 - Enable/disable implicit firewall policy logging.
152 type: str
153 choices:
154 - 'enable'
155 - 'disable'
156 fwpolicy6_implicit_log:
157 description:
158 - Enable/disable implicit firewall policy6 logging.
159 type: str
160 choices:
161 - 'enable'
162 - 'disable'
163 local_in_allow:
164 description:
165 - Enable/disable local-in-allow logging.
166 type: str
167 choices:
168 - 'enable'
169 - 'disable'
170 local_in_deny_broadcast:
171 description:
172 - Enable/disable local-in-deny-broadcast logging.
173 type: str
174 choices:
175 - 'enable'
176 - 'disable'
177 local_in_deny_unicast:
178 description:
179 - Enable/disable local-in-deny-unicast logging.
180 type: str
181 choices:
182 - 'enable'
183 - 'disable'
184 local_in_policy_log:
185 description:
186 - Enable/disable local-in-policy logging.
187 type: str
188 choices:
189 - 'enable'
190 - 'disable'
191 local_out:
192 description:
193 - Enable/disable local-out logging.
194 type: str
195 choices:
196 - 'enable'
197 - 'disable'
198 local_out_ioc_detection:
199 description:
200 - Enable/disable local-out traffic IoC detection. Requires local-out to be enabled.
201 type: str
202 choices:
203 - 'enable'
204 - 'disable'
205 log_invalid_packet:
206 description:
207 - Enable/disable invalid packet traffic logging.
208 type: str
209 choices:
210 - 'enable'
211 - 'disable'
212 log_policy_comment:
213 description:
214 - Enable/disable inserting policy comments into traffic logs.
215 type: str
216 choices:
217 - 'enable'
218 - 'disable'
219 log_policy_name:
220 description:
221 - Enable/disable inserting policy name into traffic logs.
222 type: str
223 choices:
224 - 'enable'
225 - 'disable'
226 log_user_in_upper:
227 description:
228 - Enable/disable logs with user-in-upper.
229 type: str
230 choices:
231 - 'enable'
232 - 'disable'
233 long_live_session_stat:
234 description:
235 - Enable/disable long-live-session statistics logging.
236 type: str
237 choices:
238 - 'enable'
239 - 'disable'
240 neighbor_event:
241 description:
242 - Enable/disable neighbor event logging.
243 type: str
244 choices:
245 - 'enable'
246 - 'disable'
247 resolve_ip:
248 description:
249 - Enable/disable adding resolved domain names to traffic logs if possible.
250 type: str
251 choices:
252 - 'enable'
253 - 'disable'
254 resolve_port:
255 description:
256 - Enable/disable adding resolved service names to traffic logs.
257 type: str
258 choices:
259 - 'enable'
260 - 'disable'
261 rest_api_get:
262 description:
263 - Enable/disable REST API GET request logging.
264 type: str
265 choices:
266 - 'enable'
267 - 'disable'
268 rest_api_performance:
269 description:
270 - Enable/disable REST API memory and performance stats in rest-api-get/set logs.
271 type: str
272 choices:
273 - 'enable'
274 - 'disable'
275 rest_api_set:
276 description:
277 - Enable/disable REST API POST/PUT/DELETE request logging.
278 type: str
279 choices:
280 - 'enable'
281 - 'disable'
282 syslog_override:
283 description:
284 - Enable/disable override Syslog settings.
285 type: str
286 choices:
287 - 'enable'
288 - 'disable'
289 user_anonymize:
290 description:
291 - Enable/disable anonymizing user names in log messages.
292 type: str
293 choices:
294 - 'enable'
295 - 'disable'
296 web_svc_perf:
297 description:
298 - Enable/disable web-svc performance logging.
299 type: str
300 choices:
301 - 'enable'
302 - 'disable'
303 zone_name:
304 description:
305 - Enable/disable zone name logging.
306 type: str
307 choices:
308 - 'enable'
309 - 'disable'
310 """
311
312 EXAMPLES = """
313 - name: Configure general log settings.
314 fortinet.fortios.fortios_log_setting:
315 vdom: "{{ vdom }}"
316 log_setting:
317 anonymization_hash: "<your_own_value>"
318 brief_traffic_format: "enable"
319 custom_log_fields:
320 -
321 field_id: "<your_own_value> (source log.custom-field.id)"
322 daemon_log: "enable"
323 expolicy_implicit_log: "enable"
324 extended_log: "enable"
325 extended_utm_log: "enable"
326 faz_override: "enable"
327 fortiview_weekly_data: "enable"
328 fwpolicy_implicit_log: "enable"
329 fwpolicy6_implicit_log: "enable"
330 local_in_allow: "enable"
331 local_in_deny_broadcast: "enable"
332 local_in_deny_unicast: "enable"
333 local_in_policy_log: "enable"
334 local_out: "enable"
335 local_out_ioc_detection: "enable"
336 log_invalid_packet: "enable"
337 log_policy_comment: "enable"
338 log_policy_name: "enable"
339 log_user_in_upper: "enable"
340 long_live_session_stat: "enable"
341 neighbor_event: "enable"
342 resolve_ip: "enable"
343 resolve_port: "enable"
344 rest_api_get: "enable"
345 rest_api_performance: "enable"
346 rest_api_set: "enable"
347 syslog_override: "enable"
348 user_anonymize: "enable"
349 web_svc_perf: "enable"
350 zone_name: "enable"
351 """
352
353 RETURN = """
354 build:
355 description: Build number of the fortigate image
356 returned: always
357 type: str
358 sample: '1547'
359 http_method:
360 description: Last method used to provision the content into FortiGate
361 returned: always
362 type: str
363 sample: 'PUT'
364 http_status:
365 description: Last result given by FortiGate on last operation applied
366 returned: always
367 type: str
368 sample: "200"
369 mkey:
370 description: Master key (id) used in the last call to FortiGate
371 returned: success
372 type: str
373 sample: "id"
374 name:
375 description: Name of the table used to fulfill the request
376 returned: always
377 type: str
378 sample: "urlfilter"
379 path:
380 description: Path of the table used to fulfill the request
381 returned: always
382 type: str
383 sample: "webfilter"
384 revision:
385 description: Internal revision number
386 returned: always
387 type: str
388 sample: "17.0.2.10658"
389 serial:
390 description: Serial number of the unit
391 returned: always
392 type: str
393 sample: "FGVMEVYYQT3AB5352"
394 status:
395 description: Indication of the operation's result
396 returned: always
397 type: str
398 sample: "success"
399 vdom:
400 description: Virtual domain used
401 returned: always
402 type: str
403 sample: "root"
404 version:
405 description: Version of the FortiGate
406 returned: always
407 type: str
408 sample: "v5.6.3"
409 """
410 from ansible.module_utils.basic import AnsibleModule
411 from ansible.module_utils.connection import Connection
412 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
413 FortiOSHandler,
414 )
415 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
416 check_legacy_fortiosapi,
417 )
418 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
419 schema_to_module_spec,
420 )
421 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
422 check_schema_versioning,
423 )
424 from ansible_collections.fortinet.fortios.plugins.module_utils.fortimanager.common import (
425 FAIL_SOCKET_MSG,
426 )
427 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.data_post_processor import (
428 remove_invalid_fields,
429 )
430 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
431 is_same_comparison,
432 )
433 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
434 serialize,
435 )
436 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
437 find_current_values,
438 )
439 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
440 unify_data_format,
441 )
442
443
444 def filter_log_setting_data(json):
445 option_list = [
446 "anonymization_hash",
447 "brief_traffic_format",
448 "custom_log_fields",
449 "daemon_log",
450 "expolicy_implicit_log",
451 "extended_log",
452 "extended_utm_log",
453 "faz_override",
454 "fortiview_weekly_data",
455 "fwpolicy_implicit_log",
456 "fwpolicy6_implicit_log",
457 "local_in_allow",
458 "local_in_deny_broadcast",
459 "local_in_deny_unicast",
460 "local_in_policy_log",
461 "local_out",
462 "local_out_ioc_detection",
463 "log_invalid_packet",
464 "log_policy_comment",
465 "log_policy_name",
466 "log_user_in_upper",
467 "long_live_session_stat",
468 "neighbor_event",
469 "resolve_ip",
470 "resolve_port",
471 "rest_api_get",
472 "rest_api_performance",
473 "rest_api_set",
474 "syslog_override",
475 "user_anonymize",
476 "web_svc_perf",
477 "zone_name",
478 ]
479
480 json = remove_invalid_fields(json)
481 dictionary = {}
482
483 for attribute in option_list:
484 if attribute in json and json[attribute] is not None:
485 dictionary[attribute] = json[attribute]
486
487 return dictionary
488
489
490 def underscore_to_hyphen(data):
491 new_data = None
492 if isinstance(data, list):
493 new_data = []
494 for i, elem in enumerate(data):
495 new_data.append(underscore_to_hyphen(elem))
496 elif isinstance(data, dict):
497 new_data = {}
498 for k, v in data.items():
499 new_data[k.replace("_", "-")] = underscore_to_hyphen(v)
500 else:
501 return data
502 return new_data
503
504
505 def log_setting(data, fos, check_mode=False):
506
507 state = None
508 vdom = data["vdom"]
509 parameters = None
510 state = data.get("state", None)
511 log_setting_data = data["log_setting"]
512
513 filtered_data = filter_log_setting_data(log_setting_data)
514 converted_data = underscore_to_hyphen(filtered_data)
515
516 # check_mode starts from here
517 if check_mode:
518 diff = {
519 "before": "",
520 "after": filtered_data,
521 }
522 mkeyname = fos.get_mkeyname(None, None)
523 mkey = fos.get_mkey("log", "setting", filtered_data, vdom=vdom)
524 current_data = fos.get(
525 "log", "setting", vdom=vdom, mkey=mkey, parameters=parameters
526 )
527 is_existed = (
528 current_data
529 and current_data.get("http_status") == 200
530 and (
531 mkeyname
532 and isinstance(current_data.get("results"), list)
533 and len(current_data["results"]) > 0
534 or not mkeyname
535 and current_data["results"] # global object response
536 )
537 )
538
539 # 2. if it exists and the state is 'present' then compare current settings with desired
540 if state == "present" or state is True or state is None:
541 # for non global modules, mkeyname must exist and it's a new module when mkey is None
542 if mkeyname is not None and mkey is None:
543 return False, True, filtered_data, diff
544
545 # if mkey exists then compare each other
546 # record exits and they're matched or not
547 copied_filtered_data = filtered_data.copy()
548 copied_filtered_data.pop(mkeyname, None)
549 unified_filtered_data = unify_data_format(copied_filtered_data)
550
551 current_data_results = current_data.get("results", {})
552 current_config = (
553 current_data_results[0]
554 if mkeyname
555 and isinstance(current_data_results, list)
556 and len(current_data_results) > 0
557 else current_data_results
558 )
559 if is_existed:
560 unified_current_values = find_current_values(
561 unified_filtered_data,
562 unify_data_format(current_config),
563 )
564
565 is_same = is_same_comparison(
566 serialize(unified_current_values), serialize(unified_filtered_data)
567 )
568
569 return (
570 False,
571 not is_same,
572 filtered_data,
573 {"before": unified_current_values, "after": unified_filtered_data},
574 )
575
576 # record does not exist
577 return False, True, filtered_data, diff
578
579 if state == "absent":
580 if mkey is None:
581 return (
582 False,
583 False,
584 filtered_data,
585 {"before": current_data["results"][0], "after": ""},
586 )
587
588 if is_existed:
589 return (
590 False,
591 True,
592 filtered_data,
593 {"before": current_data["results"][0], "after": ""},
594 )
595 return False, False, filtered_data, {}
596
597 return True, False, {"reason: ": "Must provide state parameter"}, {}
598 # pass post processed data to member operations
599 # no need to do underscore_to_hyphen since do_member_operation handles it by itself
600 data_copy = data.copy()
601 data_copy["log_setting"] = filtered_data
602 fos.do_member_operation(
603 "log",
604 "setting",
605 data_copy,
606 )
607
608 return fos.set(
609 "log", "setting", data=converted_data, vdom=vdom, parameters=parameters
610 )
611
612
613 def is_successful_status(resp):
614 return (
615 "status" in resp
616 and resp["status"] == "success"
617 or "http_status" in resp
618 and resp["http_status"] == 200
619 or "http_method" in resp
620 and resp["http_method"] == "DELETE"
621 and resp["http_status"] == 404
622 )
623
624
625 def fortios_log(data, fos, check_mode):
626
627 if data["log_setting"]:
628 resp = log_setting(data, fos, check_mode)
629 else:
630 fos._module.fail_json(msg="missing task body: %s" % ("log_setting"))
631 if isinstance(resp, tuple) and len(resp) == 4:
632 return resp
633 return (
634 not is_successful_status(resp),
635 is_successful_status(resp)
636 and (resp["revision_changed"] if "revision_changed" in resp else True),
637 resp,
638 {},
639 )
640
641
642 versioned_schema = {
643 "v_range": [["v6.0.0", ""]],
644 "type": "dict",
645 "children": {
646 "resolve_ip": {
647 "v_range": [["v6.0.0", ""]],
648 "type": "string",
649 "options": [{"value": "enable"}, {"value": "disable"}],
650 },
651 "resolve_port": {
652 "v_range": [["v6.0.0", ""]],
653 "type": "string",
654 "options": [{"value": "enable"}, {"value": "disable"}],
655 },
656 "log_user_in_upper": {
657 "v_range": [["v6.0.0", ""]],
658 "type": "string",
659 "options": [{"value": "enable"}, {"value": "disable"}],
660 },
661 "fwpolicy_implicit_log": {
662 "v_range": [["v6.0.0", ""]],
663 "type": "string",
664 "options": [{"value": "enable"}, {"value": "disable"}],
665 },
666 "fwpolicy6_implicit_log": {
667 "v_range": [["v6.0.0", ""]],
668 "type": "string",
669 "options": [{"value": "enable"}, {"value": "disable"}],
670 },
671 "extended_log": {
672 "v_range": [["v7.4.0", ""]],
673 "type": "string",
674 "options": [{"value": "enable"}, {"value": "disable"}],
675 },
676 "local_in_allow": {
677 "v_range": [["v6.0.0", ""]],
678 "type": "string",
679 "options": [{"value": "enable"}, {"value": "disable"}],
680 },
681 "local_in_deny_unicast": {
682 "v_range": [["v6.0.0", ""]],
683 "type": "string",
684 "options": [{"value": "enable"}, {"value": "disable"}],
685 },
686 "local_in_deny_broadcast": {
687 "v_range": [["v6.0.0", ""]],
688 "type": "string",
689 "options": [{"value": "enable"}, {"value": "disable"}],
690 },
691 "local_in_policy_log": {
692 "v_range": [["v7.6.0", ""]],
693 "type": "string",
694 "options": [{"value": "enable"}, {"value": "disable"}],
695 },
696 "local_out": {
697 "v_range": [["v6.0.0", ""]],
698 "type": "string",
699 "options": [{"value": "enable"}, {"value": "disable"}],
700 },
701 "local_out_ioc_detection": {
702 "v_range": [["v7.2.0", ""]],
703 "type": "string",
704 "options": [{"value": "enable"}, {"value": "disable"}],
705 },
706 "daemon_log": {
707 "v_range": [["v6.0.0", ""]],
708 "type": "string",
709 "options": [{"value": "enable"}, {"value": "disable"}],
710 },
711 "neighbor_event": {
712 "v_range": [["v6.0.0", ""]],
713 "type": "string",
714 "options": [{"value": "enable"}, {"value": "disable"}],
715 },
716 "brief_traffic_format": {
717 "v_range": [["v6.0.0", ""]],
718 "type": "string",
719 "options": [{"value": "enable"}, {"value": "disable"}],
720 },
721 "user_anonymize": {
722 "v_range": [["v6.0.0", ""]],
723 "type": "string",
724 "options": [{"value": "enable"}, {"value": "disable"}],
725 },
726 "fortiview_weekly_data": {
727 "v_range": [["v6.0.0", "v7.4.1"], ["v7.4.3", ""]],
728 "type": "string",
729 "options": [{"value": "enable"}, {"value": "disable"}],
730 },
731 "expolicy_implicit_log": {
732 "v_range": [["v6.0.0", ""]],
733 "type": "string",
734 "options": [{"value": "enable"}, {"value": "disable"}],
735 },
736 "log_policy_comment": {
737 "v_range": [["v6.0.0", ""]],
738 "type": "string",
739 "options": [{"value": "enable"}, {"value": "disable"}],
740 },
741 "faz_override": {
742 "v_range": [["v6.2.0", ""]],
743 "type": "string",
744 "options": [{"value": "enable"}, {"value": "disable"}],
745 },
746 "syslog_override": {
747 "v_range": [["v6.2.0", ""]],
748 "type": "string",
749 "options": [{"value": "enable"}, {"value": "disable"}],
750 },
751 "rest_api_set": {
752 "v_range": [["v7.0.4", ""]],
753 "type": "string",
754 "options": [{"value": "enable"}, {"value": "disable"}],
755 },
756 "rest_api_get": {
757 "v_range": [["v7.0.4", ""]],
758 "type": "string",
759 "options": [{"value": "enable"}, {"value": "disable"}],
760 },
761 "rest_api_performance": {
762 "v_range": [["v7.6.5", ""]],
763 "type": "string",
764 "options": [{"value": "enable"}, {"value": "disable"}],
765 },
766 "long_live_session_stat": {
767 "v_range": [["v7.4.2", ""]],
768 "type": "string",
769 "options": [{"value": "enable"}, {"value": "disable"}],
770 },
771 "extended_utm_log": {
772 "v_range": [["v7.6.0", ""]],
773 "type": "string",
774 "options": [{"value": "enable"}, {"value": "disable"}],
775 },
776 "zone_name": {
777 "v_range": [["v7.6.4", ""]],
778 "type": "string",
779 "options": [{"value": "enable"}, {"value": "disable"}],
780 },
781 "web_svc_perf": {
782 "v_range": [["v7.6.5", ""]],
783 "type": "string",
784 "options": [{"value": "enable"}, {"value": "disable"}],
785 },
786 "custom_log_fields": {
787 "type": "list",
788 "elements": "dict",
789 "children": {
790 "field_id": {
791 "v_range": [["v6.0.0", ""]],
792 "type": "string",
793 "required": True,
794 }
795 },
796 "v_range": [["v6.0.0", ""]],
797 },
798 "anonymization_hash": {"v_range": [["v7.0.2", ""]], "type": "string"},
799 "log_invalid_packet": {
800 "v_range": [["v6.0.0", "v7.2.4"]],
801 "type": "string",
802 "options": [{"value": "enable"}, {"value": "disable"}],
803 },
804 "log_policy_name": {
805 "v_range": [["v6.0.0", "v6.2.7"]],
806 "type": "string",
807 "options": [{"value": "enable"}, {"value": "disable"}],
808 },
809 },
810 }
811
812
813 def main():
814 module_spec = schema_to_module_spec(versioned_schema)
815 mkeyname = None
816 fields = {
817 "access_token": {"required": False, "type": "str", "no_log": True},
818 "enable_log": {"required": False, "type": "bool", "default": False},
819 "vdom": {"required": False, "type": "str", "default": "root"},
820 "member_path": {"required": False, "type": "str"},
821 "member_state": {
822 "type": "str",
823 "required": False,
824 "choices": ["present", "absent"],
825 },
826 "log_setting": {
827 "required": False,
828 "type": "dict",
829 "default": None,
830 "options": {},
831 },
832 }
833 for attribute_name in module_spec["options"]:
834 fields["log_setting"]["options"][attribute_name] = module_spec["options"][
835 attribute_name
836 ]
837 if mkeyname and mkeyname == attribute_name:
838 fields["log_setting"]["options"][attribute_name]["required"] = True
839
840 module = AnsibleModule(argument_spec=fields, supports_check_mode=True)
841 check_legacy_fortiosapi(module)
842
843 is_error = False
844 has_changed = False
845 result = None
846 diff = None
847
848 versions_check_result = None
849 if module._socket_path:
850 connection = Connection(module._socket_path)
851 if "access_token" in module.params:
852 connection.set_custom_option("access_token", module.params["access_token"])
853
854 if "enable_log" in module.params:
855 connection.set_custom_option("enable_log", module.params["enable_log"])
856 else:
857 connection.set_custom_option("enable_log", False)
858 fos = FortiOSHandler(connection, module, mkeyname, admin_passwd_header=False)
859 versions_check_result = check_schema_versioning(
860 fos, versioned_schema, "log_setting"
861 )
862
863 is_error, has_changed, result, diff = fortios_log(
864 module.params, fos, module.check_mode
865 )
866
867 else:
868 module.fail_json(**FAIL_SOCKET_MSG)
869
870 if versions_check_result and versions_check_result["matched"] is False:
871 module.warn(
872 "Ansible has detected version mismatch between FortOS system and your playbook, see more details by specifying option -vvv"
873 )
874
875 if not is_error:
876 if versions_check_result and versions_check_result["matched"] is False:
877 module.exit_json(
878 changed=has_changed,
879 version_check_warning=versions_check_result,
880 meta=result,
881 diff=diff,
882 )
883 else:
884 module.exit_json(changed=has_changed, meta=result, diff=diff)
885 else:
886 if versions_check_result and versions_check_result["matched"] is False:
887 module.fail_json(
888 msg="Error in repo",
889 version_check_warning=versions_check_result,
890 meta=result,
891 )
892 else:
893 module.fail_json(msg="Error in repo", meta=result)
894
895
896 if __name__ == "__main__":
897 main()