Debian Codegraph @

ansible_collections/fortinet/fortimanager/plugins/modules/fmgr_pkg_firewall_dospolicy.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_pkg_firewall_dospolicy
15 short_description: Configure IPv4 DoS policies.
16 version_added: "2.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 pkg:
29 description: The parameter (pkg) in requested url.
30 type: str
31 required: true
32 pkg_firewall_dospolicy:
33 description: The top level parameters set.
34 required: false
35 type: dict
36 suboptions:
37 anomaly:
38 type: list
39 elements: dict
40 description: Anomaly.
41 suboptions:
42 action:
43 type: str
44 description: Action taken when the threshold is reached.
45 choices: ['pass', 'block', 'proxy']
46 log:
47 type: str
48 description: Enable/disable logging for this anomaly.
49 choices: ['disable', 'enable']
50 name:
51 type: str
52 description: Anomaly name.
53 quarantine:
54 type: str
55 description: Quarantine method.
56 choices: ['none', 'attacker', 'both', 'interface']
57 quarantine_expiry:
58 aliases: ['quarantine-expiry']
59 type: str
60 description: Duration of quarantine, from 1 minute to 364 days, 23 hours, and 59 minutes from now.
61 quarantine_log:
62 aliases: ['quarantine-log']
63 type: str
64 description: Enable/disable quarantine logging.
65 choices: ['disable', 'enable']
66 status:
67 type: str
68 description: Enable/disable the active status of this anomaly sensor.
69 choices: ['disable', 'enable']
70 threshold:
71 type: int
72 description: Number of detected instances per minute which triggers action
73 threshold_default:
74 aliases: ['threshold(default)']
75 type: int
76 description: Threshold
77 synproxy_tos:
78 type: str
79 description: Determine TCP differentiated services code point value
80 choices: ['0', '10', '12', '14', '18', '20', '22', '26', '28', '30', '34',
81 '36', '38', '40', '46', '255']
82 synproxy_ttl:
83 type: str
84 description: Determine Time to live
85 choices: ['32', '64', '128', '255']
86 synproxy_tcp_sack:
87 type: str
88 description: Enable/disable TCP selective acknowledage
89 choices: ['disable', 'enable']
90 synproxy_tcp_window:
91 type: str
92 description: Determine TCP Window size for packets replied by syn proxy module.
93 choices: ['4096', '8192', '16384', '32768']
94 synproxy_tcp_timestamp:
95 type: str
96 description: Enable/disable TCP timestamp option for packets replied by syn proxy module.
97 choices: ['disable', 'enable']
98 synproxy_tcp_mss:
99 type: str
100 description: Determine TCP maximum segment size
101 choices: ['0', '256', '512', '1024', '1300', '1360', '1460', '1500']
102 synproxy_tcp_windowscale:
103 type: str
104 description: Determine TCP window scale option value for packets replied by syn proxy module.
105 choices: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11',
106 '12', '13', '14']
107 synproxy-tos:
108 type: str
109 description: Deprecated, please rename it to synproxy_tos. Determine TCP differentiated services code point value
110 choices: ['0', '10', '12', '14', '18', '20', '22', '26', '28', '30', '34',
111 '36', '38', '40', '46', '255']
112 synproxy-tcp-window:
113 type: str
114 description: Deprecated, please rename it to synproxy_tcp_window. Determine TCP Window size for packets replied by syn proxy mo...
115 choices: ['4096', '8192', '16384', '32768']
116 synproxy-tcp-windowscale:
117 type: str
118 description: Deprecated, please rename it to synproxy_tcp_windowscale. Determine TCP window scale option value for packets repl...
119 choices: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11',
120 '12', '13', '14']
121 synproxy-tcp-timestamp:
122 type: str
123 description: Deprecated, please rename it to synproxy_tcp_timestamp. Enable/disable TCP timestamp option for packets replied by...
124 choices: ['disable', 'enable']
125 synproxy-ttl:
126 type: str
127 description: Deprecated, please rename it to synproxy_ttl. Determine Time to live
128 choices: ['32', '64', '128', '255']
129 synproxy-tcp-mss:
130 type: str
131 description: Deprecated, please rename it to synproxy_tcp_mss. Determine TCP maximum segment size
132 choices: ['0', '256', '512', '1024', '1300', '1360', '1460', '1500']
133 synproxy-tcp-sack:
134 type: str
135 description: Deprecated, please rename it to synproxy_tcp_sack. Enable/disable TCP selective acknowledage
136 choices: ['disable', 'enable']
137 comments:
138 type: str
139 description: Comment.
140 dstaddr:
141 type: raw
142 description: (list or str) Destination address name from available addresses.
143 interface:
144 type: str
145 description: Incoming interface name from available interfaces.
146 policyid:
147 type: int
148 description: Policy ID.
149 required: true
150 service:
151 type: raw
152 description: (list or str) Service object from available options.
153 srcaddr:
154 type: raw
155 description: (list or str) Source address name from available addresses.
156 status:
157 type: str
158 description: Enable/disable this policy.
159 choices: ['disable', 'enable']
160 uuid:
161 type: str
162 description: Universally Unique Identifier
163 name:
164 type: str
165 description: Policy name.
166 '''
167
168 EXAMPLES = '''
169 - name: Example playbook
170 hosts: fortimanagers
171 gather_facts: false
172 connection: httpapi
173 vars:
174 ansible_httpapi_use_ssl: true
175 ansible_httpapi_validate_certs: false
176 ansible_httpapi_port: 443
177 tasks:
178 - name: Configure IPv4 DoS policies.
179 fortinet.fortimanager.fmgr_pkg_firewall_dospolicy:
180 bypass_validation: false
181 adom: ansible
182 pkg: ansible # package name
183 state: present
184 pkg_firewall_dospolicy:
185 comments: "ansible-comment1"
186 interface: "sslvpn_tun_intf"
187 policyid: 1
188 status: enable
189
190 - name: Gathering fortimanager facts
191 hosts: fortimanagers
192 gather_facts: false
193 connection: httpapi
194 vars:
195 ansible_httpapi_use_ssl: true
196 ansible_httpapi_validate_certs: false
197 ansible_httpapi_port: 443
198 tasks:
199 - name: Retrieve all the IPv4 DoS policies
200 fortinet.fortimanager.fmgr_fact:
201 facts:
202 selector: "pkg_firewall_dospolicy"
203 params:
204 adom: "ansible"
205 pkg: "ansible" # package name
206 DoS_policy: "your_value"
207 '''
208
209 RETURN = '''
210 meta:
211 description: The result of the request.
212 type: dict
213 returned: always
214 contains:
215 request_url:
216 description: The full url requested.
217 returned: always
218 type: str
219 sample: /sys/login/user
220 response_code:
221 description: The status of api request.
222 returned: always
223 type: int
224 sample: 0
225 response_data:
226 description: The api response.
227 type: list
228 returned: always
229 response_message:
230 description: The descriptive message of the api response.
231 type: str
232 returned: always
233 sample: OK.
234 system_information:
235 description: The information of the target system.
236 type: dict
237 returned: always
238 rc:
239 description: The status the request.
240 type: int
241 returned: always
242 sample: 0
243 version_check_warning:
244 description: Warning if the parameters used in the playbook are not supported by the current FortiManager version.
245 type: list
246 returned: complex
247 '''
248 from ansible.module_utils.basic import AnsibleModule
249 from ansible.module_utils.connection import Connection
250 from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass
251 from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec
252
253
254 def main():
255 urls_list = [
256 '/pm/config/adom/{adom}/pkg/{pkg}/firewall/DoS-policy'
257 ]
258 module_arg_spec = {
259 'adom': {'required': True, 'type': 'str'},
260 'pkg': {'required': True, 'type': 'str'},
261 'revision_note': {'type': 'str'},
262 'pkg_firewall_dospolicy': {
263 'type': 'dict', 'v_range': [['6.0.0', '']],
264 'options': {
265 'anomaly': {
266 'type': 'list',
267 'options': {
268 'action': {'choices': ['pass', 'block', 'proxy'], 'type': 'str'},
269 'log': {'choices': ['disable', 'enable'], 'type': 'str'},
270 'name': {'type': 'str'},
271 'quarantine': {'choices': ['none', 'attacker', 'both', 'interface'], 'type': 'str'},
272 'quarantine-expiry': {'type': 'str'},
273 'quarantine-log': {'choices': ['disable', 'enable'], 'type': 'str'},
274 'status': {'choices': ['disable', 'enable'], 'type': 'str'},
275 'threshold': {'type': 'int'},
276 'threshold(default)': {'type': 'int'},
277 'synproxy_tos': {
278 'v_range': [['6.2.5', '7.2.0']],
279 'choices': ['0', '10', '12', '14', '18', '20', '22', '26', '28', '30', '34', '36', '38', '40', '46', '255'],
280 'type': 'str'
281 },
282 'synproxy_ttl': {'v_range': [['6.2.5', '7.2.0']], 'choices': ['32', '64', '128', '255'], 'type': 'str'},
283 'synproxy_tcp_sack': {'v_range': [['6.2.5', '7.2.0']], 'choices': ['disable', 'enable'], 'type': 'str'},
284 'synproxy_tcp_window': {'v_range': [['6.2.5', '7.2.0']], 'choices': ['4096', '8192', '16384', '32768'], 'type': 'str'},
285 'synproxy_tcp_timestamp': {'v_range': [['6.2.5', '7.2.0']], 'choices': ['disable', 'enable'], 'type': 'str'},
286 'synproxy_tcp_mss': {
287 'v_range': [['6.2.5', '7.2.0']],
288 'choices': ['0', '256', '512', '1024', '1300', '1360', '1460', '1500'],
289 'type': 'str'
290 },
291 'synproxy_tcp_windowscale': {
292 'v_range': [['6.2.5', '7.2.0']],
293 'choices': ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14'],
294 'type': 'str'
295 },
296 'synproxy-tos': {
297 'v_range': [['6.2.6', '6.2.13'], ['6.4.2', '7.2.0'], ['7.2.6', '7.2.12'], ['7.4.3', '']],
298 'choices': ['0', '10', '12', '14', '18', '20', '22', '26', '28', '30', '34', '36', '38', '40', '46', '255'],
299 'type': 'str'
300 },
301 'synproxy-tcp-window': {
302 'v_range': [['6.2.6', '6.2.13'], ['6.4.2', '7.2.0'], ['7.2.6', '7.2.12'], ['7.4.3', '']],
303 'choices': ['4096', '8192', '16384', '32768'],
304 'type': 'str'
305 },
306 'synproxy-tcp-windowscale': {
307 'v_range': [['6.2.6', '6.2.13'], ['6.4.2', '7.2.0'], ['7.2.6', '7.2.12'], ['7.4.3', '']],
308 'choices': ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14'],
309 'type': 'str'
310 },
311 'synproxy-tcp-timestamp': {
312 'v_range': [['6.2.6', '6.2.13'], ['6.4.2', '7.2.0'], ['7.2.6', '7.2.12'], ['7.4.3', '']],
313 'choices': ['disable', 'enable'],
314 'type': 'str'
315 },
316 'synproxy-ttl': {
317 'v_range': [['6.2.6', '6.2.13'], ['6.4.2', '7.2.0'], ['7.2.6', '7.2.12'], ['7.4.3', '']],
318 'choices': ['32', '64', '128', '255'],
319 'type': 'str'
320 },
321 'synproxy-tcp-mss': {
322 'v_range': [['6.2.6', '6.2.13'], ['6.4.2', '7.2.0'], ['7.2.6', '7.2.12'], ['7.4.3', '']],
323 'choices': ['0', '256', '512', '1024', '1300', '1360', '1460', '1500'],
324 'type': 'str'
325 },
326 'synproxy-tcp-sack': {
327 'v_range': [['6.2.6', '6.2.13'], ['6.4.2', '7.2.0'], ['7.2.6', '7.2.12'], ['7.4.3', '']],
328 'choices': ['disable', 'enable'],
329 'type': 'str'
330 }
331 },
332 'elements': 'dict'
333 },
334 'comments': {'type': 'str'},
335 'dstaddr': {'type': 'raw'},
336 'interface': {'type': 'str'},
337 'policyid': {'required': True, 'type': 'int'},
338 'service': {'type': 'raw'},
339 'srcaddr': {'type': 'raw'},
340 'status': {'choices': ['disable', 'enable'], 'type': 'str'},
341 'uuid': {'v_range': [['6.2.1', '7.2.0']], 'type': 'str'},
342 'name': {'v_range': [['6.4.2', '']], 'type': 'str'}
343 }
344 }
345 }
346
347 module_option_spec = get_module_arg_spec('full crud')
348 module_arg_spec.update(module_option_spec)
349 check_galaxy_version(module_arg_spec)
350 module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'pkg_firewall_dospolicy'),
351 supports_check_mode=True)
352 if not module._socket_path:
353 module.fail_json(msg='MUST RUN IN HTTPAPI MODE')
354 connection = Connection(module._socket_path)
355 fmgr = NAPIManager('full crud', module_arg_spec, urls_list,
356 'policyid', 'data', module, connection)
357 fmgr.process_crud()
358 module.exit_json(meta=module.params)
359
360
361 if __name__ == '__main__':
362 main()