package main import ( "encoding/json" "io" "log" "net/http" "os" ) func main() { addr := envDefault("AGENTMON_UI_ADDR", ":8082") queryAPIBase := envDefault("AGENTMON_QUERY_BASE", "http://query-api") mux := http.NewServeMux() mux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) _, _ = w.Write([]byte("ok")) }) mux.HandleFunc("/api/events", func(w http.ResponseWriter, r *http.Request) { resp, err := http.Get(queryAPIBase + "/v1/events?limit=100") if err != nil { w.WriteHeader(http.StatusBadGateway) _, _ = w.Write([]byte("query-api unreachable")) return } defer resp.Body.Close() w.Header().Set("Content-Type", "application/json") w.WriteHeader(resp.StatusCode) _, _ = io.Copy(w, resp.Body) }) mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html; charset=utf-8") payload, _ := json.Marshal(map[string]any{"query_api": queryAPIBase}) _, _ = w.Write([]byte("
Recent events:
loading...")) _, _ = w.Write([]byte("")) }) log.Printf("web-ui listening on %s", addr) log.Fatal(http.ListenAndServe(addr, mux)) } func envDefault(key, def string) string { if v := os.Getenv(key); v != "" { return v } return def }