Added tests and readme

This commit is contained in:
2026-05-12 06:20:51 +00:00
parent 7e85bb0fcc
commit 139c224a31
23 changed files with 1449 additions and 97 deletions
+5 -18
View File
@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"text/tabwriter"
"time"
"github.com/google/uuid"
@@ -30,30 +31,16 @@ func addAlertCmd(root *cobra.Command) {
Use: "list",
Short: "List configured alerts",
RunE: func(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(cmd.Context(), 10*time.Second)
defer cancel()
raw, err := callDaemon(ctx, daemon.CtrlStatus, nil)
if err != nil {
return err
}
var st transport.StatusResponse
if err := json.Unmarshal(raw, &st); err != nil {
return err
}
// status response doesn't carry alerts — call mutate with a
// "list" by reading cluster.yaml indirectly via status's
// version is not enough. Fall back: ask for ClusterConfig
// via a dedicated read RPC if needed. For v1 we rely on
// node.yaml being co-located: read the local cluster.yaml
// directly so the operator gets up-to-date output.
cluster, err := config.LoadClusterConfig()
if err != nil {
return err
}
tw := tabwriter.NewWriter(cmd.OutOrStdout(), 0, 0, 2, ' ', 0)
fmt.Fprintln(tw, "ID\tTYPE\tNAME")
for _, a := range cluster.Alerts {
fmt.Fprintf(cmd.OutOrStdout(), "%s\t%s\t%s\n", a.ID, a.Type, a.Name)
fmt.Fprintf(tw, "%s\t%s\t%s\n", a.ID, a.Type, a.Name)
}
return nil
return tw.Flush()
},
}
-5
View File
@@ -30,7 +30,6 @@ func addCheckCmd(root *cobra.Command) {
})
addHTTP.Flags().Int("expect", 200, "HTTP status code that signals UP")
addHTTP.Flags().String("body-match", "", "substring required in response body for UP")
bindHTTPFlags(addHTTP)
addTCP := buildAddCheckCmd(config.CheckTCP, "tcp", "<name> <host:port>",
"Add a TCP-connect check",
@@ -168,7 +167,3 @@ func bindCheckFlags(cmd *cobra.Command) {
cmd.Flags().String("timeout", "10s", "per-probe timeout")
cmd.Flags().String("alerts", "", "comma-separated alert IDs/names to notify on transition")
}
// bindHTTPFlags is a no-op kept to mirror the per-type flag bind sites
// so the caller can extend cleanly later.
func bindHTTPFlags(cmd *cobra.Command) {}