| 1 |
|
| 2 |
from __future__ import absolute_import, division, print_function |
| 3 |
|
| 4 |
|
| 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_dlp_profile_rule |
| 15 |
short_description: Set up DLP rules for this profile. |
| 16 |
version_added: "2.1.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 |
profile: |
| 29 |
description: The parameter (profile) in requested url. |
| 30 |
type: str |
| 31 |
required: true |
| 32 |
dlp_profile_rule: |
| 33 |
description: The top level parameters set. |
| 34 |
required: false |
| 35 |
type: dict |
| 36 |
suboptions: |
| 37 |
action: |
| 38 |
type: str |
| 39 |
description: Action to take with content that this DLP profile matches. |
| 40 |
choices: ['log-only', 'block', 'quarantine-ip', 'allow'] |
| 41 |
archive: |
| 42 |
type: str |
| 43 |
description: Enable/disable DLP archiving. |
| 44 |
choices: ['disable', 'enable'] |
| 45 |
expiry: |
| 46 |
type: str |
| 47 |
description: Quarantine duration in days, hours, minutes |
| 48 |
file_size: |
| 49 |
aliases: ['file-size'] |
| 50 |
type: int |
| 51 |
description: Match files this size or larger |
| 52 |
file_type: |
| 53 |
aliases: ['file-type'] |
| 54 |
type: str |
| 55 |
description: Select the number of a DLP file pattern table to match. |
| 56 |
filter_by: |
| 57 |
aliases: ['filter-by'] |
| 58 |
type: str |
| 59 |
description: Select the type of content to match. |
| 60 |
choices: ['fingerprint', 'sensor', 'encrypted', 'none', 'mip', 'label'] |
| 61 |
id: |
| 62 |
type: int |
| 63 |
description: ID. |
| 64 |
required: true |
| 65 |
label: |
| 66 |
type: str |
| 67 |
description: MIP label dictionary. |
| 68 |
match_percentage: |
| 69 |
aliases: ['match-percentage'] |
| 70 |
type: int |
| 71 |
description: Percentage of fingerprints in the fingerprint databases designated with the selected sensitivity to match. |
| 72 |
name: |
| 73 |
type: str |
| 74 |
description: Filter name. |
| 75 |
proto: |
| 76 |
type: list |
| 77 |
elements: str |
| 78 |
description: Check messages or files over one or more of these protocols. |
| 79 |
choices: ['smtp', 'pop3', 'imap', 'http-post', 'http-get', 'ftp', 'nntp', 'mapi', |
| 80 |
'ssh', 'cifs'] |
| 81 |
sensitivity: |
| 82 |
type: raw |
| 83 |
description: (list) Select a DLP file pattern sensitivity to match. |
| 84 |
sensor: |
| 85 |
type: raw |
| 86 |
description: (list) Select DLP sensors. |
| 87 |
severity: |
| 88 |
type: str |
| 89 |
description: Select the severity or threat level that matches this filter. |
| 90 |
choices: ['info', 'low', 'medium', 'high', 'critical'] |
| 91 |
type: |
| 92 |
type: str |
| 93 |
description: Select whether to check the content of messages |
| 94 |
choices: ['file', 'message'] |
| 95 |
''' |
| 96 |
|
| 97 |
EXAMPLES = ''' |
| 98 |
- name: Example playbook (generated based on argument schema) |
| 99 |
hosts: fortimanagers |
| 100 |
connection: httpapi |
| 101 |
gather_facts: false |
| 102 |
tasks: |
| 103 |
- name: Set up DLP rules for this profile. |
| 104 |
fortinet.fortimanager.fmgr_dlp_profile_rule: |
| 105 |
# workspace_locking_adom: <global or your adom name> |
| 106 |
adom: <your own value> |
| 107 |
profile: <your own value> |
| 108 |
state: present # <value in [present, absent]> |
| 109 |
dlp_profile_rule: |
| 110 |
id: 0 # Required variable, integer |
| 111 |
# action: <value in [log-only, block, quarantine-ip, ...]> |
| 112 |
# archive: <value in [disable, enable]> |
| 113 |
# expiry: <string> |
| 114 |
# file_size: <integer> |
| 115 |
# file_type: <string> |
| 116 |
# filter_by: <value in [fingerprint, sensor, encrypted, ...]> |
| 117 |
# label: <string> |
| 118 |
# match_percentage: <integer> |
| 119 |
# name: <string> |
| 120 |
# proto: ["smtp", "pop3", "imap", "http-post", "http-get", "ftp", "nntp", "mapi", "ssh", |
| 121 |
# "cifs"] |
| 122 |
# sensitivity: <list or string> |
| 123 |
# sensor: <list or string> |
| 124 |
# severity: <value in [info, low, medium, ...]> |
| 125 |
# type: <value in [file, message]> |
| 126 |
''' |
| 127 |
|
| 128 |
RETURN = ''' |
| 129 |
meta: |
| 130 |
description: The result of the request. |
| 131 |
type: dict |
| 132 |
returned: always |
| 133 |
contains: |
| 134 |
request_url: |
| 135 |
description: The full url requested. |
| 136 |
returned: always |
| 137 |
type: str |
| 138 |
sample: /sys/login/user |
| 139 |
response_code: |
| 140 |
description: The status of api request. |
| 141 |
returned: always |
| 142 |
type: int |
| 143 |
sample: 0 |
| 144 |
response_data: |
| 145 |
description: The api response. |
| 146 |
type: list |
| 147 |
returned: always |
| 148 |
response_message: |
| 149 |
description: The descriptive message of the api response. |
| 150 |
type: str |
| 151 |
returned: always |
| 152 |
sample: OK. |
| 153 |
system_information: |
| 154 |
description: The information of the target system. |
| 155 |
type: dict |
| 156 |
returned: always |
| 157 |
rc: |
| 158 |
description: The status the request. |
| 159 |
type: int |
| 160 |
returned: always |
| 161 |
sample: 0 |
| 162 |
version_check_warning: |
| 163 |
description: Warning if the parameters used in the playbook are not supported by the current FortiManager version. |
| 164 |
type: list |
| 165 |
returned: complex |
| 166 |
''' |
| 167 |
from ansible.module_utils.basic import AnsibleModule |
| 168 |
from ansible.module_utils.connection import Connection |
| 169 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass |
| 170 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec |
| 171 |
|
| 172 |
|
| 173 |
def main(): |
| 174 |
urls_list = [ |
| 175 |
'/pm/config/adom/{adom}/obj/dlp/profile/{profile}/rule', |
| 176 |
'/pm/config/global/obj/dlp/profile/{profile}/rule' |
| 177 |
] |
| 178 |
module_arg_spec = { |
| 179 |
'adom': {'required': True, 'type': 'str'}, |
| 180 |
'profile': {'required': True, 'type': 'str'}, |
| 181 |
'revision_note': {'type': 'str'}, |
| 182 |
'dlp_profile_rule': { |
| 183 |
'type': 'dict', 'v_range': [['7.2.0', '']], |
| 184 |
'options': { |
| 185 |
'action': {'v_range': [['7.2.0', '']], 'choices': ['log-only', 'block', 'quarantine-ip', 'allow'], 'type': 'str'}, |
| 186 |
'archive': {'v_range': [['7.2.0', '']], 'choices': ['disable', 'enable'], 'type': 'str'}, |
| 187 |
'expiry': {'v_range': [['7.2.0', '']], 'type': 'str'}, |
| 188 |
'file-size': {'v_range': [['7.2.0', '']], 'type': 'int'}, |
| 189 |
'file-type': {'v_range': [['7.2.0', '']], 'type': 'str'}, |
| 190 |
'filter-by': {'v_range': [['7.2.0', '']], 'choices': ['fingerprint', 'sensor', 'encrypted', 'none', 'mip', 'label'], 'type': 'str'}, |
| 191 |
'id': {'v_range': [['7.2.0', '']], 'required': True, 'type': 'int'}, |
| 192 |
'label': {'v_range': [['7.2.0', '']], 'type': 'str'}, |
| 193 |
'match-percentage': {'v_range': [['7.2.0', '']], 'type': 'int'}, |
| 194 |
'name': {'v_range': [['7.2.0', '']], 'type': 'str'}, |
| 195 |
'proto': { |
| 196 |
'v_range': [['7.2.0', '']], |
| 197 |
'type': 'list', |
| 198 |
'choices': ['smtp', 'pop3', 'imap', 'http-post', 'http-get', 'ftp', 'nntp', 'mapi', 'ssh', 'cifs'], |
| 199 |
'elements': 'str' |
| 200 |
}, |
| 201 |
'sensitivity': {'v_range': [['7.2.0', '']], 'type': 'raw'}, |
| 202 |
'sensor': {'v_range': [['7.2.0', '']], 'type': 'raw'}, |
| 203 |
'severity': {'v_range': [['7.2.0', '']], 'choices': ['info', 'low', 'medium', 'high', 'critical'], 'type': 'str'}, |
| 204 |
'type': {'v_range': [['7.2.0', '']], 'choices': ['file', 'message'], 'type': 'str'} |
| 205 |
} |
| 206 |
} |
| 207 |
} |
| 208 |
|
| 209 |
module_option_spec = get_module_arg_spec('full crud') |
| 210 |
module_arg_spec.update(module_option_spec) |
| 211 |
check_galaxy_version(module_arg_spec) |
| 212 |
module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'dlp_profile_rule'), |
| 213 |
supports_check_mode=True) |
| 214 |
if not module._socket_path: |
| 215 |
module.fail_json(msg='MUST RUN IN HTTPAPI MODE') |
| 216 |
connection = Connection(module._socket_path) |
| 217 |
fmgr = NAPIManager('full crud', module_arg_spec, urls_list, |
| 218 |
'id', 'data', module, connection) |
| 219 |
fmgr.process_crud() |
| 220 |
module.exit_json(meta=module.params) |
| 221 |
|
| 222 |
|
| 223 |
if __name__ == '__main__': |
| 224 |
main() |