| 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_system_log_ratelimit |
| 15 |
short_description: Logging rate limit. |
| 16 |
version_added: "2.1.0" |
| 17 |
extends_documentation_fragment: |
| 18 |
- fortinet.fortimanager.general |
| 19 |
- fortinet.fortimanager.general.partial_crud |
| 20 |
options: |
| 21 |
system_log_ratelimit: |
| 22 |
description: The top level parameters set. |
| 23 |
required: false |
| 24 |
type: dict |
| 25 |
suboptions: |
| 26 |
device: |
| 27 |
type: list |
| 28 |
elements: dict |
| 29 |
description: Device. |
| 30 |
suboptions: |
| 31 |
device: |
| 32 |
type: str |
| 33 |
description: Device |
| 34 |
filter_type: |
| 35 |
aliases: ['filter-type'] |
| 36 |
type: str |
| 37 |
description: |
| 38 |
- Device filter type. |
| 39 |
- devid - Device ID. |
| 40 |
choices: ['devid'] |
| 41 |
id: |
| 42 |
type: int |
| 43 |
description: Device filter ID. |
| 44 |
ratelimit: |
| 45 |
type: int |
| 46 |
description: Maximum device log rate limit. |
| 47 |
device_ratelimit_default: |
| 48 |
aliases: ['device-ratelimit-default'] |
| 49 |
type: int |
| 50 |
description: Default maximum device log rate limit. |
| 51 |
mode: |
| 52 |
type: str |
| 53 |
description: |
| 54 |
- Logging rate limit mode. |
| 55 |
- disable - Logging rate limit function disabled. |
| 56 |
- manual - System rate limit and device rate limit both configurable, no limit if not configured. |
| 57 |
choices: ['disable', 'manual'] |
| 58 |
system_ratelimit: |
| 59 |
aliases: ['system-ratelimit'] |
| 60 |
type: int |
| 61 |
description: Maximum system log rate limit. |
| 62 |
ratelimits: |
| 63 |
type: list |
| 64 |
elements: dict |
| 65 |
description: Ratelimits. |
| 66 |
suboptions: |
| 67 |
filter: |
| 68 |
type: str |
| 69 |
description: Device or ADOM filter according to filter-type setting, wildcard expression supported. |
| 70 |
filter_type: |
| 71 |
aliases: ['filter-type'] |
| 72 |
type: str |
| 73 |
description: |
| 74 |
- Device filter type. |
| 75 |
- devid - Device ID. |
| 76 |
- adom - ADOM name. |
| 77 |
choices: ['devid', 'adom'] |
| 78 |
id: |
| 79 |
type: int |
| 80 |
description: Filter ID. |
| 81 |
ratelimit: |
| 82 |
type: int |
| 83 |
description: Maximum log rate limit. |
| 84 |
''' |
| 85 |
|
| 86 |
EXAMPLES = ''' |
| 87 |
- name: Example playbook (generated based on argument schema) |
| 88 |
hosts: fortimanagers |
| 89 |
connection: httpapi |
| 90 |
gather_facts: false |
| 91 |
tasks: |
| 92 |
- name: Logging rate limit. |
| 93 |
fortinet.fortimanager.fmgr_system_log_ratelimit: |
| 94 |
# workspace_locking_adom: <global or your adom name> |
| 95 |
system_log_ratelimit: |
| 96 |
# device: |
| 97 |
# - device: <string> |
| 98 |
# filter_type: <value in [devid]> |
| 99 |
# id: <integer> |
| 100 |
# ratelimit: <integer> |
| 101 |
# device_ratelimit_default: <integer> |
| 102 |
# mode: <value in [disable, manual]> |
| 103 |
# system_ratelimit: <integer> |
| 104 |
# ratelimits: |
| 105 |
# - filter: <string> |
| 106 |
# filter_type: <value in [devid, adom]> |
| 107 |
# id: <integer> |
| 108 |
# ratelimit: <integer> |
| 109 |
''' |
| 110 |
|
| 111 |
RETURN = ''' |
| 112 |
meta: |
| 113 |
description: The result of the request. |
| 114 |
type: dict |
| 115 |
returned: always |
| 116 |
contains: |
| 117 |
request_url: |
| 118 |
description: The full url requested. |
| 119 |
returned: always |
| 120 |
type: str |
| 121 |
sample: /sys/login/user |
| 122 |
response_code: |
| 123 |
description: The status of api request. |
| 124 |
returned: always |
| 125 |
type: int |
| 126 |
sample: 0 |
| 127 |
response_data: |
| 128 |
description: The api response. |
| 129 |
type: list |
| 130 |
returned: always |
| 131 |
response_message: |
| 132 |
description: The descriptive message of the api response. |
| 133 |
type: str |
| 134 |
returned: always |
| 135 |
sample: OK. |
| 136 |
system_information: |
| 137 |
description: The information of the target system. |
| 138 |
type: dict |
| 139 |
returned: always |
| 140 |
rc: |
| 141 |
description: The status the request. |
| 142 |
type: int |
| 143 |
returned: always |
| 144 |
sample: 0 |
| 145 |
version_check_warning: |
| 146 |
description: Warning if the parameters used in the playbook are not supported by the current FortiManager version. |
| 147 |
type: list |
| 148 |
returned: complex |
| 149 |
''' |
| 150 |
from ansible.module_utils.basic import AnsibleModule |
| 151 |
from ansible.module_utils.connection import Connection |
| 152 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass |
| 153 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec |
| 154 |
|
| 155 |
|
| 156 |
def main(): |
| 157 |
urls_list = [ |
| 158 |
'/cli/global/system/log/ratelimit' |
| 159 |
] |
| 160 |
module_arg_spec = { |
| 161 |
'system_log_ratelimit': { |
| 162 |
'type': 'dict', 'v_range': [['6.4.8', '']], |
| 163 |
'options': { |
| 164 |
'device': { |
| 165 |
'v_range': [['6.4.8', '7.0.2']], |
| 166 |
'type': 'list', |
| 167 |
'options': { |
| 168 |
'device': {'v_range': [['6.4.8', '7.0.2']], 'type': 'str'}, |
| 169 |
'filter-type': {'v_range': [['6.4.8', '7.0.2']], 'choices': ['devid'], 'type': 'str'}, |
| 170 |
'id': {'v_range': [['6.4.8', '7.0.2']], 'type': 'int'}, |
| 171 |
'ratelimit': {'v_range': [['6.4.8', '7.0.2']], 'type': 'int'} |
| 172 |
}, |
| 173 |
'elements': 'dict' |
| 174 |
}, |
| 175 |
'device-ratelimit-default': {'v_range': [['6.4.8', '']], 'type': 'int'}, |
| 176 |
'mode': {'v_range': [['6.4.8', '']], 'choices': ['disable', 'manual'], 'type': 'str'}, |
| 177 |
'system-ratelimit': {'v_range': [['6.4.8', '']], 'type': 'int'}, |
| 178 |
'ratelimits': { |
| 179 |
'v_range': [['7.0.3', '']], |
| 180 |
'type': 'list', |
| 181 |
'options': { |
| 182 |
'filter': {'v_range': [['7.0.3', '']], 'type': 'str'}, |
| 183 |
'filter-type': {'v_range': [['7.0.3', '']], 'choices': ['devid', 'adom'], 'type': 'str'}, |
| 184 |
'id': {'v_range': [['7.0.3', '']], 'type': 'int'}, |
| 185 |
'ratelimit': {'v_range': [['7.0.3', '']], 'type': 'int'} |
| 186 |
}, |
| 187 |
'elements': 'dict' |
| 188 |
} |
| 189 |
} |
| 190 |
} |
| 191 |
} |
| 192 |
|
| 193 |
module_option_spec = get_module_arg_spec('partial crud') |
| 194 |
module_arg_spec.update(module_option_spec) |
| 195 |
check_galaxy_version(module_arg_spec) |
| 196 |
module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'system_log_ratelimit'), |
| 197 |
supports_check_mode=True) |
| 198 |
if not module._socket_path: |
| 199 |
module.fail_json(msg='MUST RUN IN HTTPAPI MODE') |
| 200 |
connection = Connection(module._socket_path) |
| 201 |
fmgr = NAPIManager('partial crud', module_arg_spec, urls_list, |
| 202 |
None, 'data', module, connection) |
| 203 |
fmgr.process_partial_crud() |
| 204 |
module.exit_json(meta=module.params) |
| 205 |
|
| 206 |
|
| 207 |
if __name__ == '__main__': |
| 208 |
main() |