44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
import subprocess
|
|
import os
|
|
import sys
|
|
sys.path.append('/opt/opengnsys/lib/engine/bin')
|
|
from NetLib import ogGetIpAddress
|
|
sys.path.append('/opt/opengnsys/lib/engine/bin')
|
|
from InventoryLib import ogListHardwareInfo
|
|
|
|
def get_server_log_dir():
|
|
# Obtener el directorio de logs del servidor
|
|
oglog = os.getenv("OGLOG")
|
|
if not oglog:
|
|
return ""
|
|
result = subprocess.run(["mount"], capture_output=True, text=True)
|
|
for line in result.stdout.splitlines():
|
|
parts = line.split()
|
|
if len(parts) >= 4 and parts[3] == oglog:
|
|
return parts[1]
|
|
return ""
|
|
|
|
def list_hardware_info():
|
|
oglog = os.getenv("OGLOG", "/tmp") # Usar /tmp como valor por defecto para OGLOG
|
|
ip_address = ogGetIpAddress()
|
|
# Fichero de listado de hardware basado en la IP obtenida
|
|
hardfile = f"hard-{ogGetIpAddress()}"
|
|
print(f"hardfile:{hardfile}")
|
|
# Ejecutar ogListHardwareInfo y redirigir al archivo de listado
|
|
hardware_info_path = os.path.join(oglog, hardfile)
|
|
with open(hardware_info_path, 'w') as output_file:
|
|
output_file.write(ogListHardwareInfo())
|
|
|
|
return hardware_info_path
|
|
|
|
if __name__ == "__main__":
|
|
# Obtener el directorio del servidor donde se exportan los ficheros de registro
|
|
server_log_dir = get_server_log_dir()
|
|
|
|
# Generar el archivo de listado de hardware y obtener su ruta
|
|
hardware_info_path = list_hardware_info()
|
|
|
|
# Imprimir la ruta del archivo generado
|
|
print(hardware_info_path)
|
|
|