ajout de doc

This commit is contained in:
Chevallier
2026-05-26 15:10:05 +02:00
parent f79e6e69c4
commit d6ecf14737
12 changed files with 1830 additions and 44 deletions

View File

@@ -0,0 +1,781 @@
```json
{
"switch-device": {
"type": "hpe",
"name": "NOM_Switch"
},
"openconfig-system:system": {
"state": [
{
"hostname": "NOM_Switch",
"login-banner": [
"Message de",
"Connexion"
],
"motd-banner": [
"Message de",
"Connexion"
],
"current-datetime": "",
"up-time": "1 weeks, 1 days, 1 hours, 1 minutes",
"software-version": "Version 1 Release 1"
}
],
"aaa": {
"authentication": {
"users": {
"user": [
{
"username": "user",
"config": {
"username": "user",
"password-hashed": "hash",
"role": "role",
"openconfig-system-ext:allowed-services": [
"http"
]
}
}
]
}
}
},
"processes": {
"process": [
{
"pid": 1, // int de l'id du master
"state": {
"pid": 1, // int de l'id du master
"args": [
"cpu process master",
"liste des éléments",
"process master",
"liste des éléments"
]
}
}
]
},
"messages": {
"state": {
"message": [
{
"msg": "log" //string de tous les logs
}
]
}
},
"ssh-server": {
"enabled": true,
"config": {
"enabled": true,
"openconfig-system-ext:access-permissible": "1"
}
},
"cpus": {
"cpu": [
{
"index": 1, // int de l'id du master
"state": {
"index": 1, // int de l'id du master
"instant": 0, // % CPU utilization in 5 secs
"min": 0, // % CPU utilization in 1 min
"max": 0 // % CPU utilization in 5 mins
}
}
]
},
"ntp": {
"config": {
"enabled": true,
"ntp-source-address": "interface name"
},
"servers": {
"server": [
{
"address": "ip",
"config": {
"address": "ip",
"prefer": true
}
}
]
},
"peers": {
"peer": [
{
"address": "ip",
"config": {
"address": "ip",
"prefer": true
}
}
]
}
}
},
"openconfig-lldp:lldp": {
"config": {
"enabled": true
}
},
"openconfig-relay-agent:relay-agent": {
"dhcp": {
"config": {
"enable-relay-agent": true
}
}
},
"ietf-snmp:snmp": {
"ietf-snmp:snmp": {
"engine": {
"version": {
"v1": true,
"v2c": true,
"v3": true
},
"engine-id": "id"
},
"community": [
{
"index": 0,
"text-name": "mail@contact",
"context": "Contact: NOM Location: NOM" // Format Contact: NOM Location: NOM
}
],
"usm": {
"local": {
"user": [
{
"name": "NOM UTILISATEUR",
"auth": {
"md5": {
"key": "" //REDACTED si authentication mode
}
},
"priv": {
"aes": {
"key": "" //REDACTED si privacy mode
}
}
}
]
}
},
"vacm": {
"group": [
{
"name": "NOM GROUPE",
"access": [
{
"security-model": "", //V1, v2, v3
"notify-view": "",
"source-context": "", //id acl
"read-view": "All",
"write-view": "All",
"notify-view": "All"
}
]
}
],
"view": [ //mib view
{
"name": "All",
"include": [
"iso"
],
"exclude": []
}
]
},
"target": [ // target host
{
"name": "NOM TARGET",
"udp": {
"ip": "ip"
},
"target-params": "NOM PARAM"
}
],
"target-params": [ // target param
{
"name": "NOM PARAM",
"usm": {
"user-name": "NOM TARGET",
"security-level": "auth-priv"
}
}
]
}
},
"openconfig-interfaces:interfaces": {
"interface": [
{
"name": "NOM INTERFACE",
"config": {
"name": "NOM INTERFACE",
"type": "" // iana-if-type:ieee8023adLag si Bridge-Aggregation sinon null
},
"state": {
"name": "NOM INTERFACE",
"admin-status": "", //UP ou DOWN
"oper-status": "", // UP ou DOWN ou null
"description": "", // Format "Jumbo: True/False;Description: ...;Media: ...;Hardware: type de lien;Raw: config de l'interface dans current-configuration;Counters Cleared: date;
"mtu": null,
"counters": {
"in-octets": null,
"in-pkts": null,
"in-unicast-pkts": null,
"in-broadcast-pkts": null,
"in-multicast-pkts": null,
"in-pauses-pkts": null,
"in-drops": null,
"in-errors": null,
"out-octets": null,
"out-pkts": null,
"out-unicast-pkts": null,
"out-broadcast-pkts": null,
"out-multicast-pkts": null,
"out-pauses-pkts": null,
"out-drops": null,
"out-errors": [
{
"type": "output errors",
"count": 0
},
{
"type": "underruns",
"count": 0
},
{
"type": "buffer failures",
"count": 0
},
{
"type": "aborts",
"count": 0
},
{
"type": "deferred",
"count": 0
},
{
"type": "collisions",
"count": 0
},
{
"type": "late collisions",
"count": 0
},
{
"type": "lost carrier",
"count": 0
},
{
"type": "no carrier",
"count": 0
}
]
},
"openconfig-if-aggregate-ext:load-sharing-type": "Shar"
},
"ethernet": {
"name": "Bridge-Aggregation1",
"state": {
"enable-flow-control": null,
"duplex-mode": "unknown-duplex",
"port-speed": null
},
"switched-vlan": {
"state": {
"interface-mode": "", //ACCESS ou TRUNK
"native-vlan": 1, // PVID
"access-vlan": 1, // si ACCESS: PVID
"trunk-vlans": [ // si TRUNK
"vlan_passing",
1,
"vlan_permitted",
1
]
}
}
},
"subinterfaces": {
"subinterface": [
{
"index": 0, //toujours 0
"config": {
"index": 0 //toujours 0
},
"state": {
"index": 0 //toujours 0
},
"oc-ip:ipv4": {
"oc-ip:neighbors": { // table arp
"oc-ip:neighbor": [
{
"ip": "IP",
"config": {
"ip": "IP",
"link-layer-address": "MAC"
},
"state": {
"ip": "IP",
"link-layer-address": "MAC",
"origin": "DYNAMIC",
"openconfig-if-ip-ext:aging": "",
"openconfig-if-ip-ext:vlan": ""
}
}
]
},
"addresses": { // Internet address
"address": [
{
"ip": "IP",
"state": {
"ip": "IP",
"prefix-length": 255 // Masque
}
}
]
}
}
}
]
},
"openconfig-if-aggregate:aggregation": {
"state": {
"lag-type": "Static", //Static ou Dynamic
"member": [
"Local",
"texte",
"Remote",
"texte"
]
}
}
}
]
},
"openconfig-network-instance:network-instances": {
"network-instance": [
{
"name": "default",
"fdb": {
"mac-table": { // table mac
"entries": {
"entry": [
{
"mac-address": "MAC",
"vlan": "1",
"config": {
"mac-address": "MAC",
"vlan": "1"
},
"state": {
"mac-address": "MAC",
"vlan": "1",
"age": "Y", //aging
"entry-type": "Learned" // State
},
"interface": {
"interface-ref": {
"config": {
"interface": "NOM INTERFACE"
}
}
}
}
]
}
}
},
"protocols": { //table de routage
"protocol": [
{
"identifier": "", // oc-pol-types:RIP, oc-pol-types:DIRECT, oc-pol-types:STATIC, oc-pol-types:IPV4
"name": "", //RIP, DIRECT, STATIC, IPV4
"static-routes": {
"static": [
{
"prefix": "CIDR",
"config": {
"prefix": "CIDR"
},
"next-hops": {
"next-hop": [
{
"index": 0,
"config": {
"next-hop": "IP",
"metric": 0,
"preference": 0
},
"interface-ref": {
"config": {
"interface": "INTERFACE"
}
}
}
]
}
}
]
}
}
]
},
"tables": { //table FIB
"table": [
{
"protocol": "oc-pol-types:IPV4",
"address-family": "oc-types:IPV4",
"ipv4": {
"routes": {
"route": [
{
"prefix": "CIDR",
"state": {
"prefix": "CIDR",
"active": true,
"_custom_flags": "" //FLAG
},
"next-hops": {
"next-hop": [
{
"index": 0,
"state": {
"next-hop": "IP",
"pushed-mpls-label-stack": []
},
"interface-ref": {
"state": {
"interface": "INTERFACE"
}
}
}
]
}
}
]
}
}
}
]
}
}
]
},
"openconfig-vlan:vlans": {
"vlan": [
{
"vlan-id": 1,
"config": {
"vlan-id": 1,
"name": "" //NAME
},
"state": {
"name": "" //DESCRIPTION
}
}
]
},
"openconfig-acl:acl": {
"acl-sets": {
"acl-set": [
{
"name": "1", //numéro ACL
"type": "", //basic ou advanced
"config": {
"name": "1", //numéro ACL
"type": "", //basic ou advanced
"description": ""
},
"acl-entries": {
"acl-entry": [
{
"sequence-id": 1,
"config": {
"sequence-id": 1,
"forwarding-action": "" //ACCEPT ou DROP
},
"ipv4": {
"config": {
"protocol": "", //IP_TCP, UP_UDP, IP_PIM
"source-address": "IP",
"source-address-prefix-set": "MASQUE",
"destination-address": "IP",
"destination-address-prefix-set": "MASQUE"
}
}
}
]
}
}
]
}
},
"openconfig-platform:components": {
"component": [
{
"name": "CHASSIS",
"config": {
"name": "CHASSIS"
},
"state": {
"name": "CHASSIS",
"type": "oc-platform-types:CHASSIS",
"model-name": ""
}
},
{
"name": "OS",
"config": {
"name": "OS"
},
"state": {
"name": "OS",
"type": "oc-platform-types:OPERATING_SYSTEM",
"description": "", //Format "Boot-image: ..."
"software-version": "Version 1 Release 1"
}
},
{
"name": "Switch 1",
"config": {
"name": "Switch 1"
},
"state": {
"name": "Switch 1",
"type": "oc-platform-types:LINECARD",
"id": 1,
"description": "", //Format "Patch version: ..."
"hardware-version": "", // release version
"software-version": "", //Format "CURRENT: ... | MAIN: ... | BACKUP: ..."
"model-name": "", //board type
"last-reboot-reason": "",
"redundant-role": "", //Standby ou Master
"memory": {
"available": 1,
"utilized": 1
}
},
"properties": {
"property": [
{
"name": "irf-priority",
"state": {
"name": "irf-priority",
"value": "1" //priority
}
},
{
"name": "irf-link-1",
"state": {
"name": "irf-link-1",
"value": "Neighbor: 2 | State: UP"
}
},
{
"name": "irf-link-2",
"state": {
"name": "irf-link-2",
"value": "Neighbor: 3 | State: UP"
}
},
{
"name": "irf-config-port1",
"state": {
"name": "irf-config-port1",
"value": "Ten-GigabitEthernet1/0/1, Ten-GigabitEthernet1/0/2"
}
},
{
"name": "irf-config-port2",
"state": {
"name": "irf-config-port2",
"value": "Ten-GigabitEthernet1/0/3, Ten-GigabitEthernet1/0/4"
}
}
]
}
},
{
"name": "CPU 1",
"config": {
"name": "CPU 1"
},
"state": {
"name": "CPU 1",
"type": "oc-platform-types:LINECARD",
"description": "", //DEVICE NAME
"mfg-name": "", // VENDOR NAME
"mfg-date": "", // MANUFACTURING DATE
"serial-no": "", //SN
"part-no": "", //PRODUCT NUMBER
"base-mac-address": "MAC"
}
},
{
"name": "FAN 1",
"config": {
"name": "FAN 1"
},
"state": {
"name": "FAN 1",
"type": "oc-platform-types:FAN",
"description": "", //DEVICE NAME
"mfg-name": "", // VENDOR NAME
"mfg-date": "", // MANUFACTURING DATE
"serial-no": "", //SN
"parent": "CPU 1",
"oper-status": "" //STATE
},
"openconfig-platform-fan:fan": {
"state": {
"oc-fan:airflow-direction": "",
"oc-fan:prefer-airflow-direction": ""
}
}
},
{
"name": "POWER 1",
"config": {
"name": "POWER 1"
},
"state": {
"name": "POWER 1",
"type": "oc-platform-types:POWER_SUPPLY",
"description": "", //DEVICE NAME
"mfg-name": "", // VENDOR NAME
"mfg-date": "", // MANUFACTURING DATE
"serial-no": "", //SN
"parent": "CPU 1",
"oper-status": "" //STATE
},
"openconfig-platform-psu:power-supply": {
"state": {
"oc-platform-psu:mode": ""
}
}
},
{
"name": "hotspot 1",
"config": {
"name": "hotspot 1"
},
"state": {
"name": "hotspot 1",
"type": "oc-platform-types:SENSOR",
"parent": 1, //SLOT
"temperature": {
"instant": "1"
}
}
},
{ //transceiver diagnostic et interface
"name": "INTERFACE NAME",
"config": {
"name": "INTERFACE NAME"
},
"state": {
"name": "INTERFACE NAME",
"type": "oc-platform-types:TRANSCEIVER",
"present": "", //PRESENT ou null
"form-factor": "", //TRANSCEIVER TYPE
"connector-type": "",
"vendor": "",
"part-no": "", //PRODUCT NUMBER/ORDERING NAME
"temperature": {
"instant": 1
}
},
"properties": {
"property": [
{
"name": "wavelength",
"state": {
"name": "wavelength",
"value": "1"
}
}
]
},
"oc-transceiver:transceiver": {
"state": {
"supply-voltage": {
"instant": 1 //VOLTAGE
},
"output-power": {
"instant": 1 //TX
},
"input-power": {
"instant": 1 //RX
},
"laser-bias-current": {
"instant": 1 //BIAS
}
}
}
}
]
},
"openconfig-spanning-tree:stp": {
"global": {
"state": {
"enabled-protocol": [
"oc-stp-types:RSTP"
],
"bpdu-guard": false
}
},
"interfaces": {
"interface": [
{
"name": "INTERFACE NAME",
"state": {
"hello-time": "",
"name": "INTERFACE NAME",
"edge-port": "",
"bpdu-mst": "",
"rapid-transition": "", //True ou False
"num-vlans": 1
}
}
]
},
"rstp": {
"state": {
"hello-time": "",
"bridge-priority": "0",
"bridge-address": "MAC",
"designated-root-address": "MAC",
"root-port": "0",
"topology-changes": 1,
"last-topology-change": "DATE"
},
"interfaces": {
"interface": [
{
"name": "INTERFACE NAME",
"state": {
"name": "INTERFACE NAME",
"port-num": 1,
"protocol": "", //Enabled ou Disabled
"role": "",
"port-state": "", //UP ou DOWN
"counters": {
"state": {
"bpdu-sent": 1,
"bpdu-received": 1
}
}
}
}
]
}
}
}
}
```

