Implement 'get' and 'get keys' -SDL CLI commands
[ric-plt/sdlgo.git] / internal / cli / healthcheck.go
index 94467a9..2da97a3 100644 (file)
 package cli
 
 import (
-       "bytes"
        "fmt"
        "gerrit.o-ran-sc.org/r/ric-plt/sdlgo/internal/sdlgoredis"
        "github.com/spf13/cobra"
        "os"
 )
 
-func NewHealthCheckCmd() *cobra.Command {
-       return newHealthCheckCmd(newDatabase)
+func init() {
+       rootCmd.AddCommand(newHealthCheckCmd(newDatabase))
 }
 
 func newHealthCheckCmd(dbCreateCb DbCreateCb) *cobra.Command {
@@ -40,8 +39,6 @@ func newHealthCheckCmd(dbCreateCb DbCreateCb) *cobra.Command {
                Short: "healthcheck - validates database healthiness",
                Long:  `healthcheck - validates database healthiness`,
                RunE: func(cmd *cobra.Command, args []string) error {
-                       var buf bytes.Buffer
-                       sdlgoredis.SetDbLogger(&buf)
                        out, err := runHealthCheck(dbCreateCb)
                        cmd.Println(out)
                        if err != nil {
@@ -96,6 +93,15 @@ func writeStateResults(dbStates []sdlgoredis.DbState) string {
                                }
                        }
                }
+               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 {
                str = fmt.Sprintf("Overall status: OK\n\n") + str