Added more output for debugging

This commit is contained in:
David J. Allen 2024-05-09 13:18:38 -06:00
parent a75530e96b
commit e93f49eb82
No known key found for this signature in database
GPG key ID: 717C593FF60A2ACC
3 changed files with 21 additions and 8 deletions

View file

@ -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)

View file

@ -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

View file

@ -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)