OpsRadar
OROpsRadar Docs

API Reference

Complete HTTP API reference for the OpsRadar backend.

API Reference

Base URL: http://localhost:8080

All routes except GET /health require the X-API-Key header when OPS_RADAR_API_KEY is set. The one exception is the pod-exec WebSocket, which authenticates with a ?key= query parameter because a browser WebSocket handshake can't send custom headers.


Health

GET /health

Returns server status. No auth required.

Response

{ "status": "ok" }

Scans

POST /scan

Start an asynchronous scan across all (or filtered) kubeconfig contexts. Returns immediately with a scan_id โ€” use the SSE stream to follow progress.

Body

{
  "cluster_name": "my-cluster",
  "namespace": ""
}
  • cluster_name โ€” label stored with the scan record (cosmetic, defaults to "default-cluster")
  • namespace โ€” if non-empty, restricts scanning to this namespace only

Response 202 Accepted

{ "scan_id": "550e8400-e29b-41d4-a716-446655440000" }

GET /scan/:id/stream

Server-sent events (SSE) stream for a running scan.

Headers

Accept: text/event-stream

Event shape

{
  "task_id": "uuid",
  "message": "๐Ÿ” analysing prod/api-server (resource-audit)โ€ฆ",
  "finding": {
    "severity": "critical",
    "title": "Unpinned image tag โ€” nginx:latest",
    "detail": "...",
    "suggestion": "...",
    "diff_patch": "--- a/deploy/deployment.yaml\n+++ ..."
  },
  "done": false
}

done: true signals the stream is closed. finding is only present on finding events.


History

GET /history

Returns all scan records, newest first, with aggregated open-finding severity counts.

Response

{
  "scans": [
    {
      "id": "uuid",
      "cluster_name": "prod",
      "started_at": "2025-01-15T10:00:00Z",
      "finished_at": "2025-01-15T10:01:42Z",
      "status": "completed",
      "critical": 2,
      "high": 5,
      "medium": 3,
      "low": 1
    }
  ]
}

Recommendations

GET /recommendations?scan_id=<uuid>

All findings for a scan, sorted by severity (critical first).

Response

{
  "findings": [
    {
      "id": "uuid",
      "scan_target_id": "uuid",
      "kind": "resource-audit",
      "severity": "critical",
      "title": "Unpinned image tag โ€” nginx:latest",
      "detail": "The container web uses nginx:latest...",
      "suggestion": "Pin to a specific digest, e.g. nginx:1.27.0",
      "diff_patch": "--- a/deploy/deployment.yaml\n+++ ..."
    }
  ]
}

Radar

GET /radar

Aggregated open-finding counts per namespace from the latest completed scan only.

{
  "radar": [
    { "namespace": "prod",      "critical": 2, "high": 1, "medium": 3, "low": 0 },
    { "namespace": "staging",   "critical": 0, "high": 2, "medium": 1, "low": 4 },
    { "namespace": "kube-system","critical": 0, "high": 0, "medium": 0, "low": 0 }
  ]
}

Resolved findings (where resolved_at IS NOT NULL) are excluded.


Pull Requests

POST /pr/generate

Create a GitHub branch, commit the finding's diff patch, and open a PR.

Body

{ "finding_id": "uuid" }

Response

{ "pr_url": "https://github.com/myorg/myrepo/pull/42" }

Returns 400 if the finding has no diff_patch.


Findings

POST /findings/:id/resolve

Mark a finding as resolved. Sets resolved_at to now. The next GET /radar will exclude it.

Response

{ "resolved": true }

Docker

GET /docker

Lists all containers on the Docker host running the API (calls docker ps -a).

{
  "containers": [
    {
      "id": "abc123",
      "name": "opsradar-api",
      "image": "opsradar-api:latest",
      "status": "Up 2 hours",
      "created": "2025-01-15 08:00:00 +0000 UTC"
    }
  ]
}

Cluster operations

See Cluster Operations for the full walkthrough. Every endpoint takes an optional ?context= to select a kubeconfig context (omit for the default).

Discovery

Method & pathQueryReturns
GET /k8s/contextsโ€”Loaded kubeconfig contexts
GET /k8s/namespacescontextNamespaces in the context
GET /k8s/podscontext, namespaceRunning pods

Workload lists

GET /k8s/deployments ยท /k8s/daemonsets ยท /k8s/statefulsets ยท /k8s/replicasets ยท /k8s/jobs ยท /k8s/cronjobs โ€” each accepts ?context= and ?namespace=.

Inspection

Method & pathNotes
GET /k8s/yaml?kind=&namespace=&name=&context=Live manifest of a resource
GET /k8s/pods/:namespace/:pod/logs?container=&context=Recent pod logs
GET /k8s/ha-analysis?context=High-availability findings, { "findings": [...] }

Mutations

Method & pathBody
POST /k8s/deployments/restart{ "context", "namespace", "deployment" }
POST /k8s/deployments/scale{ "context", "namespace", "deployment", "replicas" } (0โ€“50)
DELETE /k8s/pods/:namespace/:pod?context=โ€”
POST /k8s/apply{ "context", "yaml" }
POST /k8s/findings/:id/applyapplies the finding's diff patch to the live workload; 400 if none

GET /k8s/exec (WebSocket)

Interactive pod shell. Authenticates via ?key=<OPS_RADAR_API_KEY> when the key is set. Client โ†’ server messages:

{ "type": "stdin", "data": "ls\n" }
{ "type": "resize", "cols": 120, "rows": 30 }

Server streams stdout back as text frames.


Settings

Reads and writes ~/.opsradar/.env. Sensitive keys are masked in responses. See Configuration.

GET /settings

{
  "settings": {
    "ANTHROPIC_API_KEY": { "configured": true, "sensitive": true, "preview": "โ€ขโ€ขโ€ขโ€ขโ€ขโ€ขโ€ขโ€ข1234" },
    "GITHUB_REPO":       { "configured": true, "sensitive": false, "value": "myorg/myrepo" }
  }
}

POST /settings

Merge updates (empty string removes a key). Only whitelisted keys are accepted; changes apply to the running process immediately.

{ "ANTHROPIC_API_KEY": "sk-ant-...", "GITHUB_REPO": "myorg/myrepo" }

POST /settings/test

Live-tests a value (ANTHROPIC_API_KEY, GITHUB_TOKEN, or GITHUB_REPO). Omit value to test the saved one.

{ "key": "GITHUB_TOKEN", "value": "ghp_..." }

Returns { "ok": true, "message": "Connected as @you" }.


Ask Bob

POST /bob/chat

Free-form question to the AI backend, optionally grounded in live cluster state.


GitHub

See Connect GitHub.

OAuth App flow

Method & pathPurpose
GET /github/oauth/startReturns { "url": "<github authorize url>" }
GET /github/oauth/callbackGitHub redirect target; exchanges the code, saves GITHUB_TOKEN
GET /github/oauth/status{ "connected": true, "login": "you" }

Local repository scanning

Method & pathBody / query
GET /github/repos?root=<path>Lists git repos up to 3 levels under root (default: home)
POST /github/scan{ "paths": ["/abs/repo", ...] } โ†’ AI findings per repo
POST /github/fix{ "repo_path", "file", "fix", "title", "detail" }