feat: add probe command

This commit is contained in:
David Allen 2025-06-20 15:22:09 -06:00
parent 0d6cfdec2b
commit bf1ab1922b
Signed by: towk
GPG key ID: 0430CDBE22619155

49
cmd/probe.go Normal file
View file

@ -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)
}