View File

@@ -4,10 +4,10 @@
Cet outil permet de **récupérer les données des logs de différents types de switches** (HPE uniquement actuellement) et de **convertir ces informations en un format JSON normalisé basé sur des modèles OpenConfig en YANG**.
Il fournit également la possibilité de générer une **rapport des liens inter-switches format Excel** pour visualiser les liens entre les switches existants.
Il fournit également la possibilité de générer une **rapport des interfaces format Excel** pour visualiser la liste des counters pour chaque interface.
Il fournit également la possibilité de générer une **rapport des stack format Excel** pour visualiser les stack de chaque switch.
Il founit également la possibilité de générer une **schéma de l'infrastructure** pour visualiser les liens entres les switches dans l'infrastructure.
- Il fournit également la possibilité de générer un **rapport des liens inter-switches format Excel** pour visualiser les liens entre les switches existants.
- Il fournit également la possibilité de générer un **rapport des interfaces format Excel** pour visualiser la liste des counters pour chaque interface.
- Il fournit également la possibilité de générer un **rapport des stack format Excel** pour visualiser les stack de chaque switch.
- Il founit également la possibilité de générer un **schéma de l'infrastructure** pour visualiser les liens entres les switches dans l'infrastructure.
## Fonctionnalités principales

View File

@@ -0,0 +1,127 @@
import sys
import os
import time
import scripts.json_hpe as json_hpe
from pathlib import Path
from scripts.export_schema_infra import main as schema_infra
from scripts.export_rapport_uplink import main as rapport_uplink
from scripts.export_rapport_stack import main as rapport_stack
from scripts.export_rapport_interfaces import main as rapport_interfaces
sys.path.append(os.path.dirname(__file__))
def verify_if_file_exists(name):
base, ext = os.path.splitext(name)
counter = 1
new_name = name
while os.path.exists(new_name):
new_name = f"{base}_{counter}{ext}"
counter += 1
return new_name
def main():
"""Fonction principale du programme d'analyse de switches"""
if len(sys.argv) < 3:
print("Usage: python3 src/main.py <switch_type>[hpe|...] <input_file> [-o <output_file>] [-u] [-d] [-s] [-i]")
print("Options:")
print(" <switch_type> Type of switch to process (hpe)")
print(" -o <output_file> Specify output JSON file name (optional)")
print(" -d Generate infrastructure schema (optional)")
print(" -u Generate uplink report (optional)")
print(" -s Generate stack report (optional)")
print(" -i Generate interface report (optional)")
sys.exit(1)
switch_type = sys.argv[1].lower()
input_data = sys.argv[2]
input_path = "src/input/"
output_path = "src/output/"
os.makedirs(output_path, exist_ok=True)
if "-o" in sys.argv:
o_index = sys.argv.index("-o")
if o_index + 1 < len(sys.argv):
output_file1_json = f"{output_path}{switch_type}_saved_{sys.argv[o_index + 1]}.json"
output_file2_json = f"{output_path}{switch_type}_current_{sys.argv[o_index + 1]}.json"
else:
print("Erreur: nom de fichier de sortie manquant après '-o'.")
sys.exit(1)
else:
timestamp = time.strftime("%Y%m%d")
output_file1_json = f"{output_path}{switch_type}_current_{timestamp}.json"
output_file2_json = f"{output_path}{switch_type}_saved_{timestamp}.json"
output_file1_json = verify_if_file_exists(output_file1_json)
output_file2_json = verify_if_file_exists(output_file2_json)
if switch_type == "hpe":
json_hpe.generate_json_hpe(input_data, output_file1_json, output_file2_json)
else:
print("Erreur: type de switch inconnu. Utilisez 'hpe'.")
sys.exit(1)
if "-d" in sys.argv:
print(f"\nGénération du schéma d'infrastructure...")
if "-o" in sys.argv:
o_index = sys.argv.index("-o")
if o_index + 1 < len(sys.argv):
output_file_html = os.path.join(f"{output_path}schema_infra_{switch_type}_{sys.argv[o_index + 1]}.html")
else:
print("Erreur: nom de fichier de sortie manquant après '-o'.")
sys.exit(1)
else:
timestamp = time.strftime("%Y%m%d")
output_file_html = f"{output_path}schema_infra_{switch_type}_{timestamp}.html"
output_file_html = verify_if_file_exists(output_file_html)
html_file = schema_infra(output_path, output_file_html)
print(f"✓ Processus terminé. Fichiers générés:\n - JSON: {output_file1_json} & {output_file2_json}\n - HTML: {html_file}")
if "-u" in sys.argv:
print(f"\nGénération du rapport d'uplink...")
if "-o" in sys.argv:
o_index = sys.argv.index("-o")
if o_index + 1 < len(sys.argv):
output_file_excel = os.path.join(f"{output_path}rapport_uplink_{switch_type}_{sys.argv[o_index + 1]}.xlsx")
else:
print("Erreur: nom de fichier de sortie manquant après '-o'.")
sys.exit(1)
else:
timestamp = time.strftime("%Y%m%d")
output_file_excel = f"{output_path}rapport_uplink_{switch_type}_{timestamp}.xlsx"
output_file_excel = verify_if_file_exists(output_file_excel)
excel_file = rapport_uplink(output_path, output_file_excel)
print(f"✓ Processus terminé. Fichiers générés:\n - JSON: {output_file1_json} & {output_file2_json}\n - Excel: {excel_file}")
if "-s" in sys.argv:
print(f"\nGénération du rapport de stack...")
if "-o" in sys.argv:
o_index = sys.argv.index("-o")
if o_index + 1 < len(sys.argv):
output_file_excel = os.path.join(f"{output_path}rapport_stack_{switch_type}_{sys.argv[o_index + 1]}.xlsx")
else:
print("Erreur: nom de fichier de sortie manquant après '-o'.")
sys.exit(1)
else:
timestamp = time.strftime("%Y%m%d")
output_file_excel = f"{output_path}rapport_stack_{switch_type}_{timestamp}.xlsx"
output_file_excel = verify_if_file_exists(output_file_excel)
excel_file = rapport_stack(output_path, output_file_excel)
print(f"✓ Processus terminé. Fichiers générés:\n - JSON: {output_file1_json} & {output_file2_json}\n - Excel: {excel_file}")
if "-i" in sys.argv:
print(f"\nGénération du rapport d'interfaces...")
if "-o" in sys.argv:
o_index = sys.argv.index("-o")
if o_index + 1 < len(sys.argv):
output_file_excel = os.path.join(f"{output_path}rapport_interfaces_{switch_type}_{sys.argv[o_index + 1]}.xlsx")
else:
print("Erreur: nom de fichier de sortie manquant après '-o'.")
sys.exit(1)
else:
timestamp = time.strftime("%Y%m%d")
output_file_excel = f"{output_path}rapport_interfaces_{switch_type}_{timestamp}.xlsx"
output_file_excel = verify_if_file_exists(output_file_excel)
excel_file = rapport_interfaces(output_path, output_file_excel)
print(f"✓ Processus terminé. Fichiers générés:\n - JSON: {output_file1_json} & {output_file2_json}\n - Excel: {excel_file}")
if __name__ == "__main__":
main()

