add correct logout and watt data

This commit is contained in:
2025-11-13 14:18:16 +01:00
parent 2752103a3d
commit 483b914e1a

View File

@@ -28,6 +28,7 @@ class HostConfig:
# New attributes for Redfish stuff # New attributes for Redfish stuff
vendor: str | None = None vendor: str | None = None
session_token: str | None = None session_token: str | None = None
session_logout: str | None = None # SessionLocation like /redfish/v1/SessionService/Sessions/marco.lucarelli%40abacus.ch00000000xxx/
def should_skip(self) -> bool: def should_skip(self) -> bool:
"""Check if host is still in cool-down window""" """Check if host is still in cool-down window"""
@@ -120,9 +121,12 @@ async def fetch_with_retry(session, host: HostConfig, url: str) -> dict | None:
payload = {"UserName": host.username, "Password": host.password} payload = {"UserName": host.username, "Password": host.password}
async with session.post(login_url, json=payload, ssl=False, timeout=10) as login_resp: async with session.post(login_url, json=payload, ssl=False, timeout=10) as login_resp:
if login_resp.status == 201: if login_resp.status == 201:
host.session_token = login_resp.headers.get("X-Auth-Token") host.session_token = login_resp.headers.get("X-Auth-Token") # as response in header
if not host.session_token: if not host.session_token:
raise RuntimeError("No X-Auth-Token in login response") raise RuntimeError("No X-Auth-Token in login response")
host.session_logout = login_resp.headers.get("Location") # as response in header
if not host.session_logout:
raise RuntimeError("No Location in login response")
headers["X-Auth-Token"] = host.session_token headers["X-Auth-Token"] = host.session_token
logging.info("New session token obtained for %s", host.fqdn) logging.info("New session token obtained for %s", host.fqdn)
else: else:
@@ -198,6 +202,11 @@ async def get_power_data(session, host: HostConfig):
for psu in data.get("PowerSupplies", []): for psu in data.get("PowerSupplies", []):
line_input_v = psu.get("LineInputVoltage") 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") watts_input = psu.get("PowerInputWatts")
serial = psu.get("SerialNumber") serial = psu.get("SerialNumber")
@@ -220,9 +229,10 @@ async def logout_host(session, host):
"""Clean logout for Redfish with session tokens""" """Clean logout for Redfish with session tokens"""
if not host.session_token: if not host.session_token:
return return
if not host.session_logout:
return
try: try:
logout_url = f"https://{host.fqdn}/redfish/v1/SessionService/Sessions" logout_url = f"{host.session_logout}" # the full URL is here!
async with session.delete( async with session.delete(
logout_url, logout_url,
headers={"X-Auth-Token": host.session_token}, headers={"X-Auth-Token": host.session_token},