ajout name dans json, correction champ equipement matrice de routage, correction doublon headers matrice de routage

This commit is contained in:
Chevallier
2026-01-16 14:57:51 +01:00
parent e4a906652d
commit bb4de4e855
5 changed files with 27 additions and 6 deletions

View File

@@ -44,6 +44,9 @@ def export_to_excel(json_file_path, output_file_excel):
for ni in network_instances:
equipement = ni.get("name", "")
fw_names = data.get("firewall-device", {}).get("name", [])
if equipement not in fw_names:
equipement = ", ".join(fw_names)
protocols = ni.get("protocols", {}).get("protocol", [])
for proto in protocols:
@@ -84,7 +87,7 @@ def export_to_excel(json_file_path, output_file_excel):
df = pd.DataFrame(rows)
with pd.ExcelWriter(output_file_excel, engine="openpyxl") as writer:
df.to_excel(writer,sheet_name="Routes statiques",index=False,startrow=1)
df.to_excel(writer,sheet_name="Routes statiques",index=False,startrow=1,header=False)
wb = load_workbook(output_file_excel)
if "Sheet1" in wb.sheetnames:

View File

@@ -6,11 +6,12 @@ Fournit des méthodes communes pour la conversion et l'exportation des données
from typing import Dict, Any
class ParserMixin:
def to_openconfig_yang(self, type) -> Dict[str, Any]:
def to_openconfig_yang(self, type, name) -> Dict[str, Any]:
"""Convertit la configuration au format OpenConfig YANG avec les nouveaux modèles"""
openconfig = {
"firewall-device": {
"type": type
"type": type,
"name": name
},
"openconfig-interfaces:interfaces": {
"interface": []

View File

@@ -189,7 +189,8 @@ class ForcepointParser(ParserMixin):
def export_to_json(self, output_file: str):
"""Exporte la configuration au format JSON OpenConfig"""
openconfig_data = self.to_openconfig_yang("forcepoint")
fw_names = [cluster.get("name") for cluster in self.root.findall(".//fw_cluster")]
openconfig_data = self.to_openconfig_yang("forcepoint", fw_names)
with open(output_file, 'w', encoding='utf-8') as f:
json.dump(openconfig_data, f, indent=2, ensure_ascii=False)

View File

@@ -451,7 +451,11 @@ class PaloAltoParser(ParserMixin):
def export_to_json(self, output_file: str):
"""Exporte la configuration au format JSON OpenConfig"""
openconfig_data = self.to_openconfig_yang("palo-alto")
fw_name = ""
deviceconfig = self.root.find(".//deviceconfig/system/hostname")
if deviceconfig is not None and deviceconfig.text:
fw_name = deviceconfig.text.strip()
openconfig_data = self.to_openconfig_yang("palo-alto", [fw_name])
with open(output_file, 'w', encoding='utf-8') as f:
json.dump(openconfig_data, f, indent=2, ensure_ascii=False)

View File

@@ -390,6 +390,18 @@ class StormshieldParser(ParserMixin):
self.config["security_rules"].append(rule)
def _parse_name(self):
"""Parse le nom du firewall depuis le fichier network"""
path = os.path.join(self.base_dir, "network")
fw_name = ""
with open(path, "r", encoding="utf-8", errors="ignore") as f:
for line in f:
line = line.strip()
if line.startswith("Name="):
fw_name = line.split("=", 1)[1].strip()
break
return fw_name
def _extract_comment(self, line: str) -> str:
"""Extrait un commentaire après #"""
@@ -409,7 +421,7 @@ class StormshieldParser(ParserMixin):
def export_to_json(self, output_file: str):
"""Exporte la configuration au format JSON OpenConfig"""
openconfig_data = self.to_openconfig_yang("stormshield")
openconfig_data = self.to_openconfig_yang("stormshield", [self._parse_name()])
with open(output_file, 'w', encoding='utf-8') as f:
json.dump(openconfig_data, f, indent=2, ensure_ascii=False)