From bf1ab1922bda1c3027901ce11dcaec4c09ba0a31 Mon Sep 17 00:00:00 2001 From: David Allen Date: Fri, 20 Jun 2025 15:22:09 -0600 Subject: [PATCH] feat: add probe command --- cmd/probe.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 cmd/probe.go diff --git a/cmd/probe.go b/cmd/probe.go new file mode 100644 index 0000000..550b599 --- /dev/null +++ b/cmd/probe.go @@ -0,0 +1,49 @@ +package cmd + +import ( + "fmt" + "net/http" + "os" + + "github.com/davidallendj/magellan/pkg/client" + "github.com/rs/zerolog/log" + "github.com/spf13/cobra" +) + +var probeCmd = &cobra.Command{ + Use: "probe [hosts...]", + Example: ` // probe for Redfish service + magellan probe https://172.16.0.100 https://172.16.0.101 +`, + Args: cobra.MinimumNArgs(1), + Short: "Probe specified URI for Redfish service.", + Run: func(cmd *cobra.Command, args []string) { + for _, host := range args { + res, _, err := client.MakeRequest( + nil, + fmt.Sprintf("%s/redfish/v1/", host), + http.MethodGet, + nil, + nil, + ) + if err != nil { + log.Error().Err(err). + Str("host", host).Send() + continue + } + if res.StatusCode == http.StatusOK { + log.Info().Msg("found Redfish service") + os.Exit(0) + } else { + log.Error(). + Int("status_code", res.StatusCode). + Msg("something went wrong") + os.Exit(1) + } + } + }, +} + +func init() { + rootCmd.AddCommand(probeCmd) +}