Debian Codegraph @

ansible_collections/fortinet/fortimanager/plugins/modules/fmgr_system_alertevent.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_system_alertevent
15 short_description: Alert events.
16 version_added: "2.0.0"
17 extends_documentation_fragment:
18 - fortinet.fortimanager.general
19 - fortinet.fortimanager.general.full_crud
20 options:
21 system_alertevent:
22 description: The top level parameters set.
23 required: false
24 type: dict
25 suboptions:
26 alert_destination:
27 aliases: ['alert-destination']
28 type: list
29 elements: dict
30 description: Alert destination.
31 suboptions:
32 from:
33 type: str
34 description: Sender email address to use in alert emails.
35 smtp_name:
36 aliases: ['smtp-name']
37 type: str
38 description: SMTP server name.
39 snmp_name:
40 aliases: ['snmp-name']
41 type: str
42 description: SNMP trap name.
43 syslog_name:
44 aliases: ['syslog-name']
45 type: str
46 description: Syslog server name.
47 to:
48 type: str
49 description: Recipient email address to use in alert emails.
50 type:
51 type: str
52 description:
53 - Destination type.
54 - mail - Send email alert.
55 - snmp - Send SNMP trap.
56 - syslog - Send syslog message.
57 choices: ['mail', 'snmp', 'syslog']
58 enable_generic_text:
59 aliases: ['enable-generic-text']
60 type: list
61 elements: str
62 description:
63 - Enable/disable generic text match.
64 - enable - Enable setting.
65 - disable - Disable setting.
66 choices: ['enable', 'disable']
67 enable_severity_filter:
68 aliases: ['enable-severity-filter']
69 type: list
70 elements: str
71 description:
72 - Enable/disable alert severity filter.
73 - enable - Enable setting.
74 - disable - Disable setting.
75 choices: ['enable', 'disable']
76 event_time_period:
77 aliases: ['event-time-period']
78 type: str
79 description:
80 - Time period
81 - '0.'
82 - 1 - 1 hour.
83 - 3 - 3 hours.
84 - 6 - 6 hours.
85 - 12 - 12 hours.
86 - 24 - 1 day.
87 - 72 - 3 days.
88 - 168 - 1 week.
89 choices: ['0.5', '1', '3', '6', '12', '24', '72', '168']
90 generic_text:
91 aliases: ['generic-text']
92 type: str
93 description: Text that must be contained in a log to trigger alert.
94 name:
95 type: str
96 description: Alert name.
97 required: true
98 num_events:
99 aliases: ['num-events']
100 type: str
101 description:
102 - Minimum number of events required within time period.
103 - 1 - 1 event.
104 - 5 - 5 events.
105 - 10 - 10 events.
106 - 50 - 50 events.
107 - 100 - 100 events.
108 choices: ['1', '5', '10', '50', '100']
109 severity_filter:
110 aliases: ['severity-filter']
111 type: str
112 description:
113 - Required log severity to trigger alert.
114 - high - High level alert.
115 - medium-high - Medium-high level alert.
116 - medium - Medium level alert.
117 - medium-low - Medium-low level alert.
118 - low - Low level alert.
119 choices: ['high', 'medium-high', 'medium', 'medium-low', 'low']
120 severity_level_comp:
121 aliases: ['severity-level-comp']
122 type: list
123 elements: str
124 description: Log severity threshold comparison criterion.
125 choices: ['>=', '=', '<=']
126 severity_level_logs:
127 aliases: ['severity-level-logs']
128 type: list
129 elements: str
130 description:
131 - Log severity threshold level.
132 - no-check - Do not check severity level for this log type.
133 - information - Information level.
134 - notify - Notify level.
135 - warning - Warning level.
136 - error - Error level.
137 - critical - Critical level.
138 - alert - Alert level.
139 - emergency - Emergency level.
140 choices: ['no-check', 'information', 'notify', 'warning', 'error', 'critical',
141 'alert', 'emergency']
142 '''
143
144 EXAMPLES = '''
145 - name: Example playbook
146 hosts: fortimanagers
147 gather_facts: false
148 connection: httpapi
149 vars:
150 ansible_httpapi_use_ssl: true
151 ansible_httpapi_validate_certs: false
152 ansible_httpapi_port: 443
153 tasks:
154 - name: Alert events.
155 fortinet.fortimanager.fmgr_system_alertevent:
156 bypass_validation: false
157 state: present
158 system_alertevent:
159 enable_generic_text:
160 - enable
161 - disable
162 enable_severity_filter:
163 - enable
164 - disable
165 event_time_period: 1 # <value in [0.5, 1, 3, ...]>
166 name: ansible-test-sysalert
167 num_events: 1 # <value in [1, 5, 10, ...]>
168 severity_filter: high # <value in [high, medium-high, medium, ...]>
169 # severity_level_comp:
170 # - <=
171 severity_level_logs:
172 - no-check
173 - information
174 - notify
175 - warning
176 - error
177 - critical
178 - alert
179 - emergency
180
181 - name: Gathering fortimanager facts
182 hosts: fortimanagers
183 gather_facts: false
184 connection: httpapi
185 vars:
186 ansible_httpapi_use_ssl: true
187 ansible_httpapi_validate_certs: false
188 ansible_httpapi_port: 443
189 tasks:
190 - name: Retrieve all the alert events
191 fortinet.fortimanager.fmgr_fact:
192 facts:
193 selector: "system_alertevent"
194 params:
195 alert_event: "your_value"
196 '''
197
198 RETURN = '''
199 meta:
200 description: The result of the request.
201 type: dict
202 returned: always
203 contains:
204 request_url:
205 description: The full url requested.
206 returned: always
207 type: str
208 sample: /sys/login/user
209 response_code:
210 description: The status of api request.
211 returned: always
212 type: int
213 sample: 0
214 response_data:
215 description: The api response.
216 type: list
217 returned: always
218 response_message:
219 description: The descriptive message of the api response.
220 type: str
221 returned: always
222 sample: OK.
223 system_information:
224 description: The information of the target system.
225 type: dict
226 returned: always
227 rc:
228 description: The status the request.
229 type: int
230 returned: always
231 sample: 0
232 version_check_warning:
233 description: Warning if the parameters used in the playbook are not supported by the current FortiManager version.
234 type: list
235 returned: complex
236 '''
237 from ansible.module_utils.basic import AnsibleModule
238 from ansible.module_utils.connection import Connection
239 from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass
240 from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec
241
242
243 def main():
244 urls_list = [
245 '/cli/global/system/alert-event'
246 ]
247 module_arg_spec = {
248 'system_alertevent': {
249 'type': 'dict', 'v_range': [['6.0.0', '']],
250 'options': {
251 'alert-destination': {
252 'type': 'list',
253 'options': {
254 'from': {'type': 'str'},
255 'smtp-name': {'type': 'str'},
256 'snmp-name': {'type': 'str'},
257 'syslog-name': {'type': 'str'},
258 'to': {'type': 'str'},
259 'type': {'choices': ['mail', 'snmp', 'syslog'], 'type': 'str'}
260 },
261 'elements': 'dict'
262 },
263 'enable-generic-text': {'type': 'list', 'choices': ['enable', 'disable'], 'elements': 'str'},
264 'enable-severity-filter': {'type': 'list', 'choices': ['enable', 'disable'], 'elements': 'str'},
265 'event-time-period': {'choices': ['0.5', '1', '3', '6', '12', '24', '72', '168'], 'type': 'str'},
266 'generic-text': {'type': 'str'},
267 'name': {'required': True, 'type': 'str'},
268 'num-events': {'choices': ['1', '5', '10', '50', '100'], 'type': 'str'},
269 'severity-filter': {'choices': ['high', 'medium-high', 'medium', 'medium-low', 'low'], 'type': 'str'},
270 'severity-level-comp': {'type': 'list', 'choices': ['>=', '=', '<='], 'elements': 'str'},
271 'severity-level-logs': {
272 'type': 'list',
273 'choices': ['no-check', 'information', 'notify', 'warning', 'error', 'critical', 'alert', 'emergency'],
274 'elements': 'str'
275 }
276 }
277 }
278 }
279
280 module_option_spec = get_module_arg_spec('full crud')
281 module_arg_spec.update(module_option_spec)
282 check_galaxy_version(module_arg_spec)
283 module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'system_alertevent'),
284 supports_check_mode=True)
285 if not module._socket_path:
286 module.fail_json(msg='MUST RUN IN HTTPAPI MODE')
287 connection = Connection(module._socket_path)
288 fmgr = NAPIManager('full crud', module_arg_spec, urls_list,
289 'name', 'data', module, connection)
290 fmgr.process_crud()
291 module.exit_json(meta=module.params)
292
293
294 if __name__ == '__main__':
295 main()