Debian Codegraph @

ansible_collections/check_point/mgmt/plugins/modules/cp_mgmt_smart_task.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 #
4 # Ansible module to manage CheckPoint Firewall (c) 2019
5 #
6 # Ansible is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # Ansible is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
18 #
19
20 from __future__ import (absolute_import, division, print_function)
21
22 __metaclass__ = type
23
24 ANSIBLE_METADATA = {'metadata_version': '1.1',
25 'status': ['preview'],
26 'supported_by': 'community'}
27
28 DOCUMENTATION = """
29 ---
30 module: cp_mgmt_smart_task
31 short_description: Manages smart-task objects on Checkpoint over Web Services API
32 description:
33 - Manages smart-task objects on Checkpoint devices including creating, updating and removing objects.
34 - All operations are performed over Web Services API.
35 - Available from R80.40 management version.
36 version_added: "5.0.0"
37 author: "Eden Brillant (@chkp-edenbr)"
38 options:
39 name:
40 description:
41 - Object name.
42 type: str
43 required: True
44 action:
45 description:
46 - The action to be run when the trigger is fired.
47 type: dict
48 suboptions:
49 send_web_request:
50 description:
51 - When the trigger is fired, sends an HTTPS POST web request to the configured URL.<br>The trigger data will be passed along with the
52 SmartTask's custom data in the request's payload.
53 type: dict
54 suboptions:
55 url:
56 description:
57 - URL used for the web request.
58 type: str
59 fingerprint:
60 description:
61 - The SHA1 fingerprint of the URL's SSL certificate. Used to trust servers with self-signed SSL certificates.
62 type: str
63 override_proxy:
64 description:
65 - Option to send to the web request via a proxy other than the Management's Server proxy (if defined).
66 type: bool
67 proxy_url:
68 description:
69 - URL of the proxy used to send the request.
70 type: str
71 shared_secret:
72 description:
73 - Shared secret that can be used by the target server to identify the Management Server.<br>The value will be sent as part of
74 the request in the "X-chkp-shared-secret" header.
75 type: str
76 time_out:
77 description:
78 - Web Request time-out in seconds.
79 type: int
80 run_script:
81 description:
82 - When the trigger is fired, runs the configured Repository Script on the defined targets.<br>The trigger data is then passed to the
83 script as the first parameter. The parameter is JSON encoded in Base64 format.
84 type: dict
85 suboptions:
86 repository_script:
87 description:
88 - Repository script that is executed when the trigger is fired., identified by the name or UID.
89 type: str
90 targets:
91 description:
92 - Targets to execute the script on.
93 type: list
94 elements: str
95 time_out:
96 description:
97 - Script execution time-out in seconds.
98 type: int
99 send_mail:
100 description:
101 - When the trigger is fired, sends the configured email to the defined recipients.
102 type: dict
103 suboptions:
104 mail_settings:
105 description:
106 - The required settings to send the mail by.
107 type: dict
108 suboptions:
109 recipients:
110 description:
111 - A comma separated list of recipient mail addresses.
112 type: str
113 sender_email:
114 description:
115 - An email address to send the mail from.
116 type: str
117 subject:
118 description:
119 - The email subject.
120 type: str
121 body:
122 description:
123 - The email body.
124 type: str
125 attachment:
126 description:
127 - What file should be attached to the mail.
128 type: str
129 choices: ['no attachment', 'changes report', 'policy installation report']
130 bcc_recipients:
131 description:
132 - A comma separated list of bcc recipient mail addresses.
133 type: str
134 cc_recipients:
135 description:
136 - A comma separated list of cc recipient mail addresses.
137 type: str
138 smtp_server:
139 description:
140 - The UID or the name a preconfigured SMTP server object.
141 type: str
142 trigger:
143 description:
144 - Trigger type associated with the SmartTask.
145 type: str
146 custom_data:
147 description:
148 - Per SmartTask custom data in JSON format.<br>When the trigger is fired, the trigger data is converted to JSON. The custom data is then
149 concatenated to the trigger data JSON.
150 type: str
151 description:
152 description:
153 - Description of the SmartTask's functionality and options.
154 type: str
155 enabled:
156 description:
157 - Whether the SmartTask is enabled and will run when triggered.
158 type: bool
159 fail_open:
160 description:
161 - If the action fails to execute, whether to treat the execution failure as an error, or continue.
162 type: bool
163 tags:
164 description:
165 - Collection of tag identifiers.
166 type: list
167 elements: str
168 color:
169 description:
170 - Color of the object. Should be one of existing colors.
171 type: str
172 choices: ['aquamarine', 'black', 'blue', 'crete blue', 'burlywood', 'cyan', 'dark green', 'khaki', 'orchid', 'dark orange', 'dark sea green',
173 'pink', 'turquoise', 'dark blue', 'firebrick', 'brown', 'forest green', 'gold', 'dark gold', 'gray', 'dark gray', 'light green', 'lemon chiffon',
174 'coral', 'sea green', 'sky blue', 'magenta', 'purple', 'slate blue', 'violet red', 'navy blue', 'olive', 'orange', 'red', 'sienna', 'yellow']
175 comments:
176 description:
177 - Comments string.
178 type: str
179 details_level:
180 description:
181 - The level of detail for some of the fields in the response can vary from showing only the UID value of the object to a fully detailed
182 representation of the object.
183 type: str
184 choices: ['uid', 'standard', 'full']
185 ignore_warnings:
186 description:
187 - Apply changes ignoring warnings.
188 type: bool
189 ignore_errors:
190 description:
191 - Apply changes ignoring errors. You won't be able to publish such a changes. If ignore-warnings flag was omitted - warnings will also be ignored.
192 type: bool
193 extends_documentation_fragment: check_point.mgmt.checkpoint_objects
194 """
195
196 EXAMPLES = """
197 - name: add-smart-task
198 cp_mgmt_smart_task:
199 action:
200 run_script:
201 repository_script: Session Name Validation Script
202 time_out: 30
203 custom_data: '{"session-name-format": "CR"}'
204 description: Run a validation script that ensures that the a session name matches the expected name format as described in the Custom Data field.
205 enabled: true
206 name: Validate Session Name Before Publish
207 state: present
208 trigger: Before Publish
209
210 - name: set-smart-task
211 cp_mgmt_smart_task:
212 action:
213 send_web_request:
214 fingerprint: 3FDD902286DBF130EF4CEC7939EF81060AB0FEB6
215 url: https://demo.example.com/policy-installation-reports
216 custom_data: '{"mail-address": "[email protected]"}'
217 description: Send policy installation results to the mail address specified in the Custom Data field using the corporate's dedicated web server.
218 enabled: true
219 name: Send Policy Installation Reports
220 state: present
221 trigger: After Install Policy
222
223 - name: delete-smart-task
224 cp_mgmt_smart_task:
225 name: Validate Session Name Before Publish
226 state: absent
227 """
228
229 RETURN = """
230 cp_mgmt_smart_task:
231 description: The checkpoint object created or updated.
232 returned: always, except when deleting the object.
233 type: dict
234 """
235
236 from ansible.module_utils.basic import AnsibleModule
237 from ansible_collections.check_point.mgmt.plugins.module_utils.checkpoint import checkpoint_argument_spec_for_objects, api_call
238
239
240 def main():
241 argument_spec = dict(
242 name=dict(type='str', required=True),
243 action=dict(type='dict', options=dict(
244 send_web_request=dict(type='dict', options=dict(
245 url=dict(type='str'),
246 fingerprint=dict(type='str'),
247 override_proxy=dict(type='bool'),
248 proxy_url=dict(type='str'),
249 shared_secret=dict(type='str', no_log=True),
250 time_out=dict(type='int')
251 )),
252 run_script=dict(type='dict', options=dict(
253 repository_script=dict(type='str'),
254 targets=dict(type='list', elements='str'),
255 time_out=dict(type='int')
256 )),
257 send_mail=dict(type='dict', options=dict(
258 mail_settings=dict(type='dict', options=dict(
259 recipients=dict(type='str'),
260 sender_email=dict(type='str'),
261 subject=dict(type='str'),
262 body=dict(type='str'),
263 attachment=dict(type='str', choices=['no attachment', 'changes report', 'policy installation report']),
264 bcc_recipients=dict(type='str'),
265 cc_recipients=dict(type='str')
266 )),
267 smtp_server=dict(type='str')
268 ))
269 )),
270 trigger=dict(type='str'),
271 custom_data=dict(type='str'),
272 description=dict(type='str'),
273 enabled=dict(type='bool'),
274 fail_open=dict(type='bool'),
275 tags=dict(type='list', elements='str'),
276 color=dict(type='str', choices=['aquamarine', 'black', 'blue', 'crete blue', 'burlywood', 'cyan', 'dark green',
277 'khaki', 'orchid', 'dark orange', 'dark sea green', 'pink', 'turquoise', 'dark blue', 'firebrick', 'brown',
278 'forest green', 'gold', 'dark gold', 'gray', 'dark gray', 'light green', 'lemon chiffon', 'coral', 'sea green',
279 'sky blue', 'magenta', 'purple', 'slate blue', 'violet red', 'navy blue', 'olive', 'orange', 'red', 'sienna',
280 'yellow']),
281 comments=dict(type='str'),
282 details_level=dict(type='str', choices=['uid', 'standard', 'full']),
283 ignore_warnings=dict(type='bool'),
284 ignore_errors=dict(type='bool')
285 )
286 argument_spec.update(checkpoint_argument_spec_for_objects)
287
288 module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
289 api_call_object = 'smart-task'
290
291 result = api_call(module, api_call_object)
292 module.exit_json(**result)
293
294
295 if __name__ == '__main__':
296 main()