diff --git a/etcdctl/ctlv3/command/ep_command.go b/etcdctl/ctlv3/command/ep_command.go index bc86b4aa6..589a76aa7 100644 --- a/etcdctl/ctlv3/command/ep_command.go +++ b/etcdctl/ctlv3/command/ep_command.go @@ -20,6 +20,7 @@ import ( "sync" "time" + "go.etcd.io/etcd/api/v3/etcdserverpb" "go.etcd.io/etcd/api/v3/v3rpc/rpctypes" v3 "go.etcd.io/etcd/client/v3" "go.etcd.io/etcd/pkg/v3/flags" @@ -124,7 +125,6 @@ func epHealthCommandFunc(cmd *cobra.Command, args []string) { // endpoint is health. ctx, cancel := commandCtx(cmd) _, err = cli.Get(ctx, "health") - cancel() eh := epHealth{Ep: ep, Health: false, Took: time.Since(st).String()} // permission denied is OK since proposal goes through consensus to get it if err == nil || err == rpctypes.ErrPermissionDenied { @@ -132,6 +132,28 @@ func epHealthCommandFunc(cmd *cobra.Command, args []string) { } else { eh.Error = err.Error() } + + if eh.Health == true { + resp, err := cli.AlarmList(ctx) + if err == nil && len(resp.Alarms) > 0 { + eh.Health = false + eh.Error = "Active Alarm(s): " + for _, v := range resp.Alarms { + switch v.Alarm { + case etcdserverpb.AlarmType_NOSPACE: + eh.Error = eh.Error + "NOSPACE " + case etcdserverpb.AlarmType_CORRUPT: + eh.Error = eh.Error + "CORRUPT " + default: + eh.Error = eh.Error + "UNKNOWN " + } + } + } else if err != nil { + eh.Health = false + eh.Error = "Unable to fetch the alarm list" + } + } + cancel() hch <- eh }(cfg) }