Skip to main content
mhm_ameen
New Member
November 19, 2023
Question

export policies from multiple fortigate firewalls and import them into one fortigtae firewall

Hi, 

 

we have 4 FortiGate firewall each has around 3000 polices, we want export them and import them into single FortiGate firewall. the question how can i use notepad++ or any other editor to have auto sequential number for policies to make sure no policy ID will be same from all firewalls.

 

in plain English i want i want to find "edit" and have auto incremental number after it. 

2 replies

abarushka
Staff
Staff
November 19, 2023

Hello,

 

Manual configuration edition is not supported since it can lead to mistakes due to lack of input validation. You may consider to use FortiConverter instead. Please find the details by following the link below:

https://www.fortinet.com/products/next-generation-firewall/forticonverter

srajeswaran
Staff
Staff
November 19, 2023

I believe it will be difficult/not possible to do with just text editors, but can be done with the help of a python script as below.

______________________________________________________

import sys
import re

def replace_edits_with_sequence(txt_path):
with open(txt_path, 'r') as file:
lines = file.readlines()

sequence_counter = 1

lines = [re.sub(r'^edit\d+', 'edit', line, flags=re.IGNORECASE) for line in lines]

def repl(match):
nonlocal sequence_counter
replacement = f'edit{sequence_counter}'
sequence_counter += 1
return replacement

lines = [re.sub(r'\bedit\b', repl, line, flags=re.IGNORECASE) for line in lines]

updated_txt_path = txt_path.replace('.txt', '_updated.txt')
with open(updated_txt_path, 'w') as file:
file.writelines(lines)

print(f"File updated and saved as: {updated_txt_path}")

if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python script.py <input_file.txt>")
sys.exit(1)

input_file = sys.argv[1]
replace_edits_with_sequence(input_file)
______________________________________________________

Save the above script as <name>.py file (example script.py) and then save your consolidated policies file in .txt file (exmple Consolidatedpolicies.txt) on same folder.

Run the script as > script.py Consolidatedpolicies.txt
This will give output as Consolidatedpolicies_updated.txt with corrected sequence numbers.


Thought Leadership. Security Summit. Thursday, November 12th, PGA National Resort, Palm Beach Gardens, FL.
Thought Leadership. Security Summit. Thursday, October 8th. Disney's Grand Californian Hotel & SPA, Anaheim, CA.
Security Operations Summit: Modernize SecOps. Operate AI-Native.AMER: November 4 | 9:00 AM PST. India and SAARC: November 5 | 10:00 AM IST. EMEA: November 5 | 10:30 AM CET. APAC: November 5 | 11:00 AM SGT