diff --git a/python/redfish-api/redfish_exporter.py b/python/redfish-api/redfish_exporter.py index 538885c..2a550ca 100644 --- a/python/redfish-api/redfish_exporter.py +++ b/python/redfish-api/redfish_exporter.py @@ -28,6 +28,7 @@ class HostConfig: # New attributes for Redfish stuff vendor: 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: """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} async with session.post(login_url, json=payload, ssl=False, timeout=10) as login_resp: 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: 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 logging.info("New session token obtained for %s", host.fqdn) else: @@ -198,7 +202,12 @@ async def get_power_data(session, host: HostConfig): for psu in data.get("PowerSupplies", []): line_input_v = psu.get("LineInputVoltage") - watts_input = psu.get("PowerInputWatts") + # 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 = ( @@ -220,9 +229,10 @@ async def logout_host(session, host): """Clean logout for Redfish with session tokens""" if not host.session_token: return - + if not host.session_logout: + return 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( logout_url, headers={"X-Auth-Token": host.session_token},