-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwalkerstatus.go
69 lines (60 loc) · 1.77 KB
/
walkerstatus.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package walker
import (
"fmt"
"io"
"sort"
"github.com/foomo/walker/reports"
"github.com/foomo/walker/vo"
)
func (w *Walker) PrintStatus(writer io.Writer, status vo.Status) {
headline(writer,
"Status: ",
" jobs: ", len(status.Jobs),
", results: ", len(status.Results),
", current scapespeed: ", status.ScrapeSpeed, "requests/s",
",average scrape speed:", status.ScrapeSpeedAverage, "requests/s",
)
headline(writer,
" scrape window: ", status.ScrapeWindowRequests, status.ScrapeWindowSeconds,
", scapespeed: ", status.ScrapeSpeed, "requests/s",
)
headline(writer,
" scrape average: ", status.ScrapeTotalRequests, status.ScrapeTotalSeconds,
", scapespeed: ", status.ScrapeSpeedAverage, "requests/s",
)
reports.ReportSummaryBody(status, writer, nil)
headline(writer, "currently scanning")
for targetURL, active := range status.Jobs {
if active {
fmt.Fprintln(writer, targetURL)
}
}
notFoundKeys := []string{}
notFoundMap := map[string]vo.ScrapeResult{}
errorKeys := []string{}
errorMap := map[string]vo.ScrapeResult{}
for targetURL, result := range status.Results {
switch true {
case result.Code == 404:
notFoundKeys = append(notFoundKeys, targetURL)
notFoundMap[targetURL] = result
case result.Code >= 500:
errorKeys = append(errorKeys, targetURL)
errorMap[targetURL] = result
case result.Code == 0:
errorKeys = append(errorKeys, targetURL)
errorMap[targetURL] = result
}
}
sort.Strings(errorKeys)
sort.Strings(notFoundKeys)
headline(writer, "bad errors")
for _, targetURL := range errorKeys {
result := status.Results[targetURL]
fmt.Fprintln(writer, result.Code, result.Status, result.TargetURL, result.Error)
}
headline(writer, "dead links")
for _, targetURL := range notFoundKeys {
fmt.Fprintln(writer, targetURL)
}
}