diff --git a/cmd/scan.go b/cmd/scan.go index ca2fdd0..50534a2 100644 --- a/cmd/scan.go +++ b/cmd/scan.go @@ -57,7 +57,7 @@ var scanCmd = &cobra.Command{ if threads <= 0 { threads = mathutil.Clamp(len(hostsToScan), 1, 255) } - probeStates := magellan.ScanForAssets(hostsToScan, portsToScan, threads, timeout, disableProbing) + probeStates := magellan.ScanForAssets(hostsToScan, portsToScan, threads, timeout, disableProbing, verbose) if verbose { for _, r := range probeStates { fmt.Printf("%s:%d (%s)\n", r.Host, r.Port, r.Protocol) diff --git a/internal/collect.go b/internal/collect.go index d97b6e6..9eff14f 100644 --- a/internal/collect.go +++ b/internal/collect.go @@ -125,7 +125,10 @@ func CollectAll(probeStates *[]ScannedResult, l *log.Logger, q *QueryParams) err l.Log.Errorf("failed to query chassis: %v", err) continue } - json.Unmarshal(chassis, &rm) + err = json.Unmarshal(chassis, &rm) + if err != nil { + l.Log.Errorf("failed to unmarshal chassis JSON: %v", err) + } data["Chassis"] = rm["Chassis"] // systems @@ -133,7 +136,10 @@ func CollectAll(probeStates *[]ScannedResult, l *log.Logger, q *QueryParams) err if err != nil { l.Log.Errorf("failed to query systems: %v", err) } - json.Unmarshal(systems, &rm) + err = json.Unmarshal(systems, &rm) + if err != nil { + l.Log.Errorf("failed to unmarshal system JSON: %v", err) + } data["Systems"] = rm["Systems"] // add other fields from systems diff --git a/internal/scan.go b/internal/scan.go index 2b8c14e..4ff6fc4 100644 --- a/internal/scan.go +++ b/internal/scan.go @@ -95,11 +95,12 @@ func generateHosts(ip *net.IP, mask *net.IPMask) []string { return hosts } -func ScanForAssets(hosts []string, ports []int, threads int, timeout int, disableProbing bool) []ScannedResult { - results := make([]ScannedResult, 0, len(hosts)) - done := make(chan struct{}, threads+1) - chanHost := make(chan string, threads+1) - // chanPort := make(chan int, threads+1) +func ScanForAssets(hosts []string, ports []int, threads int, timeout int, disableProbing bool, verbose bool) []ScannedResult { + var ( + results = make([]ScannedResult, 0, len(hosts)) + done = make(chan struct{}, threads+1) + chanHost = make(chan string, threads+1) + ) var wg sync.WaitGroup wg.Add(threads) @@ -118,8 +119,14 @@ func ScanForAssets(hosts []string, ports []int, threads int, timeout int, disabl url := fmt.Sprintf("https://%s:%d/redfish/v1/", result.Host, result.Port) res, _, err := util.MakeRequest(nil, url, "GET", nil, nil) if err != nil || res == nil { + if verbose { + fmt.Printf("failed to make request: %v\n", err) + } continue } else if res.StatusCode != http.StatusOK { + if verbose { + fmt.Printf("request returned code: %v\n", res.StatusCode) + } continue } else { probeResults = append(probeResults, result)