mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 03:27:03 -07:00
feat: add probe command
This commit is contained in:
parent
193733a8e3
commit
e1f190034d
1 changed files with 49 additions and 0 deletions
49
cmd/probe.go
Normal file
49
cmd/probe.go
Normal 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)
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue