WIP suche fehler in session/login
This commit is contained in:
@@ -9,6 +9,7 @@ import asyncio
|
||||
import aiohttp
|
||||
import urllib3
|
||||
import yaml
|
||||
import json
|
||||
from prometheus_client import (
|
||||
Gauge,
|
||||
start_http_server,
|
||||
@@ -215,6 +216,25 @@ async def fetch_with_retry(session, host: HostConfig, url: str) -> dict | None:
|
||||
return None
|
||||
|
||||
|
||||
async def discover_redfish_resources(session, host: HostConfig) -> dict:
|
||||
"""Discover available Redfish resources and return relevant URLs"""
|
||||
root_url = f"https://{host.fqdn}/redfish/v1/"
|
||||
data = await fetch_with_retry(session, host, root_url)
|
||||
if not data:
|
||||
return {}
|
||||
|
||||
# Extrahiere Links aus der Root-Antwort
|
||||
links = {
|
||||
"Chassis": data.get("Chassis", {}).get("@odata.id"),
|
||||
"Systems": data.get("Systems", {}).get("@odata.id"),
|
||||
"SessionService": data.get("SessionService", {}).get("@odata.id"),
|
||||
}
|
||||
if not links["Chassis"]:
|
||||
logging.error("No valid Chassis URL found for host %s", host.fqdn)
|
||||
return {}
|
||||
return links
|
||||
|
||||
|
||||
def get_power_resource_info(
|
||||
member_data: dict, host_fqdn: str
|
||||
) -> tuple[str | None, str | None]:
|
||||
@@ -338,8 +358,15 @@ async def get_power_data(session, host: HostConfig):
|
||||
start = time.monotonic()
|
||||
# Root ressource abfragen
|
||||
resources = await discover_redfish_resources(session, host)
|
||||
if not resources or "Chassis" not in resources:
|
||||
logging.error("Could not discover Chassis resource for %s", host.fqdn)
|
||||
if not resources:
|
||||
logging.error("Could not discover any resources for %s", host.fqdn)
|
||||
host.mark_failure()
|
||||
up_gauge.labels(host=host.fqdn).set(0)
|
||||
return
|
||||
|
||||
chassis_url = resources.get("Chassis")
|
||||
if not chassis_url:
|
||||
logging.error("No valid Chassis URL found for %s", host.fqdn)
|
||||
host.mark_failure()
|
||||
up_gauge.labels(host=host.fqdn).set(0)
|
||||
return
|
||||
@@ -349,7 +376,7 @@ async def get_power_data(session, host: HostConfig):
|
||||
up_gauge.labels(host=host.fqdn).set(1)
|
||||
|
||||
# Get chassis ressource
|
||||
chassis_url = f"https://{host.fqdn}{resources['Chassis']}"
|
||||
chassis_url = f"https://{host.fqdn}{chassis_url}"
|
||||
chassis_data = await fetch_with_retry(session, host, chassis_url)
|
||||
if not chassis_data:
|
||||
host.mark_failure()
|
||||
@@ -362,6 +389,9 @@ async def get_power_data(session, host: HostConfig):
|
||||
if not chassis_member_url:
|
||||
continue
|
||||
|
||||
# Debug-Ausgabe für Chassis-Member-URL
|
||||
print(f"Chassis Member URL: {chassis_member_url}")
|
||||
|
||||
# Get chassis id from url ("/redfish/v1/Chassis/1" -> 1)
|
||||
chassis_member_id = chassis_member_url.split("/")[-1]
|
||||
# Check if the chassis id is in config (had problem with chassis "NVMe")
|
||||
@@ -371,9 +401,13 @@ async def get_power_data(session, host: HostConfig):
|
||||
|
||||
member_url = f"https://{host.fqdn}{chassis_member_url}"
|
||||
member_data = await fetch_with_retry(session, host, member_url)
|
||||
# Debug-Ausgabe für Chassis-Member-Daten
|
||||
print(f"Chassis Member Data: {json.dumps(member_data, indent=4)}")
|
||||
if not member_data:
|
||||
continue
|
||||
|
||||
|
||||
|
||||
# Get Power ressource (fallback to "Power")
|
||||
power_resource_url, power_resource_type = get_power_resource_info(
|
||||
member_data, host.fqdn
|
||||
@@ -555,22 +589,6 @@ async def run_exporter(config, stop_event):
|
||||
logging.info("Exporter stopped cleanly.")
|
||||
|
||||
|
||||
async def discover_redfish_resources(session, host: HostConfig) -> dict:
|
||||
"""Discover available Redfish resources and return relevant URLs"""
|
||||
root_url = f"https://{host.fqdn}/redfish/v1/"
|
||||
data = await fetch_with_retry(session, host, root_url)
|
||||
if not data:
|
||||
return {}
|
||||
|
||||
# Extrahiere Links aus der Root-Antwort
|
||||
links = {
|
||||
"Chassis": data.get("Chassis", {}).get("@odata.id"),
|
||||
"Systems": data.get("Systems", {}).get("@odata.id"),
|
||||
"SessionService": data.get("SessionService", {}).get("@odata.id"),
|
||||
}
|
||||
return links
|
||||
|
||||
|
||||
async def main():
|
||||
"""Modern asyncio entry point"""
|
||||
parser = argparse.ArgumentParser(description="Redfish Prometheus Exporter")
|
||||
|
||||
Reference in New Issue
Block a user