| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
# |
| 4 |
# Ansible module to manage Check Point 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 = { |
| 25 |
"metadata_version": "1.1", |
| 26 |
"status": ["preview"], |
| 27 |
"supported_by": "community", |
| 28 |
} |
| 29 |
|
| 30 |
DOCUMENTATION = """ |
| 31 |
--- |
| 32 |
module: cp_mgmt_threat_indicator |
| 33 |
short_description: Manages threat-indicator objects on Check Point over Web Services API |
| 34 |
description: |
| 35 |
- Manages threat-indicator objects on Check Point devices including creating, updating and removing objects. |
| 36 |
- All operations are performed over Web Services API. |
| 37 |
- Available from R80.20.M1 management version. |
| 38 |
version_added: "1.0.0" |
| 39 |
author: "Or Soffer (@chkp-orso)" |
| 40 |
options: |
| 41 |
name: |
| 42 |
description: |
| 43 |
- Object name. |
| 44 |
type: str |
| 45 |
required: True |
| 46 |
observables: |
| 47 |
description: |
| 48 |
- The indicator's observables. |
| 49 |
type: list |
| 50 |
elements: dict |
| 51 |
suboptions: |
| 52 |
name: |
| 53 |
description: |
| 54 |
- Object name. Should be unique in the domain. |
| 55 |
type: str |
| 56 |
md5: |
| 57 |
description: |
| 58 |
- A valid MD5 sequence. |
| 59 |
type: str |
| 60 |
url: |
| 61 |
description: |
| 62 |
- A valid URL. |
| 63 |
type: str |
| 64 |
ip_address: |
| 65 |
description: |
| 66 |
- A valid IP-Address. |
| 67 |
type: str |
| 68 |
ip_address_first: |
| 69 |
description: |
| 70 |
- A valid IP-Address, the beginning of the range. If you configure this parameter with a value, you must also configure the value of the |
| 71 |
'ip-address-last' parameter. |
| 72 |
type: str |
| 73 |
ip_address_last: |
| 74 |
description: |
| 75 |
- A valid IP-Address, the end of the range. If you configure this parameter with a value, you must also configure the value of the |
| 76 |
'ip-address-first' parameter. |
| 77 |
type: str |
| 78 |
domain: |
| 79 |
description: |
| 80 |
- The name of a domain. |
| 81 |
type: str |
| 82 |
mail_to: |
| 83 |
description: |
| 84 |
- A valid E-Mail address, recipient filed. |
| 85 |
type: str |
| 86 |
mail_from: |
| 87 |
description: |
| 88 |
- A valid E-Mail address, sender field. |
| 89 |
type: str |
| 90 |
mail_cc: |
| 91 |
description: |
| 92 |
- A valid E-Mail address, cc field. |
| 93 |
type: str |
| 94 |
mail_reply_to: |
| 95 |
description: |
| 96 |
- A valid E-Mail address, reply-to field. |
| 97 |
type: str |
| 98 |
mail_subject: |
| 99 |
description: |
| 100 |
- Subject of E-Mail. |
| 101 |
type: str |
| 102 |
confidence: |
| 103 |
description: |
| 104 |
- The confidence level the indicator has that a real threat has been uncovered. |
| 105 |
type: str |
| 106 |
choices: ['low', 'medium', 'high', 'critical'] |
| 107 |
product: |
| 108 |
description: |
| 109 |
- The software blade that processes the observable, AV - AntiVirus, AB - AntiBot. |
| 110 |
type: str |
| 111 |
choices: ['AV', 'AB'] |
| 112 |
severity: |
| 113 |
description: |
| 114 |
- The severity level of the threat. |
| 115 |
type: str |
| 116 |
choices: ['low', 'medium', 'high', 'critical'] |
| 117 |
comments: |
| 118 |
description: |
| 119 |
- Comments string. |
| 120 |
type: str |
| 121 |
ignore_warnings: |
| 122 |
description: |
| 123 |
- Apply changes ignoring warnings. |
| 124 |
type: bool |
| 125 |
ignore_errors: |
| 126 |
description: |
| 127 |
- 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. |
| 128 |
type: bool |
| 129 |
observables_raw_data: |
| 130 |
description: |
| 131 |
- The contents of a file containing the indicator's observables. |
| 132 |
type: str |
| 133 |
action: |
| 134 |
description: |
| 135 |
- The indicator's action. |
| 136 |
type: str |
| 137 |
choices: ['Inactive', 'Ask', 'Prevent', 'Detect'] |
| 138 |
profile_overrides: |
| 139 |
description: |
| 140 |
- Profiles in which to override the indicator's default action. |
| 141 |
type: list |
| 142 |
elements: dict |
| 143 |
suboptions: |
| 144 |
action: |
| 145 |
description: |
| 146 |
- The indicator's action in this profile. |
| 147 |
type: str |
| 148 |
choices: ['Inactive', 'Ask', 'Prevent', 'Detect'] |
| 149 |
profile: |
| 150 |
description: |
| 151 |
- The profile in which to override the indicator's action. |
| 152 |
type: str |
| 153 |
tags: |
| 154 |
description: |
| 155 |
- Collection of tag identifiers. |
| 156 |
type: list |
| 157 |
elements: str |
| 158 |
color: |
| 159 |
description: |
| 160 |
- Color of the object. Should be one of existing colors. |
| 161 |
type: str |
| 162 |
choices: ['aquamarine', 'black', 'blue', 'crete blue', 'burlywood', 'cyan', 'dark green', 'khaki', 'orchid', 'dark orange', 'dark sea green', |
| 163 |
'pink', 'turquoise', 'dark blue', 'firebrick', 'brown', 'forest green', 'gold', 'dark gold', 'gray', 'dark gray', 'light green', 'lemon chiffon', |
| 164 |
'coral', 'sea green', 'sky blue', 'magenta', 'purple', 'slate blue', 'violet red', 'navy blue', 'olive', 'orange', 'red', 'sienna', 'yellow'] |
| 165 |
comments: |
| 166 |
description: |
| 167 |
- Comments string. |
| 168 |
type: str |
| 169 |
details_level: |
| 170 |
description: |
| 171 |
- 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 |
| 172 |
representation of the object. |
| 173 |
type: str |
| 174 |
choices: ['uid', 'standard', 'full'] |
| 175 |
ignore_warnings: |
| 176 |
description: |
| 177 |
- Apply changes ignoring warnings. |
| 178 |
type: bool |
| 179 |
ignore_errors: |
| 180 |
description: |
| 181 |
- 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. |
| 182 |
type: bool |
| 183 |
extends_documentation_fragment: check_point.mgmt.checkpoint_objects |
| 184 |
""" |
| 185 |
|
| 186 |
EXAMPLES = """ |
| 187 |
- name: add-threat-indicator |
| 188 |
cp_mgmt_threat_indicator: |
| 189 |
action: ask |
| 190 |
ignore_warnings: true |
| 191 |
name: My_Indicator |
| 192 |
observables: |
| 193 |
- confidence: medium |
| 194 |
mail_to: [email protected] |
| 195 |
name: My_Observable |
| 196 |
product: AV |
| 197 |
severity: low |
| 198 |
profile_overrides: |
| 199 |
- action: detect |
| 200 |
profile: My_Profile |
| 201 |
state: present |
| 202 |
|
| 203 |
- name: set-threat-indicator |
| 204 |
cp_mgmt_threat_indicator: |
| 205 |
action: prevent |
| 206 |
ignore_warnings: true |
| 207 |
name: My_Indicator |
| 208 |
state: present |
| 209 |
|
| 210 |
- name: delete-threat-indicator |
| 211 |
cp_mgmt_threat_indicator: |
| 212 |
name: My_Indicator |
| 213 |
state: absent |
| 214 |
""" |
| 215 |
|
| 216 |
RETURN = """ |
| 217 |
cp_mgmt_threat_indicator: |
| 218 |
description: The checkpoint object created or updated. |
| 219 |
returned: always, except when deleting the object. |
| 220 |
type: dict |
| 221 |
""" |
| 222 |
|
| 223 |
from ansible.module_utils.basic import AnsibleModule |
| 224 |
from ansible_collections.check_point.mgmt.plugins.module_utils.checkpoint import ( |
| 225 |
checkpoint_argument_spec_for_objects, |
| 226 |
api_call, |
| 227 |
) |
| 228 |
|
| 229 |
|
| 230 |
def main(): |
| 231 |
argument_spec = dict( |
| 232 |
name=dict(type="str", required=True), |
| 233 |
observables=dict( |
| 234 |
type="list", |
| 235 |
elements="dict", |
| 236 |
options=dict( |
| 237 |
name=dict(type="str"), |
| 238 |
md5=dict(type="str"), |
| 239 |
url=dict(type="str"), |
| 240 |
ip_address=dict(type="str"), |
| 241 |
ip_address_first=dict(type="str"), |
| 242 |
ip_address_last=dict(type="str"), |
| 243 |
domain=dict(type="str"), |
| 244 |
mail_to=dict(type="str"), |
| 245 |
mail_from=dict(type="str"), |
| 246 |
mail_cc=dict(type="str"), |
| 247 |
mail_reply_to=dict(type="str"), |
| 248 |
mail_subject=dict(type="str"), |
| 249 |
confidence=dict( |
| 250 |
type="str", choices=["low", "medium", "high", "critical"] |
| 251 |
), |
| 252 |
product=dict(type="str", choices=["AV", "AB"]), |
| 253 |
severity=dict( |
| 254 |
type="str", choices=["low", "medium", "high", "critical"] |
| 255 |
), |
| 256 |
comments=dict(type="str"), |
| 257 |
ignore_warnings=dict(type="bool"), |
| 258 |
ignore_errors=dict(type="bool"), |
| 259 |
), |
| 260 |
), |
| 261 |
observables_raw_data=dict(type="str"), |
| 262 |
action=dict( |
| 263 |
type="str", choices=["Inactive", "Ask", "Prevent", "Detect"] |
| 264 |
), |
| 265 |
profile_overrides=dict( |
| 266 |
type="list", |
| 267 |
elements="dict", |
| 268 |
options=dict( |
| 269 |
action=dict( |
| 270 |
type="str", |
| 271 |
choices=["Inactive", "Ask", "Prevent", "Detect"], |
| 272 |
), |
| 273 |
profile=dict(type="str"), |
| 274 |
), |
| 275 |
), |
| 276 |
tags=dict(type="list", elements="str"), |
| 277 |
color=dict( |
| 278 |
type="str", |
| 279 |
choices=[ |
| 280 |
"aquamarine", |
| 281 |
"black", |
| 282 |
"blue", |
| 283 |
"crete blue", |
| 284 |
"burlywood", |
| 285 |
"cyan", |
| 286 |
"dark green", |
| 287 |
"khaki", |
| 288 |
"orchid", |
| 289 |
"dark orange", |
| 290 |
"dark sea green", |
| 291 |
"pink", |
| 292 |
"turquoise", |
| 293 |
"dark blue", |
| 294 |
"firebrick", |
| 295 |
"brown", |
| 296 |
"forest green", |
| 297 |
"gold", |
| 298 |
"dark gold", |
| 299 |
"gray", |
| 300 |
"dark gray", |
| 301 |
"light green", |
| 302 |
"lemon chiffon", |
| 303 |
"coral", |
| 304 |
"sea green", |
| 305 |
"sky blue", |
| 306 |
"magenta", |
| 307 |
"purple", |
| 308 |
"slate blue", |
| 309 |
"violet red", |
| 310 |
"navy blue", |
| 311 |
"olive", |
| 312 |
"orange", |
| 313 |
"red", |
| 314 |
"sienna", |
| 315 |
"yellow", |
| 316 |
], |
| 317 |
), |
| 318 |
comments=dict(type="str"), |
| 319 |
details_level=dict(type="str", choices=["uid", "standard", "full"]), |
| 320 |
ignore_warnings=dict(type="bool"), |
| 321 |
ignore_errors=dict(type="bool"), |
| 322 |
) |
| 323 |
argument_spec.update(checkpoint_argument_spec_for_objects) |
| 324 |
|
| 325 |
module = AnsibleModule( |
| 326 |
argument_spec=argument_spec, supports_check_mode=True |
| 327 |
) |
| 328 |
api_call_object = "threat-indicator" |
| 329 |
|
| 330 |
result = api_call(module, api_call_object) |
| 331 |
module.exit_json(**result) |
| 332 |
|
| 333 |
|
| 334 |
if __name__ == "__main__": |
| 335 |
main() |