- Updated: March 24, 2026
- 5 min read
Extending the OpenClaw Rating API Go CLI into an Active Remediation Tool
# Extending the OpenClaw Rating API Go CLI into an Active Remediation Tool
**Author:** UBOS Team
In this tutorial we’ll turn the **OpenClaw Rating API Go CLI** into a fully‑featured active remediation tool that listens to Alertmanager webhook events and automatically triggers corrective actions such as scaling services, restarting pods, and sending Slack notifications.
—
## Table of Contents
1. [Prerequisites](#prerequisites)
2. [Architecture Overview](#architecture-overview)
3. [Step 1 – Create a Go CLI Wrapper](#step-1)
4. [Step 2 – Add Alertmanager Webhook Listener](#step-2)
5. [Step 3 – Implement Remediation Actions](#step-3)
6. [Step 4 – Deploy with Docker & Kubernetes](#step-4)
7. [Step 5 – Test the End‑to‑End Flow](#step-5)
8. [Production Hosting Option](#hosting)
—
## Prerequisites
– Go 1.22 or later installed
– Access to an OpenClaw Rating API endpoint (API key required)
– A running Prometheus + Alertmanager stack
– Slack workspace with an Incoming Webhook URL
– Docker & a Kubernetes cluster (minikube works for testing)
—
+——————-+ +——————-+ +——————-+
| Alertmanager | —> | Remediation | —> | OpenClaw Rating |
| (webhook) | | Service (Go CLI) | | API (Go CLI) |
+——————-+ +——————-+ +——————-+
| |
| v
| +——————-+
| | Slack / K8s Ops |
+————————>+——————-+
The service receives JSON payloads from Alertmanager, parses the alert, decides which remediation action to run, and then invokes the OpenClaw CLI with the appropriate arguments.
—
## Step 1 – Create a Go CLI Wrapper
Create a new Go module and import the existing OpenClaw CLI as a library (or call it as a subprocess).
bash
mkdir openclaw-remediation && cd openclaw-remediation
go mod init github.com/yourorg/openclaw-remediation
go get github.com/openclaw/rating-cli
**main.go**
go
package main
import (
“bytes”
“encoding/json”
“log”
“net/http”
“os/exec”
)
type Alert struct {
Labels map[string]string `json:”labels”`
Annotations map[string]string `json:”annotations”`
Status string `json:”status”`
}
func handleAlert(w http.ResponseWriter, r *http.Request) {
var a Alert
if err := json.NewDecoder(r.Body).Decode(&a); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
go remediate(a) // fire‑and‑forget
w.WriteHeader(http.StatusAccepted)
}
func remediate(a Alert) {
// Example: if alert is about high CPU, trigger scaling
if a.Labels[“alertname”] == “HighCPUUsage” {
scaleService(a.Labels[“service”])
}
// Example: if alert is about pod crash, restart it
if a.Labels[“alertname”] == “PodCrashLoopBackOff” {
restartPod(a.Labels[“pod”])
}
// Notify Slack for every alert
notifySlack(a)
}
func scaleService(service string) {
cmd := exec.Command(“openclaw-cli”, “scale”, “–service”, service, “–factor”, “2”)
runCmd(cmd, “scale”)
}
func restartPod(pod string) {
cmd := exec.Command(“kubectl”, “rollout”, “restart”, “deployment”, pod)
runCmd(cmd, “restart”)
}
func notifySlack(a Alert) {
webhook := os.Getenv(“SLACK_WEBHOOK_URL”)
msg := map[string]string{“text”: “Alert: ” + a.Labels[“alertname”] + ” – ” + a.Annotations[“summary”]}
payload, _ := json.Marshal(msg)
http.Post(webhook, “application/json”, bytes.NewBuffer(payload))
}
func runCmd(c *exec.Cmd, action string) {
out, err := c.CombinedOutput()
if err != nil {
log.Printf(“%s failed: %v – %s”, action, err, string(out))
} else {
log.Printf(“%s succeeded: %s”, action, string(out))
}
}
func main() {
http.HandleFunc(“/alert”, handleAlert)
log.Println(“Listening on :8080 …”)
log.Fatal(http.ListenAndServe(“:8080”, nil))
}
The wrapper exposes a single `/alert` endpoint that Alertmanager will call.
—
## Step 2 – Add Alertmanager Webhook Listener
Edit your Alertmanager configuration to point to the new service.
yaml
receivers:
– name: “openclaw-remediation”
webhook_configs:
– url: “http://openclaw-remediation.default.svc.cluster.local:8080/alert”
send_resolved: true
route:
receiver: “openclaw-remediation”
Apply the config and reload Alertmanager.
—
## Step 3 – Implement Remediation Actions
The example above shows two simple actions (scale & restart). You can extend `remediate` with additional logic:
– **Run custom scripts** (`exec.Command(“/path/to/script.sh”)`)
– **Create GitOps pull‑requests** using the OpenClaw API
– **Post to other chat tools** (Teams, Discord)
Make sure each action logs its output – this helps with debugging.
—
## Step 4 – Deploy with Docker & Kubernetes
Create a Dockerfile:
Dockerfile
FROM golang:1.22-alpine AS builder
WORKDIR /app
COPY . .
RUN go build -o /openclaw-remediation .
FROM alpine:latest
COPY –from=builder /openclaw-remediation /openclaw-remediation
ENV SLACK_WEBHOOK_URL=”${SLACK_WEBHOOK_URL}”
EXPOSE 8080
ENTRYPOINT [“/openclaw-remediation”]
Build and push the image, then deploy:
yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: openclaw-remediation
spec:
replicas: 1
selector:
matchLabels:
app: openclaw-remediation
template:
metadata:
labels:
app: openclaw-remediation
spec:
containers:
– name: app
image: ghcr.io/yourorg/openclaw-remediation:latest
env:
– name: SLACK_WEBHOOK_URL
valueFrom:
secretKeyRef:
name: slack-webhook
key: url
ports:
– containerPort: 8080
—
apiVersion: v1
kind: Service
metadata:
name: openclaw-remediation
spec:
selector:
app: openclaw-remediation
ports:
– protocol: TCP
port: 80
targetPort: 8080
Apply the manifests:
bash
kubectl apply -f deployment.yaml
Now the service is reachable inside the cluster at `http://openclaw-remediation:80/alert`.
—
## Step 5 – Test the End‑to‑End Flow
1. **Create a test alert**:
bash
curl -XPOST -d ‘{“labels”:{“alertname”:”HighCPUUsage”,”service”:”frontend”},”annotations”:{“summary”:”CPU > 90% on frontend”},”status”:”firing”}’ http:///api/v1/alerts
2. **Check the pod logs**:
bash
kubectl logs deployment/openclaw-remediation
You should see the scaling command executed.
3. **Verify Slack** – the channel should contain the alert notification.
—
## Production Hosting Option
For a production‑ready deployment, we recommend using UBOS’s hosted OpenClaw solution. It provides automatic TLS, built‑in monitoring, and one‑click scaling of the remediation service. Learn more at the dedicated hosting page:
—
*Happy automating!*