- Updated: March 24, 2026
- 4 min read
Extending the OpenClaw Rating API Go CLI to Listen for Alertmanager Webhooks and Trigger Automated Remediation
# Extending the OpenClaw Rating API Go CLI for Alertmanager Webhooks
Developers often need to react automatically when Prometheus Alertmanager fires an alert. In this guide we’ll extend the **OpenClaw Rating API** Go CLI so it can listen to Alertmanager webhook events and trigger remediation actions such as scaling agents, resetting state, or notifying Moltbook.
—
## Prerequisites
– A running UBOS instance with WordPress installed (your site: `https://ubos.tech`).
– OpenClaw Rating API Go CLI source code (available in the UBOS repository).
– Access to an Alertmanager instance with webhook integration enabled.
– Docker (optional, for containerised deployment).
—
## 1. Add a Webhook Listener to the CLI
Create a new Go file `webhook_listener.go` inside the CLI project:
go
package main
import (
“encoding/json”
“log”
“net/http”
“os/exec”
)
type Alert struct {
Status string `json:”status”`
Alerts []struct {
Labels map[string]string `json:”labels”`
Annotations map[string]string `json:”annotations”`
} `json:”alerts”`
}
func handleAlert(w http.ResponseWriter, r *http.Request) {
var a Alert
if err := json.NewDecoder(r.Body).Decode(&a); err != nil {
http.Error(w, “bad request”, http.StatusBadRequest)
return
}
log.Printf(“Received alert: %s”, a.Status)
// Example remediation: scale agents when alert is firing
if a.Status == “firing” {
go remediate()
}
w.WriteHeader(http.StatusOK)
}
func remediate() {
// Example: run a shell command that scales the OpenClaw agents
cmd := exec.Command(“sh”, “-c”, “docker service scale openclaw_agent=5”)
out, err := cmd.CombinedOutput()
if err != nil {
log.Printf(“Remediation failed: %v, output: %s”, err, out)
return
}
log.Printf(“Remediation succeeded: %s”, out)
// Notify Moltbook (example HTTP POST)
http.Post(“https://moltbook.example.com/notify”, “application/json”, nil)
}
func main() {
http.HandleFunc(“/alertmanager/webhook”, handleAlert)
log.Println(“Starting webhook listener on :8080”)
if err := http.ListenAndServe(“:8080”, nil); err != nil {
log.Fatalf(“Server failed: %v”, err)
}
}
Compile and add the binary to your deployment package.
—
## 2. Deploy the Extended CLI
### Docker‑Compose Example
yaml
version: “3.8”
services:
openclaw-cli:
image: ubos/openclaw-cli:latest
build: .
ports:
– “8080:8080” # expose webhook endpoint
environment:
– ALERTMANAGER_WEBHOOK_URL=http://localhost:8080/alertmanager/webhook
### Kubernetes Manifest (optional)
yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: openclaw-cli
spec:
replicas: 1
selector:
matchLabels:
app: openclaw-cli
template:
metadata:
labels:
app: openclaw-cli
spec:
containers:
– name: cli
image: ubos/openclaw-cli:latest
ports:
– containerPort: 8080
env:
– name: ALERTMANAGER_WEBHOOK_URL
value: “http://localhost:8080/alertmanager/webhook”
—
apiVersion: v1
kind: Service
metadata:
name: openclaw-cli-service
spec:
selector:
app: openclaw-cli
ports:
– protocol: TCP
port: 80
targetPort: 8080
—
## 3. Configure Alertmanager
Add a receiver that points to the new endpoint:
yaml
receivers:
– name: “openclaw-webhook”
webhook_configs:
– url: “http://:8080/alertmanager/webhook”
Reload Alertmanager and test by firing a test alert.
—
## 4. What Happens on an Alert
1. **Alertmanager** sends a POST request to `/alertmanager/webhook`.
2. The CLI parses the payload and, if the status is `firing`, triggers the `remediate` function.
3. `remediate` scales the OpenClaw agents (Docker Swarm example) and notifies **Moltbook** via an HTTP call.
4. All actions are logged for observability.
—
## 5. Deployment Tips
– **Health checks**: expose a `/healthz` endpoint to let orchestration platforms verify the listener is alive.
– **TLS**: terminate TLS at the ingress (NGINX, Traefik) and forward plain HTTP to the CLI.
– **Rate limiting**: add a simple token bucket if you expect bursty alerts.
– **Observability**: ship logs to a central system (e.g., Loki) and expose Prometheus metrics for remediation success/failure counters.
—
## 6. Next Steps
– Extend remediation logic to call OpenClaw’s REST API for more granular actions.
– Add a fallback path that creates a GitHub issue when automated remediation fails.
– Integrate with UBOS’s internal alert dashboard for a unified view.
—
For a full walkthrough of hosting OpenClaw on UBOS, see the dedicated guide: [Host OpenClaw on UBOS](/host-openclaw/).
—
*Happy hacking!*