From 2f249beb8a17812edb8011c3e3b20337266ebe1b Mon Sep 17 00:00:00 2001 From: Marco Lucarelli Date: Thu, 29 Jan 2026 15:12:43 +0100 Subject: [PATCH] final... --- python/redfish-api/config.yaml.example | 2 ++ python/redfish-api/redfish_exporter_v9000.py | 26 +++++++++++--------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/python/redfish-api/config.yaml.example b/python/redfish-api/config.yaml.example index f323556..7a7547b 100644 --- a/python/redfish-api/config.yaml.example +++ b/python/redfish-api/config.yaml.example @@ -3,6 +3,7 @@ interval: 10 port: 8000 username: gloabl-user password: global-password +systemid: ["1"] # Strings, not integers! hosts: - fqdn: host1.example.com username: user1 @@ -11,4 +12,5 @@ hosts: username: user2 password: secret2 - fqdn: host3.example.com + systemid: ["0"] # Strings, not integers! - fqdn: host4.example.com diff --git a/python/redfish-api/redfish_exporter_v9000.py b/python/redfish-api/redfish_exporter_v9000.py index ecb3fe9..998affa 100644 --- a/python/redfish-api/redfish_exporter_v9000.py +++ b/python/redfish-api/redfish_exporter_v9000.py @@ -20,6 +20,7 @@ class HostConfig: fqdn: str username: str password: str + systemid: list[str] | None = None max_retries: int = 1 backoff: int = 2 cool_down: int = 120 # seconds to wait after too many failures @@ -234,8 +235,6 @@ async def get_power_data(session, host: HostConfig): host.mark_failure() up_gauge.labels(host=host.fqdn).set(0) return - pretty = json.dumps(chassis_data, indent=4, sort_keys=True) - print(pretty) # 3. Power-Daten aus den Chassis-Mitgliedern extrahieren for chassis_member in chassis_data.get("Members", []): @@ -243,6 +242,13 @@ async def get_power_data(session, host: HostConfig): if not chassis_member_url: continue + # Get Chassis ID from url ("/redfish/v1/Chassis/1" -> 1) + chassis_id = chassis_member_url.split("/")[-1] + # Check if the chassis id is in config (had problem with chassis "NVMe") + if hasattr(host, 'systemid') and host.systemid: + if chassis_id not in host.systemid: + continue + member_url = f"https://{host.fqdn}{chassis_member_url}" member_data = await fetch_with_retry(session, host, member_url) if not member_data: @@ -302,23 +308,19 @@ async def get_power_data(session, host: HostConfig): continue # Get Metrics from data - line_input_v = metrics_data.get("LineInputVoltage") - watts_input = metrics_data.get("PowerInputWatts") + line_input_v = metrics_data.get("InputVoltage", {}).get("Reading") + watts_input = metrics_data.get("InputPowerWatts", {}).get("Reading") + amps_input = metrics_data.get("InputCurrentAmps", {}).get("Reading") 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) + if amps_input is not None: + amps_gauge.labels(host=host.fqdn, psu_serial=serial).set(amps_input) REQUEST_LATENCY.labels(host=host.fqdn).observe(time.monotonic() - start) @@ -354,6 +356,7 @@ async def run_exporter(config, stop_event): port = config.get("port", 8000) default_username = config.get("username") default_password = config.get("password") + default_systemid = config.get("systemid") hosts = config["hosts"] interval = config.get("interval", 10) @@ -369,6 +372,7 @@ async def run_exporter(config, stop_event): fqdn=host_entry["fqdn"], username=host_entry.get("username", default_username), password=host_entry.get("password", default_password), + systemid=host_entry.get("systemid", default_systemid), ) else: hc = HostConfig(