View File

@@ -181,7 +181,7 @@ class ParserMixin:
"software-version": f"Version {self.config['version'].version if self.config['version'].version else None} Release {self.config['version'].release if self.config['version'].release else None}"
})
# Conversion current configuration/saved configuration TODO
# Conversion current configuration/saved configuration
# Users
if self.config[config_type].local_users:
oc_users = []

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env python3
"""
Parser pour configuration switch HPE vers un format json normalisé OpenConfig YANG
Extrait les différentes sections de la configuration HPE et les convertit en objets Python, puis exporte le tout au format JSON OpenConfig.
Extrait les différentes sections de logs et les convertit en objets Python, puis exporte le tout au format JSON OpenConfig.
"""
import json
@@ -14,7 +14,7 @@ class HpeParser(ParserMixin):
"""Parser pour fichier XML HPE"""
def __init__(self, file_path: str):
"""Initialise le parser avec le chemin du fichier de configuration HPE"""
"""Initialise le parser avec le chemin du fichier de logs HPE"""
self.file = file_path
self.root = None
self.raw_data = None
@@ -1505,33 +1505,4 @@ def generate_json_hpe(input_file: str, output_file1: str, output_file2: str):
except Exception as e:
print(f"✗ Erreur: {e}")
return
# if __name__ == "__main__":
# import sys
# if len(sys.argv) != 2:
# print("Usage: python json_hpe.py <fichier_config>")
# print("Exemple: python json_hpe.py config_hpe")
# sys.exit(1)
# file = sys.argv[1]
# if not Path(file).exists():
# print(f"✗ Erreur: Le fichier '{file}' n'existe pas")
# sys.exit(1)
# try:
# parser = HpeParser(file)
# parser.parse_all()
# parser.print_summary()
# input_path = Path(file)
# output_file = 'output_Hpe.json'
# parser.export_to_json(output_file)
# print(f"\n✓ Conversion terminée! Vérifiez le fichier: {output_file}")
# except Exception as e:
# print(f"✗ Erreur: {e}")
# sys.exit(1)
return