| 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_log_npuserver |
| 15 |
short_description: Configure all the log servers and create the server groups. |
| 16 |
version_added: "2.2.0" |
| 17 |
extends_documentation_fragment: |
| 18 |
- fortinet.fortimanager.general |
| 19 |
- fortinet.fortimanager.general.partial_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 |
log_npuserver: |
| 29 |
description: The top level parameters set. |
| 30 |
required: false |
| 31 |
type: dict |
| 32 |
suboptions: |
| 33 |
log_processing: |
| 34 |
aliases: ['log-processing'] |
| 35 |
type: str |
| 36 |
description: Configure log processed by host to drop or no drop. |
| 37 |
choices: ['may-drop', 'no-drop'] |
| 38 |
log_processor: |
| 39 |
aliases: ['log-processor'] |
| 40 |
type: str |
| 41 |
description: Configure the log module. |
| 42 |
choices: ['hardware', 'host'] |
| 43 |
netflow_ver: |
| 44 |
aliases: ['netflow-ver'] |
| 45 |
type: str |
| 46 |
description: Configure the netfow verson. |
| 47 |
choices: ['v9', 'v10'] |
| 48 |
server_group: |
| 49 |
aliases: ['server-group'] |
| 50 |
type: list |
| 51 |
elements: dict |
| 52 |
description: Server group. |
| 53 |
suboptions: |
| 54 |
group_name: |
| 55 |
aliases: ['group-name'] |
| 56 |
type: str |
| 57 |
description: Server group name. |
| 58 |
log_format: |
| 59 |
aliases: ['log-format'] |
| 60 |
type: str |
| 61 |
description: Set the log format |
| 62 |
choices: ['syslog', 'netflow'] |
| 63 |
log_mode: |
| 64 |
aliases: ['log-mode'] |
| 65 |
type: str |
| 66 |
description: Set the log mode |
| 67 |
choices: ['per-session', 'per-nat-mapping', 'per-session-ending'] |
| 68 |
log_tx_mode: |
| 69 |
aliases: ['log-tx-mode'] |
| 70 |
type: str |
| 71 |
description: Configure log transmit mode. |
| 72 |
choices: ['multicast', 'roundrobin'] |
| 73 |
server_number: |
| 74 |
aliases: ['server-number'] |
| 75 |
type: int |
| 76 |
description: Server number in this group. |
| 77 |
server_start_id: |
| 78 |
aliases: ['server-start-id'] |
| 79 |
type: int |
| 80 |
description: The start id of the continuous server series in this group,[1,16]. |
| 81 |
sw_log_flags: |
| 82 |
aliases: ['sw-log-flags'] |
| 83 |
type: raw |
| 84 |
description: (int or str) Set flags for software logging via driver. |
| 85 |
log_gen_event: |
| 86 |
aliases: ['log-gen-event'] |
| 87 |
type: str |
| 88 |
description: Enable/disbale generating event for Per-Mapping log |
| 89 |
choices: ['disable', 'enable'] |
| 90 |
log_user_info: |
| 91 |
aliases: ['log-user-info'] |
| 92 |
type: str |
| 93 |
description: Enable/disbale logging user information. |
| 94 |
choices: ['disable', 'enable'] |
| 95 |
server_info: |
| 96 |
aliases: ['server-info'] |
| 97 |
type: list |
| 98 |
elements: dict |
| 99 |
description: Server info. |
| 100 |
suboptions: |
| 101 |
dest_port: |
| 102 |
aliases: ['dest-port'] |
| 103 |
type: int |
| 104 |
description: Set the dest port for the log packet |
| 105 |
id: |
| 106 |
type: int |
| 107 |
description: Server id. |
| 108 |
ip_family: |
| 109 |
aliases: ['ip-family'] |
| 110 |
type: str |
| 111 |
description: Set the version the IP address |
| 112 |
choices: ['v4', 'v6'] |
| 113 |
ipv4_server: |
| 114 |
aliases: ['ipv4-server'] |
| 115 |
type: str |
| 116 |
description: Set the IPv4 address for the log server |
| 117 |
ipv6_server: |
| 118 |
aliases: ['ipv6-server'] |
| 119 |
type: str |
| 120 |
description: Set the IPv6 address for the log server |
| 121 |
source_port: |
| 122 |
aliases: ['source-port'] |
| 123 |
type: int |
| 124 |
description: Set the source port for the log packet |
| 125 |
template_tx_timeout: |
| 126 |
aliases: ['template-tx-timeout'] |
| 127 |
type: int |
| 128 |
description: Set the template tx timeout |
| 129 |
vdom: |
| 130 |
type: str |
| 131 |
description: Interface connected to the log server is in this virtual domain |
| 132 |
log_transport: |
| 133 |
aliases: ['log-transport'] |
| 134 |
type: str |
| 135 |
description: Set transport protocol |
| 136 |
choices: ['udp', 'tcp'] |
| 137 |
vdom_: |
| 138 |
type: str |
| 139 |
description: Vdom. |
| 140 |
fmgr_syslog_facility: |
| 141 |
aliases: ['syslog-facility'] |
| 142 |
type: int |
| 143 |
description: Configure the syslog facility. |
| 144 |
syslog_severity: |
| 145 |
aliases: ['syslog-severity'] |
| 146 |
type: int |
| 147 |
description: Configure the syslog severity. |
| 148 |
enforce_seq_order: |
| 149 |
aliases: ['enforce-seq-order'] |
| 150 |
type: str |
| 151 |
description: Sw session netflow logs will be delivered in strict order if the option is enabled. |
| 152 |
choices: ['disable', 'enable'] |
| 153 |
''' |
| 154 |
|
| 155 |
EXAMPLES = ''' |
| 156 |
- name: Example playbook (generated based on argument schema) |
| 157 |
hosts: fortimanagers |
| 158 |
connection: httpapi |
| 159 |
gather_facts: false |
| 160 |
tasks: |
| 161 |
- name: Configure all the log servers and create the server groups. |
| 162 |
fortinet.fortimanager.fmgr_log_npuserver: |
| 163 |
# workspace_locking_adom: <global or your adom name> |
| 164 |
adom: <your own value> |
| 165 |
log_npuserver: |
| 166 |
# log_processing: <value in [may-drop, no-drop]> |
| 167 |
# log_processor: <value in [hardware, host]> |
| 168 |
# netflow_ver: <value in [v9, v10]> |
| 169 |
# server_group: |
| 170 |
# - group_name: <string> |
| 171 |
# log_format: <value in [syslog, netflow]> |
| 172 |
# log_mode: <value in [per-session, per-nat-mapping, per-session-ending]> |
| 173 |
# log_tx_mode: <value in [multicast, roundrobin]> |
| 174 |
# server_number: <integer> |
| 175 |
# server_start_id: <integer> |
| 176 |
# sw_log_flags: <value in [tcp-udp-only, enable-all-log, disable-all-log]> |
| 177 |
# log_gen_event: <value in [disable, enable]> |
| 178 |
# log_user_info: <value in [disable, enable]> |
| 179 |
# server_info: |
| 180 |
# - dest_port: <integer> |
| 181 |
# id: <integer> |
| 182 |
# ip_family: <value in [v4, v6]> |
| 183 |
# ipv4_server: <string> |
| 184 |
# ipv6_server: <string> |
| 185 |
# source_port: <integer> |
| 186 |
# template_tx_timeout: <integer> |
| 187 |
# vdom: <string> |
| 188 |
# log_transport: <value in [udp, tcp]> |
| 189 |
# vdom_: <string> |
| 190 |
# fmgr_syslog_facility: <integer> |
| 191 |
# syslog_severity: <integer> |
| 192 |
# enforce_seq_order: <value in [disable, enable]> |
| 193 |
''' |
| 194 |
|
| 195 |
RETURN = ''' |
| 196 |
meta: |
| 197 |
description: The result of the request. |
| 198 |
type: dict |
| 199 |
returned: always |
| 200 |
contains: |
| 201 |
request_url: |
| 202 |
description: The full url requested. |
| 203 |
returned: always |
| 204 |
type: str |
| 205 |
sample: /sys/login/user |
| 206 |
response_code: |
| 207 |
description: The status of api request. |
| 208 |
returned: always |
| 209 |
type: int |
| 210 |
sample: 0 |
| 211 |
response_data: |
| 212 |
description: The api response. |
| 213 |
type: list |
| 214 |
returned: always |
| 215 |
response_message: |
| 216 |
description: The descriptive message of the api response. |
| 217 |
type: str |
| 218 |
returned: always |
| 219 |
sample: OK. |
| 220 |
system_information: |
| 221 |
description: The information of the target system. |
| 222 |
type: dict |
| 223 |
returned: always |
| 224 |
rc: |
| 225 |
description: The status the request. |
| 226 |
type: int |
| 227 |
returned: always |
| 228 |
sample: 0 |
| 229 |
version_check_warning: |
| 230 |
description: Warning if the parameters used in the playbook are not supported by the current FortiManager version. |
| 231 |
type: list |
| 232 |
returned: complex |
| 233 |
''' |
| 234 |
from ansible.module_utils.basic import AnsibleModule |
| 235 |
from ansible.module_utils.connection import Connection |
| 236 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass |
| 237 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec |
| 238 |
|
| 239 |
|
| 240 |
def main(): |
| 241 |
urls_list = [ |
| 242 |
'/pm/config/adom/{adom}/obj/log/npu-server', |
| 243 |
'/pm/config/global/obj/log/npu-server' |
| 244 |
] |
| 245 |
module_arg_spec = { |
| 246 |
'adom': {'required': True, 'type': 'str'}, |
| 247 |
'revision_note': {'type': 'str'}, |
| 248 |
'log_npuserver': { |
| 249 |
'type': 'dict', 'v_range': [['6.4.7', '6.4.15'], ['7.0.1', '7.0.14'], ['7.2.0', '7.4.7'], ['7.6.0', '7.6.4']], |
| 250 |
'options': { |
| 251 |
'log-processing': { |
| 252 |
'v_range': [['6.4.8', '6.4.15'], ['7.0.3', '7.0.14'], ['7.2.0', '7.4.7'], ['7.6.0', '7.6.4']], |
| 253 |
'choices': ['may-drop', 'no-drop'], |
| 254 |
'type': 'str' |
| 255 |
}, |
| 256 |
'log-processor': { |
| 257 |
'v_range': [['6.4.7', '6.4.15'], ['7.0.1', '7.0.14'], ['7.2.0', '7.4.7'], ['7.6.0', '7.6.4']], |
| 258 |
'choices': ['hardware', 'host'], |
| 259 |
'type': 'str' |
| 260 |
}, |
| 261 |
'netflow-ver': { |
| 262 |
'v_range': [['6.4.7', '6.4.15'], ['7.0.1', '7.0.14'], ['7.2.0', '7.4.7'], ['7.6.0', '7.6.4']], |
| 263 |
'choices': ['v9', 'v10'], |
| 264 |
'type': 'str' |
| 265 |
}, |
| 266 |
'server-group': { |
| 267 |
'v_range': [['6.4.7', '6.4.15'], ['7.0.1', '7.0.14'], ['7.2.0', '7.4.7'], ['7.6.0', '7.6.4']], |
| 268 |
'type': 'list', |
| 269 |
'options': { |
| 270 |
'group-name': {'v_range': [['6.4.7', '6.4.15'], ['7.0.1', '7.0.14'], ['7.2.0', '7.4.7'], ['7.6.0', '7.6.4']], 'type': 'str'}, |
| 271 |
'log-format': { |
| 272 |
'v_range': [['6.4.7', '6.4.15'], ['7.0.1', '7.0.14'], ['7.2.0', '7.4.7'], ['7.6.0', '7.6.4']], |
| 273 |
'choices': ['syslog', 'netflow'], |
| 274 |
'type': 'str' |
| 275 |
}, |
| 276 |
'log-mode': { |
| 277 |
'v_range': [['6.4.7', '6.4.15'], ['7.0.1', '7.0.14'], ['7.2.0', '7.4.7'], ['7.6.0', '7.6.4']], |
| 278 |
'choices': ['per-session', 'per-nat-mapping', 'per-session-ending'], |
| 279 |
'type': 'str' |
| 280 |
}, |
| 281 |
'log-tx-mode': { |
| 282 |
'v_range': [['6.4.7', '6.4.15'], ['7.0.2', '7.0.14'], ['7.2.0', '7.4.7'], ['7.6.0', '7.6.4']], |
| 283 |
'choices': ['multicast', 'roundrobin'], |
| 284 |
'type': 'str' |
| 285 |
}, |
| 286 |
'server-number': {'v_range': [['6.4.7', '6.4.15'], ['7.0.1', '7.0.14'], ['7.2.0', '7.4.7'], ['7.6.0', '7.6.4']], 'type': 'int'}, |
| 287 |
'server-start-id': {'v_range': [['6.4.7', '6.4.15'], ['7.0.1', '7.0.14'], ['7.2.0', '7.4.7'], ['7.6.0', '7.6.4']], 'type': 'int'}, |
| 288 |
'sw-log-flags': {'v_range': [['6.4.8', '6.4.15'], ['7.0.3', '7.0.14'], ['7.2.0', '7.4.7'], ['7.6.0', '7.6.4']], 'type': 'raw'}, |
| 289 |
'log-gen-event': { |
| 290 |
'v_range': [['7.0.4', '7.0.14'], ['7.2.1', '7.4.7'], ['7.6.0', '7.6.4']], |
| 291 |
'choices': ['disable', 'enable'], |
| 292 |
'type': 'str' |
| 293 |
}, |
| 294 |
'log-user-info': { |
| 295 |
'v_range': [['7.0.4', '7.0.14'], ['7.2.1', '7.4.7'], ['7.6.0', '7.6.4']], |
| 296 |
'choices': ['disable', 'enable'], |
| 297 |
'type': 'str' |
| 298 |
} |
| 299 |
}, |
| 300 |
'elements': 'dict' |
| 301 |
}, |
| 302 |
'server-info': { |
| 303 |
'v_range': [['6.4.7', '6.4.15'], ['7.0.1', '7.0.14'], ['7.2.0', '7.4.7'], ['7.6.0', '7.6.4']], |
| 304 |
'type': 'list', |
| 305 |
'options': { |
| 306 |
'dest-port': {'v_range': [['6.4.7', '6.4.15'], ['7.0.1', '7.0.14'], ['7.2.0', '7.4.7'], ['7.6.0', '7.6.4']], 'type': 'int'}, |
| 307 |
'id': {'v_range': [['6.4.7', '6.4.15'], ['7.0.1', '7.0.14'], ['7.2.0', '7.4.7'], ['7.6.0', '7.6.4']], 'type': 'int'}, |
| 308 |
'ip-family': { |
| 309 |
'v_range': [['6.4.7', '6.4.15'], ['7.0.1', '7.0.14'], ['7.2.0', '7.4.7'], ['7.6.0', '7.6.4']], |
| 310 |
'choices': ['v4', 'v6'], |
| 311 |
'type': 'str' |
| 312 |
}, |
| 313 |
'ipv4-server': {'v_range': [['6.4.7', '6.4.15'], ['7.0.1', '7.0.14'], ['7.2.0', '7.4.7'], ['7.6.0', '7.6.4']], 'type': 'str'}, |
| 314 |
'ipv6-server': {'v_range': [['6.4.7', '6.4.15'], ['7.0.1', '7.0.14'], ['7.2.0', '7.4.7'], ['7.6.0', '7.6.4']], 'type': 'str'}, |
| 315 |
'source-port': {'v_range': [['6.4.7', '6.4.15'], ['7.0.1', '7.0.14'], ['7.2.0', '7.4.7'], ['7.6.0', '7.6.4']], 'type': 'int'}, |
| 316 |
'template-tx-timeout': { |
| 317 |
'v_range': [['6.4.7', '6.4.15'], ['7.0.1', '7.0.14'], ['7.2.0', '7.4.7'], ['7.6.0', '7.6.4']], |
| 318 |
'type': 'int' |
| 319 |
}, |
| 320 |
'vdom': { |
| 321 |
'v_range': [['6.4.7', '6.4.15'], ['7.0.1', '7.0.14'], ['7.2.0', '7.2.10'], ['7.4.0', '7.4.7'], ['7.6.0', '7.6.4']], |
| 322 |
'type': 'str' |
| 323 |
}, |
| 324 |
'log-transport': {'v_range': [['7.4.2', '7.4.7'], ['7.6.0', '7.6.4']], 'choices': ['udp', 'tcp'], 'type': 'str'}, |
| 325 |
'vdom_': {'v_range': [['7.2.11', '7.2.12'], ['7.6.4', '7.6.4']], 'type': 'str'} |
| 326 |
}, |
| 327 |
'elements': 'dict' |
| 328 |
}, |
| 329 |
'syslog-facility': {'v_range': [['6.4.7', '6.4.15'], ['7.0.1', '7.0.14'], ['7.2.0', '7.4.7'], ['7.6.0', '7.6.4']], 'type': 'int'}, |
| 330 |
'syslog-severity': {'v_range': [['6.4.7', '6.4.15'], ['7.0.1', '7.0.14'], ['7.2.0', '7.4.7'], ['7.6.0', '7.6.4']], 'type': 'int'}, |
| 331 |
'enforce-seq-order': {'v_range': [['7.4.2', '7.4.7'], ['7.6.0', '7.6.4']], 'choices': ['disable', 'enable'], 'type': 'str'} |
| 332 |
} |
| 333 |
} |
| 334 |
} |
| 335 |
|
| 336 |
module_option_spec = get_module_arg_spec('partial crud') |
| 337 |
module_arg_spec.update(module_option_spec) |
| 338 |
check_galaxy_version(module_arg_spec) |
| 339 |
module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'log_npuserver'), |
| 340 |
supports_check_mode=True) |
| 341 |
if not module._socket_path: |
| 342 |
module.fail_json(msg='MUST RUN IN HTTPAPI MODE') |
| 343 |
connection = Connection(module._socket_path) |
| 344 |
fmgr = NAPIManager('partial crud', module_arg_spec, urls_list, |
| 345 |
None, 'data', module, connection) |
| 346 |
fmgr.process_partial_crud() |
| 347 |
module.exit_json(meta=module.params) |
| 348 |
|
| 349 |
|
| 350 |
if __name__ == '__main__': |
| 351 |
main() |