Debian Codegraph @

ansible_collections/fortinet/fortimanager/plugins/modules/fmgr_ips_custom.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_custom
15 short_description: Configure IPS custom signature.
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 ips_custom:
29 description: The top level parameters set.
30 required: false
31 type: dict
32 suboptions:
33 action:
34 type: str
35 description: Default action
36 choices: ['block', 'pass']
37 application:
38 type: raw
39 description: (list) Applications to be protected.
40 comment:
41 type: str
42 description: Comment.
43 location:
44 type: raw
45 description: (list) Protect client or server traffic.
46 log:
47 type: str
48 description: Enable/disable logging.
49 choices: ['disable', 'enable']
50 log_packet:
51 aliases: ['log-packet']
52 type: str
53 description: Enable/disable packet logging.
54 choices: ['disable', 'enable']
55 os:
56 type: raw
57 description: (list) Operating system
58 protocol:
59 type: str
60 description: Protocol
61 rule_id:
62 aliases: ['rule-id']
63 type: int
64 description: Rule id.
65 severity:
66 type: str
67 description: Relative severity of the signature, from info to critical.
68 sig_name:
69 aliases: ['sig-name']
70 type: str
71 description: Sig name.
72 signature:
73 type: str
74 description: Custom signature enclosed in single quotes.
75 status:
76 type: str
77 description: Enable/disable this signature.
78 choices: ['disable', 'enable']
79 tag:
80 type: str
81 description: Signature tag.
82 required: true
83 '''
84
85 EXAMPLES = '''
86 - name: Example playbook
87 hosts: fortimanagers
88 gather_facts: false
89 connection: httpapi
90 vars:
91 ansible_httpapi_use_ssl: true
92 ansible_httpapi_validate_certs: false
93 ansible_httpapi_port: 443
94 tasks:
95 - name: Configure IPS custom signature.
96 fortinet.fortimanager.fmgr_ips_custom:
97 bypass_validation: true
98 adom: ansible
99 state: present
100 ips_custom:
101 rule_id: 1 # Required, no less than 1000;
102 signature: "F-SBID(--name: [string]; --service: [string]; --flow: [string])" # Required; Need follow signature syntax,
103 # check 'https://docs.fortinet.com/document/ipsengine/3.6.0/custom-ips-and-application-control-signature-syntax-guide/
104 # 274110/creating-ips-and-application-control-signatures' for more information;
105 tag: ansible-ipscustom # Required
106
107 - name: Gathering fortimanager facts
108 hosts: fortimanagers
109 gather_facts: false
110 connection: httpapi
111 vars:
112 ansible_httpapi_use_ssl: true
113 ansible_httpapi_validate_certs: false
114 ansible_httpapi_port: 443
115 tasks:
116 - name: Retrieve all the IPS custom signatures
117 fortinet.fortimanager.fmgr_fact:
118 facts:
119 selector: "ips_custom"
120 params:
121 adom: "ansible"
122 custom: "your_value"
123 '''
124
125 RETURN = '''
126 meta:
127 description: The result of the request.
128 type: dict
129 returned: always
130 contains:
131 request_url:
132 description: The full url requested.
133 returned: always
134 type: str
135 sample: /sys/login/user
136 response_code:
137 description: The status of api request.
138 returned: always
139 type: int
140 sample: 0
141 response_data:
142 description: The api response.
143 type: list
144 returned: always
145 response_message:
146 description: The descriptive message of the api response.
147 type: str
148 returned: always
149 sample: OK.
150 system_information:
151 description: The information of the target system.
152 type: dict
153 returned: always
154 rc:
155 description: The status the request.
156 type: int
157 returned: always
158 sample: 0
159 version_check_warning:
160 description: Warning if the parameters used in the playbook are not supported by the current FortiManager version.
161 type: list
162 returned: complex
163 '''
164 from ansible.module_utils.basic import AnsibleModule
165 from ansible.module_utils.connection import Connection
166 from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass
167 from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec
168
169
170 def main():
171 urls_list = [
172 '/pm/config/adom/{adom}/obj/ips/custom',
173 '/pm/config/global/obj/ips/custom'
174 ]
175 module_arg_spec = {
176 'adom': {'required': True, 'type': 'str'},
177 'revision_note': {'type': 'str'},
178 'ips_custom': {
179 'type': 'dict', 'v_range': [['6.0.0', '']],
180 'options': {
181 'action': {'choices': ['block', 'pass'], 'type': 'str'},
182 'application': {'type': 'raw'},
183 'comment': {'type': 'str'},
184 'location': {'type': 'raw'},
185 'log': {'choices': ['disable', 'enable'], 'type': 'str'},
186 'log-packet': {'choices': ['disable', 'enable'], 'type': 'str'},
187 'os': {'type': 'raw'},
188 'protocol': {'type': 'str'},
189 'rule-id': {'type': 'int'},
190 'severity': {'type': 'str'},
191 'sig-name': {'type': 'str'},
192 'signature': {'type': 'str'},
193 'status': {'choices': ['disable', 'enable'], 'type': 'str'},
194 'tag': {'required': True, 'type': 'str'}
195 }
196 }
197 }
198
199 module_option_spec = get_module_arg_spec('full crud')
200 module_arg_spec.update(module_option_spec)
201 check_galaxy_version(module_arg_spec)
202 module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'ips_custom'),
203 supports_check_mode=True)
204 if not module._socket_path:
205 module.fail_json(msg='MUST RUN IN HTTPAPI MODE')
206 connection = Connection(module._socket_path)
207 fmgr = NAPIManager('full crud', module_arg_spec, urls_list,
208 'tag', 'data', module, connection)
209 fmgr.process_crud()
210 module.exit_json(meta=module.params)
211
212
213 if __name__ == '__main__':
214 main()