ruff format

This commit is contained in:
2026-01-29 14:17:35 +01:00
parent 5b6a5e05bf
commit 7dd8313457

View File

@@ -213,6 +213,8 @@ async def get_power_data(session, host: HostConfig):
up_gauge.labels(host=host.fqdn).set(0) up_gauge.labels(host=host.fqdn).set(0)
return return
# start time measurement
start = time.monotonic()
# Root ressource abfragen # Root ressource abfragen
resources = await discover_redfish_resources(session, host) resources = await discover_redfish_resources(session, host)
if not resources or "Chassis" not in resources: if not resources or "Chassis" not in resources:
@@ -221,6 +223,10 @@ async def get_power_data(session, host: HostConfig):
up_gauge.labels(host=host.fqdn).set(0) up_gauge.labels(host=host.fqdn).set(0)
return return
# Mark host as up
host.mark_success()
up_gauge.labels(host=host.fqdn).set(1)
# Chassis-Ressource abfragen # Chassis-Ressource abfragen
chassis_url = f"https://{host.fqdn}{resources['Chassis']}" chassis_url = f"https://{host.fqdn}{resources['Chassis']}"
chassis_data = await fetch_with_retry(session, host, chassis_url) chassis_data = await fetch_with_retry(session, host, chassis_url)
@@ -248,13 +254,17 @@ async def get_power_data(session, host: HostConfig):
# PowerSubsystem collection abfragen # PowerSubsystem collection abfragen
power_subsystem_url = f"https://{host.fqdn}{power_subsystem_url}" power_subsystem_url = f"https://{host.fqdn}{power_subsystem_url}"
power_subsystem_data = await fetch_with_retry(session, host, power_subsystem_url) power_subsystem_data = await fetch_with_retry(
session, host, power_subsystem_url
)
if not power_subsystem_data: if not power_subsystem_data:
logging.warning("No PowerSubsystem data found for %s", host.fqdn) logging.warning("No PowerSubsystem data found for %s", host.fqdn)
continue continue
# PowerSupplies auflisten # PowerSupplies auflisten
power_supplies_url = power_subsystem_data.get("PowerSupplies", {}).get("@odata.id") power_supplies_url = power_subsystem_data.get("PowerSupplies", {}).get(
"@odata.id"
)
if not power_supplies_url: if not power_supplies_url:
logging.warning("No PowerSupplies found for %s", host.fqdn) logging.warning("No PowerSupplies found for %s", host.fqdn)
@@ -280,7 +290,9 @@ async def get_power_data(session, host: HostConfig):
# Get Metrics URL # Get Metrics URL
metrics_url = psu_data.get("Metrics", {}).get("@odata.id") metrics_url = psu_data.get("Metrics", {}).get("@odata.id")
if not metrics_url: if not metrics_url:
logging.warning("No Metrics found for PowerSupply %s", psu_data.get("Id")) logging.warning(
"No Metrics found for PowerSupply %s", psu_data.get("Id")
)
continue continue
metrics_url = f"https://{host.fqdn}{metrics_url}" metrics_url = f"https://{host.fqdn}{metrics_url}"
@@ -291,51 +303,24 @@ async def get_power_data(session, host: HostConfig):
print(pretty) print(pretty)
exit(100) exit(100)
# Get Metrics from data
line_input_v = metrics_data.get("LineInputVoltage")
# Ab hier neue Magie watts_input = metrics_data.get("PowerInputWatts")
# for psu in power_data.get("PowerSupplies", []): serial = psu_data.get("SerialNumber")
# ... (deine bestehende Logik für die Metriken) # Calculate Amps
amps = (
round(watts_input / line_input_v, 2)
if line_input_v and watts_input
else None
)
if line_input_v is not None:
url = f"https://{host.fqdn}/redfish/v1/Chassis/1/Power" voltage_gauge.labels(host=host.fqdn, psu_serial=serial).set(
start = time.monotonic() line_input_v
)
data = await fetch_with_retry(session, host, url) if watts_input is not None:
if not data: watts_gauge.labels(host=host.fqdn, psu_serial=serial).set(watts_input)
host.mark_failure() if amps is not None:
up_gauge.labels(host=host.fqdn).set(0) amps_gauge.labels(host=host.fqdn, psu_serial=serial).set(amps)
return
host.mark_success()
up_gauge.labels(host=host.fqdn).set(1)
for psu in data.get("PowerSupplies", []):
line_input_v = psu.get("LineInputVoltage")
# HPE Redfish uses LastPowerOutputWatts for Watts
if host.vendor.strip().upper().startswith("HPE"):
watts_input = psu.get("LastPowerOutputWatts")
else:
# Supermicro uses PowerInputWatts
watts_input = psu.get("PowerInputWatts")
serial = psu.get("SerialNumber")
amps = (
round(watts_input / line_input_v, 2)
if line_input_v and watts_input
else None
)
if line_input_v is not None:
voltage_gauge.labels(host=host.fqdn, psu_serial=serial).set(line_input_v)
if watts_input is not None:
watts_gauge.labels(host=host.fqdn, psu_serial=serial).set(watts_input)
if amps is not None:
amps_gauge.labels(host=host.fqdn, psu_serial=serial).set(amps)
REQUEST_LATENCY.labels(host=host.fqdn).observe(time.monotonic() - start) REQUEST_LATENCY.labels(host=host.fqdn).observe(time.monotonic() - start)