mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 03:27:03 -07:00
refactor: changed logging to use consistent JSON format
This commit is contained in:
parent
5c4ca34976
commit
cc112e72e4
1 changed files with 8 additions and 5 deletions
13
cmd/crawl.go
13
cmd/crawl.go
|
|
@ -3,7 +3,8 @@ package cmd
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
|
|
||||||
urlx "github.com/OpenCHAMI/magellan/internal/url"
|
urlx "github.com/OpenCHAMI/magellan/internal/url"
|
||||||
"github.com/OpenCHAMI/magellan/pkg/crawler"
|
"github.com/OpenCHAMI/magellan/pkg/crawler"
|
||||||
|
|
@ -36,9 +37,11 @@ var CrawlCmd = &cobra.Command{
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
// try and load credentials from local store first
|
||||||
store, err := secrets.OpenStore(secretsFile)
|
store, err := secrets.OpenStore(secretsFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
log.Error().Err(err).Msg("failed to open store")
|
||||||
|
// try and use the `username` and `password` arguments instead
|
||||||
store = &secrets.StaticStore{
|
store = &secrets.StaticStore{
|
||||||
Username: username,
|
Username: username,
|
||||||
Password: password,
|
Password: password,
|
||||||
|
|
@ -47,15 +50,15 @@ var CrawlCmd = &cobra.Command{
|
||||||
systems, err := crawler.CrawlBMCForSystems(crawler.CrawlerConfig{
|
systems, err := crawler.CrawlBMCForSystems(crawler.CrawlerConfig{
|
||||||
URI: args[0],
|
URI: args[0],
|
||||||
CredentialStore: store,
|
CredentialStore: store,
|
||||||
Insecure: cmd.Flag("insecure").Value.String() == "true",
|
Insecure: insecure,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error crawling BMC: %v", err)
|
log.Error().Err(err).Msg("error crawling BMC")
|
||||||
}
|
}
|
||||||
// Marshal the inventory details to JSON
|
// Marshal the inventory details to JSON
|
||||||
jsonData, err := json.MarshalIndent(systems, "", " ")
|
jsonData, err := json.MarshalIndent(systems, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error marshalling to JSON:", err)
|
log.Error().Err(err).Msg("error marshalling to JSON:")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue