Improve Fortios IPv4 policy with logging capabilities and use the backup_filename param (#23544)
* Improve Fortios IPv4 policy with logging capabilities. While there, fix typos in examples. forti_config: use the backup_filename param and dont enforce the the filename value. * forti-typos * Add version_added for new options in the documentationpull/4420/head
parent
92a425a532
commit
811eb66703
|
@ -65,12 +65,16 @@ fortios_error_codes = {
|
||||||
|
|
||||||
def backup(module,running_config):
|
def backup(module,running_config):
|
||||||
backup_path = module.params['backup_path']
|
backup_path = module.params['backup_path']
|
||||||
|
backup_filename = module.params['backup_filename']
|
||||||
if not os.path.exists(backup_path):
|
if not os.path.exists(backup_path):
|
||||||
try:
|
try:
|
||||||
os.mkdir(backup_path)
|
os.mkdir(backup_path)
|
||||||
except:
|
except:
|
||||||
module.fail_json(msg="Can't create directory {0} Permission denied ?".format(backup_path))
|
module.fail_json(msg="Can't create directory {0} Permission denied ?".format(backup_path))
|
||||||
tstamp = time.strftime("%Y-%m-%d@%H:%M:%S", time.localtime(time.time()))
|
tstamp = time.strftime("%Y-%m-%d@%H:%M:%S", time.localtime(time.time()))
|
||||||
|
if 0 < len(backup_filename):
|
||||||
|
filename = '%s/%s' % (backup_path, backup_filename)
|
||||||
|
else:
|
||||||
filename = '%s/%s_config.%s' % (backup_path, module.params['host'], tstamp)
|
filename = '%s/%s_config.%s' % (backup_path, module.params['host'], tstamp)
|
||||||
try:
|
try:
|
||||||
open(filename, 'w').write(running_config)
|
open(filename, 'w').write(running_config)
|
||||||
|
|
|
@ -117,6 +117,18 @@ options:
|
||||||
application_list:
|
application_list:
|
||||||
description:
|
description:
|
||||||
- Specifies Application Control name.
|
- Specifies Application Control name.
|
||||||
|
logtraffic:
|
||||||
|
version_added: "2.4"
|
||||||
|
description:
|
||||||
|
- Logs sessions that matched policy.
|
||||||
|
default: utm
|
||||||
|
choices: ['disable', 'utm', 'all']
|
||||||
|
logtraffic_start:
|
||||||
|
version_added: "2.4"
|
||||||
|
description:
|
||||||
|
- Logs begining of session as well.
|
||||||
|
default: false
|
||||||
|
choices: ["true", "false"]
|
||||||
comment:
|
comment:
|
||||||
description:
|
description:
|
||||||
- free text to describe policy.
|
- free text to describe policy.
|
||||||
|
@ -131,12 +143,13 @@ EXAMPLES = """
|
||||||
username: admin
|
username: admin
|
||||||
password: password
|
password: password
|
||||||
id: 42
|
id: 42
|
||||||
srcaddr: internal_network
|
src_addr: internal_network
|
||||||
dstaddr: all
|
dst_addr: all
|
||||||
service: dns
|
service: dns
|
||||||
nat: True
|
nat: True
|
||||||
state: present
|
state: present
|
||||||
policy_action: accept
|
policy_action: accept
|
||||||
|
logtraffic: disable
|
||||||
|
|
||||||
- name: Public Web
|
- name: Public Web
|
||||||
fortios_ipv4_policy:
|
fortios_ipv4_policy:
|
||||||
|
@ -144,8 +157,8 @@ EXAMPLES = """
|
||||||
username: admin
|
username: admin
|
||||||
password: password
|
password: password
|
||||||
id: 42
|
id: 42
|
||||||
srcaddr: all
|
src_addr: all
|
||||||
dstaddr: webservers
|
dst_addr: webservers
|
||||||
services:
|
services:
|
||||||
- http
|
- http
|
||||||
- https
|
- https
|
||||||
|
@ -197,6 +210,8 @@ def main():
|
||||||
webfilter_profile = dict(type='str'),
|
webfilter_profile = dict(type='str'),
|
||||||
ips_sensor = dict(type='str'),
|
ips_sensor = dict(type='str'),
|
||||||
application_list = dict(type='str'),
|
application_list = dict(type='str'),
|
||||||
|
logtraffic = dict(choices=['disable','all','utm'], default='utm'),
|
||||||
|
logtraffic_start = dict(type='bool', default=False),
|
||||||
)
|
)
|
||||||
|
|
||||||
#merge global required_if & argument_spec from module_utils/fortios.py
|
#merge global required_if & argument_spec from module_utils/fortios.py
|
||||||
|
@ -226,6 +241,11 @@ def main():
|
||||||
if module.params['fixedport']:
|
if module.params['fixedport']:
|
||||||
module.fail_json(msg='Fixedport param requires NAT to be true.')
|
module.fail_json(msg='Fixedport param requires NAT to be true.')
|
||||||
|
|
||||||
|
#log options
|
||||||
|
if module.params['logtraffic_start']:
|
||||||
|
if not module.params['logtraffic'] == 'all':
|
||||||
|
module.fail_json(msg='Logtraffic_start param requires logtraffic to be set to "all".')
|
||||||
|
|
||||||
#id must be str(int) for pyFG to work
|
#id must be str(int) for pyFG to work
|
||||||
policy_id = str(module.params['id'])
|
policy_id = str(module.params['id'])
|
||||||
|
|
||||||
|
@ -260,6 +280,14 @@ def main():
|
||||||
# action
|
# action
|
||||||
new_policy.set_param('action', '%s' % (module.params['policy_action']))
|
new_policy.set_param('action', '%s' % (module.params['policy_action']))
|
||||||
|
|
||||||
|
#logging
|
||||||
|
new_policy.set_param('logtraffic', '%s' % (module.params['logtraffic']))
|
||||||
|
if module.params['logtraffic'] == 'all':
|
||||||
|
if module.params['logtraffic_start']:
|
||||||
|
new_policy.set_param('logtraffic-start', 'enable')
|
||||||
|
else:
|
||||||
|
new_policy.set_param('logtraffic-start', 'disable')
|
||||||
|
|
||||||
# Schedule
|
# Schedule
|
||||||
new_policy.set_param('schedule', '%s' % (module.params['schedule']))
|
new_policy.set_param('schedule', '%s' % (module.params['schedule']))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue