mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-19 19:17:02 -07:00
Merge pull request 'Add probe command for detecting Redfish services' (#16) from probe-cmd into main
Reviewed-on: towk/magellan-ng#16
This commit is contained in:
commit
12cb2d03a5
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