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)
return
# start time measurement
start = time.monotonic()
# Root ressource abfragen
resources = await discover_redfish_resources(session, host)
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)
return
# Mark host as up
host.mark_success()
up_gauge.labels(host=host.fqdn).set(1)
# Chassis-Ressource abfragen
chassis_url = f"https://{host.fqdn}{resources['Chassis']}"
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
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:
logging.warning("No PowerSubsystem data found for %s", host.fqdn)
continue
# 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:
logging.warning("No PowerSupplies found for %s", host.fqdn)
@@ -280,7 +290,9 @@ async def get_power_data(session, host: HostConfig):
# Get Metrics URL
metrics_url = psu_data.get("Metrics", {}).get("@odata.id")
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
metrics_url = f"https://{host.fqdn}{metrics_url}"
@@ -291,51 +303,24 @@ async def get_power_data(session, host: HostConfig):
print(pretty)
exit(100)
# Ab hier neue Magie
# for psu in power_data.get("PowerSupplies", []):
# ... (deine bestehende Logik für die Metriken)
url = f"https://{host.fqdn}/redfish/v1/Chassis/1/Power"
start = time.monotonic()
data = await fetch_with_retry(session, host, url)
if not data:
host.mark_failure()
up_gauge.labels(host=host.fqdn).set(0)
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)
# Get Metrics from data
line_input_v = metrics_data.get("LineInputVoltage")
watts_input = metrics_data.get("PowerInputWatts")
serial = psu_data.get("SerialNumber")
# 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:
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)