Debian Codegraph @

ansible_collections/fortinet/fortios/plugins/modules/fortios_alertemail_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_alertemail_setting
23 short_description: Configure alert email 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 alertemail 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 alertemail_setting:
80 description:
81 - Configure alert email settings.
82 default: null
83 type: dict
84 suboptions:
85 admin_login_logs:
86 description:
87 - Enable/disable administrator login/logout logs in alert email.
88 type: str
89 choices:
90 - 'enable'
91 - 'disable'
92 alert_interval:
93 description:
94 - Alert alert interval in minutes.
95 type: int
96 amc_interface_bypass_mode:
97 description:
98 - Enable/disable Fortinet Advanced Mezzanine Card (AMC) interface bypass mode logs in alert email.
99 type: str
100 choices:
101 - 'enable'
102 - 'disable'
103 antivirus_logs:
104 description:
105 - Enable/disable antivirus logs in alert email.
106 type: str
107 choices:
108 - 'enable'
109 - 'disable'
110 configuration_changes_logs:
111 description:
112 - Enable/disable configuration change logs in alert email.
113 type: str
114 choices:
115 - 'enable'
116 - 'disable'
117 critical_interval:
118 description:
119 - Critical alert interval in minutes.
120 type: int
121 debug_interval:
122 description:
123 - Debug alert interval in minutes.
124 type: int
125 email_interval:
126 description:
127 - Interval between sending alert emails (1 - 99999 min).
128 type: int
129 emergency_interval:
130 description:
131 - Emergency alert interval in minutes.
132 type: int
133 error_interval:
134 description:
135 - Error alert interval in minutes.
136 type: int
137 FDS_license_expiring_days:
138 description:
139 - Number of days to send alert email prior to FortiGuard license expiration (1 - 100 days).
140 type: int
141 FDS_license_expiring_warning:
142 description:
143 - Enable/disable FortiGuard license expiration warnings in alert email.
144 type: str
145 choices:
146 - 'enable'
147 - 'disable'
148 FDS_update_logs:
149 description:
150 - Enable/disable FortiGuard update logs in alert email.
151 type: str
152 choices:
153 - 'enable'
154 - 'disable'
155 filter_mode:
156 description:
157 - How to filter log messages that are sent to alert emails.
158 type: str
159 choices:
160 - 'category'
161 - 'threshold'
162 FIPS_CC_errors:
163 description:
164 - Enable/disable FIPS and Common Criteria error logs in alert email.
165 type: str
166 choices:
167 - 'enable'
168 - 'disable'
169 firewall_authentication_failure_logs:
170 description:
171 - Enable/disable firewall authentication failure logs in alert email.
172 type: str
173 choices:
174 - 'enable'
175 - 'disable'
176 fortiguard_log_quota_warning:
177 description:
178 - Enable/disable FortiCloud log quota warnings in alert email.
179 type: str
180 choices:
181 - 'enable'
182 - 'disable'
183 FSSO_disconnect_logs:
184 description:
185 - Enable/disable logging of FSSO collector agent disconnect.
186 type: str
187 choices:
188 - 'enable'
189 - 'disable'
190 HA_logs:
191 description:
192 - Enable/disable HA logs in alert email.
193 type: str
194 choices:
195 - 'enable'
196 - 'disable'
197 information_interval:
198 description:
199 - Information alert interval in minutes.
200 type: int
201 IPS_logs:
202 description:
203 - Enable/disable IPS logs in alert email.
204 type: str
205 choices:
206 - 'enable'
207 - 'disable'
208 IPsec_errors_logs:
209 description:
210 - Enable/disable IPsec error logs in alert email.
211 type: str
212 choices:
213 - 'enable'
214 - 'disable'
215 local_disk_usage:
216 description:
217 - Disk usage percentage at which to send alert email (1 - 99 percent).
218 type: int
219 log_disk_usage_warning:
220 description:
221 - Enable/disable disk usage warnings in alert email.
222 type: str
223 choices:
224 - 'enable'
225 - 'disable'
226 mailto1:
227 description:
228 - Email address to send alert email to (usually a system administrator) (max. 63 characters).
229 type: str
230 mailto2:
231 description:
232 - Optional second email address to send alert email to (max. 63 characters).
233 type: str
234 mailto3:
235 description:
236 - Optional third email address to send alert email to (max. 63 characters).
237 type: str
238 notification_interval:
239 description:
240 - Notification alert interval in minutes.
241 type: int
242 PPP_errors_logs:
243 description:
244 - Enable/disable PPP error logs in alert email.
245 type: str
246 choices:
247 - 'enable'
248 - 'disable'
249 severity:
250 description:
251 - Lowest severity level to log.
252 type: str
253 choices:
254 - 'emergency'
255 - 'alert'
256 - 'critical'
257 - 'error'
258 - 'warning'
259 - 'notification'
260 - 'information'
261 - 'debug'
262 ssh_logs:
263 description:
264 - Enable/disable SSH logs in alert email.
265 type: str
266 choices:
267 - 'enable'
268 - 'disable'
269 sslvpn_authentication_errors_logs:
270 description:
271 - Enable/disable Agentless VPN authentication error logs in alert email.
272 type: str
273 choices:
274 - 'enable'
275 - 'disable'
276 username:
277 description:
278 - 'Name that appears in the From: field of alert emails (max. 63 characters).'
279 type: str
280 violation_traffic_logs:
281 description:
282 - Enable/disable violation traffic logs in alert email.
283 type: str
284 choices:
285 - 'enable'
286 - 'disable'
287 warning_interval:
288 description:
289 - Warning alert interval in minutes.
290 type: int
291 webfilter_logs:
292 description:
293 - Enable/disable web filter logs in alert email.
294 type: str
295 choices:
296 - 'enable'
297 - 'disable'
298 """
299
300 EXAMPLES = """
301 - name: Configure alert email settings.
302 fortinet.fortios.fortios_alertemail_setting:
303 vdom: "{{ vdom }}"
304 alertemail_setting:
305 admin_login_logs: "enable"
306 alert_interval: "2"
307 amc_interface_bypass_mode: "enable"
308 antivirus_logs: "enable"
309 configuration_changes_logs: "enable"
310 critical_interval: "3"
311 debug_interval: "60"
312 email_interval: "5"
313 emergency_interval: "1"
314 error_interval: "5"
315 FDS_license_expiring_days: "15"
316 FDS_license_expiring_warning: "enable"
317 FDS_update_logs: "enable"
318 filter_mode: "category"
319 FIPS_CC_errors: "enable"
320 firewall_authentication_failure_logs: "enable"
321 fortiguard_log_quota_warning: "enable"
322 FSSO_disconnect_logs: "enable"
323 HA_logs: "enable"
324 information_interval: "30"
325 IPS_logs: "enable"
326 IPsec_errors_logs: "enable"
327 local_disk_usage: "75"
328 log_disk_usage_warning: "enable"
329 mailto1: "<your_own_value>"
330 mailto2: "<your_own_value>"
331 mailto3: "<your_own_value>"
332 notification_interval: "20"
333 PPP_errors_logs: "enable"
334 severity: "emergency"
335 ssh_logs: "enable"
336 sslvpn_authentication_errors_logs: "enable"
337 username: "<your_own_value>"
338 violation_traffic_logs: "enable"
339 warning_interval: "10"
340 webfilter_logs: "enable"
341 """
342
343 RETURN = """
344 build:
345 description: Build number of the fortigate image
346 returned: always
347 type: str
348 sample: '1547'
349 http_method:
350 description: Last method used to provision the content into FortiGate
351 returned: always
352 type: str
353 sample: 'PUT'
354 http_status:
355 description: Last result given by FortiGate on last operation applied
356 returned: always
357 type: str
358 sample: "200"
359 mkey:
360 description: Master key (id) used in the last call to FortiGate
361 returned: success
362 type: str
363 sample: "id"
364 name:
365 description: Name of the table used to fulfill the request
366 returned: always
367 type: str
368 sample: "urlfilter"
369 path:
370 description: Path of the table used to fulfill the request
371 returned: always
372 type: str
373 sample: "webfilter"
374 revision:
375 description: Internal revision number
376 returned: always
377 type: str
378 sample: "17.0.2.10658"
379 serial:
380 description: Serial number of the unit
381 returned: always
382 type: str
383 sample: "FGVMEVYYQT3AB5352"
384 status:
385 description: Indication of the operation's result
386 returned: always
387 type: str
388 sample: "success"
389 vdom:
390 description: Virtual domain used
391 returned: always
392 type: str
393 sample: "root"
394 version:
395 description: Version of the FortiGate
396 returned: always
397 type: str
398 sample: "v5.6.3"
399 """
400 from ansible.module_utils.basic import AnsibleModule
401 from ansible.module_utils.connection import Connection
402 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
403 FortiOSHandler,
404 )
405 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
406 check_legacy_fortiosapi,
407 )
408 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
409 schema_to_module_spec,
410 )
411 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.fortios import (
412 check_schema_versioning,
413 )
414 from ansible_collections.fortinet.fortios.plugins.module_utils.fortimanager.common import (
415 FAIL_SOCKET_MSG,
416 )
417 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.data_post_processor import (
418 remove_invalid_fields,
419 )
420 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
421 is_same_comparison,
422 )
423 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
424 serialize,
425 )
426 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
427 find_current_values,
428 )
429 from ansible_collections.fortinet.fortios.plugins.module_utils.fortios.comparison import (
430 unify_data_format,
431 )
432
433
434 def filter_alertemail_setting_data(json):
435 option_list = [
436 "admin_login_logs",
437 "alert_interval",
438 "amc_interface_bypass_mode",
439 "antivirus_logs",
440 "configuration_changes_logs",
441 "critical_interval",
442 "debug_interval",
443 "email_interval",
444 "emergency_interval",
445 "error_interval",
446 "FDS_license_expiring_days",
447 "FDS_license_expiring_warning",
448 "FDS_update_logs",
449 "filter_mode",
450 "FIPS_CC_errors",
451 "firewall_authentication_failure_logs",
452 "fortiguard_log_quota_warning",
453 "FSSO_disconnect_logs",
454 "HA_logs",
455 "information_interval",
456 "IPS_logs",
457 "IPsec_errors_logs",
458 "local_disk_usage",
459 "log_disk_usage_warning",
460 "mailto1",
461 "mailto2",
462 "mailto3",
463 "notification_interval",
464 "PPP_errors_logs",
465 "severity",
466 "ssh_logs",
467 "sslvpn_authentication_errors_logs",
468 "username",
469 "violation_traffic_logs",
470 "warning_interval",
471 "webfilter_logs",
472 ]
473
474 json = remove_invalid_fields(json)
475 dictionary = {}
476
477 for attribute in option_list:
478 if attribute in json and json[attribute] is not None:
479 dictionary[attribute] = json[attribute]
480
481 return dictionary
482
483
484 def underscore_to_hyphen(data):
485 new_data = None
486 if isinstance(data, list):
487 new_data = []
488 for i, elem in enumerate(data):
489 new_data.append(underscore_to_hyphen(elem))
490 elif isinstance(data, dict):
491 new_data = {}
492 for k, v in data.items():
493 new_data[k.replace("_", "-")] = underscore_to_hyphen(v)
494 else:
495 return data
496 return new_data
497
498
499 def alertemail_setting(data, fos, check_mode=False):
500
501 state = None
502 vdom = data["vdom"]
503 parameters = None
504 state = data.get("state", None)
505 alertemail_setting_data = data["alertemail_setting"]
506
507 filtered_data = filter_alertemail_setting_data(alertemail_setting_data)
508 converted_data = underscore_to_hyphen(filtered_data)
509
510 # check_mode starts from here
511 if check_mode:
512 diff = {
513 "before": "",
514 "after": filtered_data,
515 }
516 mkeyname = fos.get_mkeyname(None, None)
517 mkey = fos.get_mkey("alertemail", "setting", filtered_data, vdom=vdom)
518 current_data = fos.get(
519 "alertemail", "setting", vdom=vdom, mkey=mkey, parameters=parameters
520 )
521 is_existed = (
522 current_data
523 and current_data.get("http_status") == 200
524 and (
525 mkeyname
526 and isinstance(current_data.get("results"), list)
527 and len(current_data["results"]) > 0
528 or not mkeyname
529 and current_data["results"] # global object response
530 )
531 )
532
533 # 2. if it exists and the state is 'present' then compare current settings with desired
534 if state == "present" or state is True or state is None:
535 # for non global modules, mkeyname must exist and it's a new module when mkey is None
536 if mkeyname is not None and mkey is None:
537 return False, True, filtered_data, diff
538
539 # if mkey exists then compare each other
540 # record exits and they're matched or not
541 copied_filtered_data = filtered_data.copy()
542 copied_filtered_data.pop(mkeyname, None)
543 unified_filtered_data = unify_data_format(copied_filtered_data)
544
545 current_data_results = current_data.get("results", {})
546 current_config = (
547 current_data_results[0]
548 if mkeyname
549 and isinstance(current_data_results, list)
550 and len(current_data_results) > 0
551 else current_data_results
552 )
553 if is_existed:
554 unified_current_values = find_current_values(
555 unified_filtered_data,
556 unify_data_format(current_config),
557 )
558
559 is_same = is_same_comparison(
560 serialize(unified_current_values), serialize(unified_filtered_data)
561 )
562
563 return (
564 False,
565 not is_same,
566 filtered_data,
567 {"before": unified_current_values, "after": unified_filtered_data},
568 )
569
570 # record does not exist
571 return False, True, filtered_data, diff
572
573 if state == "absent":
574 if mkey is None:
575 return (
576 False,
577 False,
578 filtered_data,
579 {"before": current_data["results"][0], "after": ""},
580 )
581
582 if is_existed:
583 return (
584 False,
585 True,
586 filtered_data,
587 {"before": current_data["results"][0], "after": ""},
588 )
589 return False, False, filtered_data, {}
590
591 return True, False, {"reason: ": "Must provide state parameter"}, {}
592 # pass post processed data to member operations
593 # no need to do underscore_to_hyphen since do_member_operation handles it by itself
594 data_copy = data.copy()
595 data_copy["alertemail_setting"] = filtered_data
596 fos.do_member_operation(
597 "alertemail",
598 "setting",
599 data_copy,
600 )
601
602 return fos.set(
603 "alertemail", "setting", data=converted_data, vdom=vdom, parameters=parameters
604 )
605
606
607 def is_successful_status(resp):
608 return (
609 "status" in resp
610 and resp["status"] == "success"
611 or "http_status" in resp
612 and resp["http_status"] == 200
613 or "http_method" in resp
614 and resp["http_method"] == "DELETE"
615 and resp["http_status"] == 404
616 )
617
618
619 def fortios_alertemail(data, fos, check_mode):
620
621 if data["alertemail_setting"]:
622 resp = alertemail_setting(data, fos, check_mode)
623 else:
624 fos._module.fail_json(msg="missing task body: %s" % ("alertemail_setting"))
625 if isinstance(resp, tuple) and len(resp) == 4:
626 return resp
627 return (
628 not is_successful_status(resp),
629 is_successful_status(resp)
630 and (resp["revision_changed"] if "revision_changed" in resp else True),
631 resp,
632 {},
633 )
634
635
636 versioned_schema = {
637 "v_range": [["v6.0.0", ""]],
638 "type": "dict",
639 "children": {
640 "username": {"v_range": [["v6.0.0", ""]], "type": "string"},
641 "mailto1": {"v_range": [["v6.0.0", ""]], "type": "string"},
642 "mailto2": {"v_range": [["v6.0.0", ""]], "type": "string"},
643 "mailto3": {"v_range": [["v6.0.0", ""]], "type": "string"},
644 "filter_mode": {
645 "v_range": [["v6.0.0", ""]],
646 "type": "string",
647 "options": [{"value": "category"}, {"value": "threshold"}],
648 },
649 "email_interval": {"v_range": [["v6.0.0", ""]], "type": "integer"},
650 "IPS_logs": {
651 "v_range": [["v6.0.0", ""]],
652 "type": "string",
653 "options": [{"value": "enable"}, {"value": "disable"}],
654 },
655 "firewall_authentication_failure_logs": {
656 "v_range": [["v6.0.0", ""]],
657 "type": "string",
658 "options": [{"value": "enable"}, {"value": "disable"}],
659 },
660 "HA_logs": {
661 "v_range": [["v6.0.0", ""]],
662 "type": "string",
663 "options": [{"value": "enable"}, {"value": "disable"}],
664 },
665 "IPsec_errors_logs": {
666 "v_range": [["v6.0.0", ""]],
667 "type": "string",
668 "options": [{"value": "enable"}, {"value": "disable"}],
669 },
670 "FDS_update_logs": {
671 "v_range": [["v6.0.0", ""]],
672 "type": "string",
673 "options": [{"value": "enable"}, {"value": "disable"}],
674 },
675 "PPP_errors_logs": {
676 "v_range": [["v6.0.0", ""]],
677 "type": "string",
678 "options": [{"value": "enable"}, {"value": "disable"}],
679 },
680 "sslvpn_authentication_errors_logs": {
681 "v_range": [["v6.0.0", ""]],
682 "type": "string",
683 "options": [{"value": "enable"}, {"value": "disable"}],
684 },
685 "antivirus_logs": {
686 "v_range": [["v6.0.0", ""]],
687 "type": "string",
688 "options": [{"value": "enable"}, {"value": "disable"}],
689 },
690 "webfilter_logs": {
691 "v_range": [["v6.0.0", ""]],
692 "type": "string",
693 "options": [{"value": "enable"}, {"value": "disable"}],
694 },
695 "configuration_changes_logs": {
696 "v_range": [["v6.0.0", ""]],
697 "type": "string",
698 "options": [{"value": "enable"}, {"value": "disable"}],
699 },
700 "violation_traffic_logs": {
701 "v_range": [["v6.0.0", ""]],
702 "type": "string",
703 "options": [{"value": "enable"}, {"value": "disable"}],
704 },
705 "admin_login_logs": {
706 "v_range": [["v6.0.0", ""]],
707 "type": "string",
708 "options": [{"value": "enable"}, {"value": "disable"}],
709 },
710 "FDS_license_expiring_warning": {
711 "v_range": [["v6.0.0", ""]],
712 "type": "string",
713 "options": [{"value": "enable"}, {"value": "disable"}],
714 },
715 "log_disk_usage_warning": {
716 "v_range": [["v6.0.0", ""]],
717 "type": "string",
718 "options": [{"value": "enable"}, {"value": "disable"}],
719 },
720 "fortiguard_log_quota_warning": {
721 "v_range": [["v6.0.0", ""]],
722 "type": "string",
723 "options": [{"value": "enable"}, {"value": "disable"}],
724 },
725 "amc_interface_bypass_mode": {
726 "v_range": [["v6.0.0", ""]],
727 "type": "string",
728 "options": [{"value": "enable"}, {"value": "disable"}],
729 },
730 "FIPS_CC_errors": {
731 "v_range": [["v6.0.0", ""]],
732 "type": "string",
733 "options": [{"value": "enable"}, {"value": "disable"}],
734 },
735 "FSSO_disconnect_logs": {
736 "v_range": [["v6.0.0", ""]],
737 "type": "string",
738 "options": [{"value": "enable"}, {"value": "disable"}],
739 },
740 "ssh_logs": {
741 "v_range": [["v6.0.0", ""]],
742 "type": "string",
743 "options": [{"value": "enable"}, {"value": "disable"}],
744 },
745 "local_disk_usage": {"v_range": [["v6.0.0", ""]], "type": "integer"},
746 "emergency_interval": {"v_range": [["v6.0.0", ""]], "type": "integer"},
747 "alert_interval": {"v_range": [["v6.0.0", ""]], "type": "integer"},
748 "critical_interval": {"v_range": [["v6.0.0", ""]], "type": "integer"},
749 "error_interval": {"v_range": [["v6.0.0", ""]], "type": "integer"},
750 "warning_interval": {"v_range": [["v6.0.0", ""]], "type": "integer"},
751 "notification_interval": {"v_range": [["v6.0.0", ""]], "type": "integer"},
752 "information_interval": {"v_range": [["v6.0.0", ""]], "type": "integer"},
753 "debug_interval": {"v_range": [["v6.0.0", ""]], "type": "integer"},
754 "severity": {
755 "v_range": [["v6.0.0", ""]],
756 "type": "string",
757 "options": [
758 {"value": "emergency"},
759 {"value": "alert"},
760 {"value": "critical"},
761 {"value": "error"},
762 {"value": "warning"},
763 {"value": "notification"},
764 {"value": "information"},
765 {"value": "debug"},
766 ],
767 },
768 "FDS_license_expiring_days": {
769 "v_range": [["v6.0.0", "v7.2.4"]],
770 "type": "integer",
771 },
772 },
773 }
774
775
776 def main():
777 module_spec = schema_to_module_spec(versioned_schema)
778 mkeyname = None
779 fields = {
780 "access_token": {"required": False, "type": "str", "no_log": True},
781 "enable_log": {"required": False, "type": "bool", "default": False},
782 "vdom": {"required": False, "type": "str", "default": "root"},
783 "member_path": {"required": False, "type": "str"},
784 "member_state": {
785 "type": "str",
786 "required": False,
787 "choices": ["present", "absent"],
788 },
789 "alertemail_setting": {
790 "required": False,
791 "type": "dict",
792 "default": None,
793 "options": {},
794 },
795 }
796 for attribute_name in module_spec["options"]:
797 fields["alertemail_setting"]["options"][attribute_name] = module_spec[
798 "options"
799 ][attribute_name]
800 if mkeyname and mkeyname == attribute_name:
801 fields["alertemail_setting"]["options"][attribute_name]["required"] = True
802
803 module = AnsibleModule(argument_spec=fields, supports_check_mode=True)
804 check_legacy_fortiosapi(module)
805
806 is_error = False
807 has_changed = False
808 result = None
809 diff = None
810
811 versions_check_result = None
812 if module._socket_path:
813 connection = Connection(module._socket_path)
814 if "access_token" in module.params:
815 connection.set_custom_option("access_token", module.params["access_token"])
816
817 if "enable_log" in module.params:
818 connection.set_custom_option("enable_log", module.params["enable_log"])
819 else:
820 connection.set_custom_option("enable_log", False)
821 fos = FortiOSHandler(connection, module, mkeyname, admin_passwd_header=False)
822 versions_check_result = check_schema_versioning(
823 fos, versioned_schema, "alertemail_setting"
824 )
825
826 is_error, has_changed, result, diff = fortios_alertemail(
827 module.params, fos, module.check_mode
828 )
829
830 else:
831 module.fail_json(**FAIL_SOCKET_MSG)
832
833 if versions_check_result and versions_check_result["matched"] is False:
834 module.warn(
835 "Ansible has detected version mismatch between FortOS system and your playbook, see more details by specifying option -vvv"
836 )
837
838 if not is_error:
839 if versions_check_result and versions_check_result["matched"] is False:
840 module.exit_json(
841 changed=has_changed,
842 version_check_warning=versions_check_result,
843 meta=result,
844 diff=diff,
845 )
846 else:
847 module.exit_json(changed=has_changed, meta=result, diff=diff)
848 else:
849 if versions_check_result and versions_check_result["matched"] is False:
850 module.fail_json(
851 msg="Error in repo",
852 version_check_warning=versions_check_result,
853 meta=result,
854 )
855 else:
856 module.fail_json(msg="Error in repo", meta=result)
857
858
859 if __name__ == "__main__":
860 main()