+ 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
+ }
+ }
+ }
+ return anyErr
+}
+
+func printReplicaHealthStatus(w *tabwriter.Writer, clusterID int, dbState *sdlgoredis.ReplicaDbState) error {
+ addr := printAddress(dbState.GetAddress())
+ err := dbState.IsOnline()
+ if err != nil {
+ fmt.Fprintf(w, "%d\t%s\t%s\t%s\t%s\t\n", clusterID, "replica", addr, "NOK", err.Error())
+ } else {
+ fmt.Fprintf(w, "%d\t%s\t%s\t%s\t%s\t\n", clusterID, "replica", addr, "OK", "<none>")
+ }
+ return err
+}
+
+func printSentinelsHealthStatus(w *tabwriter.Writer, clusterID int, dbState *sdlgoredis.DbState) error {
+ var anyErr error
+ if dbState.SentinelsDbState != nil {
+ for _, state := range dbState.SentinelsDbState.States {
+ if err := printSentinelHealthStatus(w, clusterID, state); err != nil {
+ anyErr = err
+ }
+ }
+ }
+ return anyErr
+}
+func printSentinelHealthStatus(w *tabwriter.Writer, clusterID int, dbState *sdlgoredis.SentinelDbState) error {
+ err := dbState.IsOnline()
+ if err != nil {
+ fmt.Fprintf(w, "%d\t%s\t%s\t%s\t%s\t\n", clusterID, "sentinel", dbState.GetAddress(), "NOK", err.Error())
+ }
+ return err
+}
+
+func printAddress(address string) string {
+ if address == "" {
+ return "<none>"