diff --git a/cmd/frostfs-cli/internal/commonflags/flags.go b/cmd/frostfs-cli/internal/commonflags/flags.go index 23dbc8c2b..cd46d63eb 100644 --- a/cmd/frostfs-cli/internal/commonflags/flags.go +++ b/cmd/frostfs-cli/internal/commonflags/flags.go @@ -53,6 +53,10 @@ const ( AwaitFlag = "await" AwaitFlagUsage = "Wait for the operation to complete" + + QuietFlag = "quiet" + QuietFlagShorthand = "q" + QuietFlagUsage = "Print nothing and exit with non-zero code on failure" ) // Init adds common flags to the command: diff --git a/cmd/frostfs-cli/modules/control/healthcheck.go b/cmd/frostfs-cli/modules/control/healthcheck.go index 097fba540..2241a403f 100644 --- a/cmd/frostfs-cli/modules/control/healthcheck.go +++ b/cmd/frostfs-cli/modules/control/healthcheck.go @@ -1,7 +1,10 @@ package control import ( + "os" + rawclient "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client" + "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key" commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control" @@ -24,6 +27,7 @@ func initControlHealthCheckCmd() { flags := healthCheckCmd.Flags() flags.Bool(healthcheckIRFlag, false, "Communicate with IR node") + flags.BoolP(commonflags.QuietFlag, commonflags.QuietFlagShorthand, false, commonflags.QuietFlagUsage) _ = flags.MarkDeprecated(healthcheckIRFlag, "for health check of inner ring nodes, use the 'control ir healthcheck' command instead.") } @@ -50,6 +54,12 @@ func healthCheck(cmd *cobra.Command, args []string) { commonCmd.ExitOnErr(cmd, "rpc error: %w", err) verifyResponse(cmd, resp.GetSignature(), resp.GetBody()) + if quietFlag, _ := cmd.Flags().GetBool(commonflags.QuietFlag); quietFlag { + if resp.GetBody().GetHealthStatus() == control.HealthStatus_READY { + return + } + os.Exit(1) + } cmd.Printf("Network status: %s\n", resp.GetBody().GetNetmapStatus()) cmd.Printf("Health status: %s\n", resp.GetBody().GetHealthStatus()) diff --git a/cmd/frostfs-cli/modules/control/ir_healthcheck.go b/cmd/frostfs-cli/modules/control/ir_healthcheck.go index e70538ce2..4f272c1b4 100644 --- a/cmd/frostfs-cli/modules/control/ir_healthcheck.go +++ b/cmd/frostfs-cli/modules/control/ir_healthcheck.go @@ -1,7 +1,10 @@ package control import ( + "os" + rawclient "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client" + "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key" commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common" ircontrol "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control/ir" @@ -18,6 +21,8 @@ var irHealthCheckCmd = &cobra.Command{ func initControlIRHealthCheckCmd() { initControlFlags(irHealthCheckCmd) + flags := irHealthCheckCmd.Flags() + flags.BoolP(commonflags.QuietFlag, commonflags.QuietFlagShorthand, false, commonflags.QuietFlagUsage) } func irHealthCheck(cmd *cobra.Command, _ []string) { @@ -39,6 +44,12 @@ func irHealthCheck(cmd *cobra.Command, _ []string) { commonCmd.ExitOnErr(cmd, "rpc error: %w", err) verifyResponse(cmd, resp.GetSignature(), resp.GetBody()) + if quietFlag, _ := cmd.Flags().GetBool(commonflags.QuietFlag); quietFlag { + if resp.GetBody().GetHealthStatus() == ircontrol.HealthStatus_READY { + return + } + os.Exit(1) + } cmd.Printf("Health status: %s\n", resp.GetBody().GetHealthStatus()) }