I first created a CSV file :
agent_name,ip,group,modules
CAMERA_Q1,192.168.10.11,Station_Q1,ping,tcp80
CAMERA_Q2,192.168.10.12,Station_Q1,ping,tcp80
, then wrote a Python script to convert the CSV data into XML format:
import csv
data_in_path = "/var/spool/pandora/data_in/"
def generate_xml(agent_name, ip, group, modules):
module_entries = ""
for module in modules.split(','):
if module == "ping":
module_type = "icmp_proc"
elif module.startswith("tcp"):
module_type = "tcp_proc"
else:
module_type = "generic_data"
**module_entries += f"""
{module}_{agent_name}</name>
{module_type}
{ip}
\n"""
xml_content = f"""
<agent_data>
<agent_name>{agent_name}</agent_name>
{group}
{ip}
{module\_entries}"
""
return xml\_content**
with open("equipements_station.csv", newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
xml_data = generate_xml(row["agent_name"], row["ip"], row["group"], row["modules"])
with open(f"{data_in_path}{row['agent_name']}.xml", "w") as f:
f.write(xml_data)
print("[INFO] Tous les fichiers XML ont été générés et placés dans data_in.")