mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 03:27:03 -07:00
Add standalone command for querying a single BMC and outputting inventory json
This commit is contained in:
parent
5072b9bc21
commit
a7d5b0ebbb
2 changed files with 131 additions and 0 deletions
43
cmd/crawl.go
Normal file
43
cmd/crawl.go
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/OpenCHAMI/magellan/pkg/crawler"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var crawlCmd = &cobra.Command{
|
||||
Use: "crawl",
|
||||
Short: "Crawl a single BMC for inventory information",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
systems, err := crawler.CrawlBMC(crawler.CrawlerConfig{
|
||||
URI: cmd.Flag("uri").Value.String(),
|
||||
Username: cmd.Flag("username").Value.String(),
|
||||
Password: cmd.Flag("password").Value.String(),
|
||||
Insecure: cmd.Flag("insecure").Value.String() == "true",
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// Marshal the inventory details to JSON
|
||||
jsonData, err := json.MarshalIndent(systems, "", " ")
|
||||
if err != nil {
|
||||
fmt.Println("Error marshalling to JSON:", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Print the pretty JSON
|
||||
fmt.Println(string(jsonData))
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
crawlCmd.Flags().StringP("uri", "u", "", "URI of the BMC")
|
||||
crawlCmd.Flags().StringP("username", "n", "", "Username for the BMC")
|
||||
crawlCmd.Flags().StringP("password", "p", "", "Password for the BMC")
|
||||
crawlCmd.Flags().BoolP("insecure", "i", false, "Ignore SSL errors")
|
||||
|
||||
rootCmd.AddCommand(crawlCmd)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue