- if dbState.SentinelsDbState != nil {
- for k, sInfo := range dbState.SentinelsDbState.States {
- err := sInfo.IsOnline()
- if err != nil {
- str = str + fmt.Sprintf(" Sentinel #%d (%s): NOK\n", (k+1), sInfo.GetAddress())
- str = str + fmt.Sprintf(" %s\n", err.Error())
- }
+ }
+ if anyErr == nil {
+ cmd.Println("Overall status: OK")
+ } else {
+ cmd.Println("Overall status: NOK")
+ }
+ cmd.Println("")
+ w.Flush()
+}
+
+func printPrimaryHealthStatus(w *tabwriter.Writer, clusterID int, dbState *sdlgoredis.DbState) error {
+ addr := printAddress(dbState.PrimaryDbState.GetAddress())
+ err := dbState.PrimaryDbState.IsOnline()
+ if err != nil {
+ fmt.Fprintf(w, "%d\t%s\t%s\t%s\t%s\t\n", clusterID, "primary", addr, "NOK", err.Error())
+ } else {
+ fmt.Fprintf(w, "%d\t%s\t%s\t%s\t%s\t\n", clusterID, "primary", addr, "OK", "<none>")
+ }
+ return err
+}
+
+func printReplicasHealthStatus(w *tabwriter.Writer, clusterID int, dbState *sdlgoredis.DbState) error {
+ var anyErr error
+
+ if dbState.ReplicasDbState != nil {
+ if dbState.ConfigNodeCnt > len(dbState.ReplicasDbState.States)+1 {
+ err := fmt.Errorf("Configured DBAAS nodes %d but only 1 primary and %d replicas",
+ dbState.ConfigNodeCnt, len(dbState.ReplicasDbState.States))
+ fmt.Fprintf(w, "%d\t%s\t%s\t%s\t%s\t\n", clusterID, "replica", "<none>", "NOK", err.Error())
+ anyErr = err
+ }
+ for _, state := range dbState.ReplicasDbState.States {
+ if err := printReplicaHealthStatus(w, clusterID, state); err != nil {
+ anyErr = err