Support Forum
The Forums are a place to find answers on a range of Fortinet products from peers and product experts.
mhm_ameen
New Contributor

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 2
abarushka
Staff
Staff

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

FortiGate
srajeswaran
Staff
Staff

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.


Regards,
Suraj
- Have you found a solution? Then give your helper a "Kudos" and mark the solution.
Announcements

Select Forum Responses to become Knowledge Articles!

Select the “Nominate to Knowledge Base” button to recommend a forum post to become a knowledge article.

Labels
Top Kudoed Authors