diff --git a/Parseurs_config_Firewall/src/scripts/export_matrice_routage.py b/Parseurs_config_Firewall/src/scripts/export_matrice_routage.py index 4934dc6..5d76ecb 100644 --- a/Parseurs_config_Firewall/src/scripts/export_matrice_routage.py +++ b/Parseurs_config_Firewall/src/scripts/export_matrice_routage.py @@ -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: diff --git a/Parseurs_config_Firewall/src/scripts/export_modele.py b/Parseurs_config_Firewall/src/scripts/export_modele.py index 4aea972..d4d01d7 100644 --- a/Parseurs_config_Firewall/src/scripts/export_modele.py +++ b/Parseurs_config_Firewall/src/scripts/export_modele.py @@ -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": [] diff --git a/Parseurs_config_Firewall/src/scripts/json_Forcepoint.py b/Parseurs_config_Firewall/src/scripts/json_Forcepoint.py index 3aadda4..aff2d78 100644 --- a/Parseurs_config_Firewall/src/scripts/json_Forcepoint.py +++ b/Parseurs_config_Firewall/src/scripts/json_Forcepoint.py @@ -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) diff --git a/Parseurs_config_Firewall/src/scripts/json_PaloAlto.py b/Parseurs_config_Firewall/src/scripts/json_PaloAlto.py index 6e7d64f..b1f8a15 100644 --- a/Parseurs_config_Firewall/src/scripts/json_PaloAlto.py +++ b/Parseurs_config_Firewall/src/scripts/json_PaloAlto.py @@ -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) diff --git a/Parseurs_config_Firewall/src/scripts/json_Stormshield.py b/Parseurs_config_Firewall/src/scripts/json_Stormshield.py index 4a26c05..347274e 100644 --- a/Parseurs_config_Firewall/src/scripts/json_Stormshield.py +++ b/Parseurs_config_Firewall/src/scripts/json_Stormshield.py @@ -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)