v1.9.40: Grafana basic auth support (user/password + api_token)

- Add user/password fields to Grafana in server dialog FIELD_MAP
- GrafanaClient: support basic auth when no api_token is set
- ssh.py: _grafana_request supports basic auth fallback

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
chrome-storm-c442
2026-03-06 10:04:09 -05:00
parent df40af5632
commit d49fa9ce90
5 changed files with 24 additions and 15 deletions

View File

@@ -1511,16 +1511,19 @@ def _grafana_request(server: dict, endpoint: str) -> dict:
import requests
host = server["ip"]
port = server.get("port", 3000)
protocol = "https" if server.get("ssl", False) else "http"
protocol = "https" if server.get("use_ssl", server.get("ssl", False)) else "http"
base_url = server.get("base_url", f"{protocol}://{host}:{port}")
api_key = server.get("api_key", server.get("password", ""))
api_token = server.get("api_token", server.get("api_key", ""))
headers = {}
if api_key:
headers["Authorization"] = f"Bearer {api_key}"
auth = None
if api_token:
headers["Authorization"] = f"Bearer {api_token}"
elif server.get("user") and server.get("password"):
auth = (server["user"], server["password"])
url = f"{base_url.rstrip('/')}/api/{endpoint.lstrip('/')}"
resp = requests.get(url, headers=headers, timeout=15, verify=server.get("ssl_verify", True))
resp = requests.get(url, headers=headers, auth=auth, timeout=15, verify=server.get("ssl_verify", True))
resp.raise_for_status()
return resp.json()