forked from zmap/zgrab2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonitor.go
62 lines (55 loc) · 1.37 KB
/
monitor.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
package zgrab2
// Monitor is a collection of states per scans and a channel to communicate
// those scans to the monitor
type Monitor struct {
states map[string]*State
statusesChan chan moduleStatus
// Callback is invoked after each scan.
Callback func(string)
}
// State contains the respective number of successes and failures
// for a given scan
type State struct {
Successes uint `json:"successes"`
Failures uint `json:"failures"`
}
type moduleStatus struct {
name string
st status
}
type status uint
const (
statusSuccess status = iota
statusFailure status = iota
)
// GetStatuses returns a mapping from scanner names to the current number
// of successes and failures for that scanner
func (m *Monitor) GetStatuses() map[string]*State {
return m.states
}
// MakeMonitor returns a Monitor object that can be used to collect and send
// the status of a running scan
func MakeMonitor() *Monitor {
m := new(Monitor)
m.statusesChan = make(chan moduleStatus, config.Senders*4)
m.states = make(map[string]*State, 10)
go func() {
for s := range m.statusesChan {
if m.states[s.name] == nil {
m.states[s.name] = new(State)
}
if m.Callback != nil {
m.Callback(s.name)
}
switch s.st {
case statusSuccess:
m.states[s.name].Successes++
case statusFailure:
m.states[s.name].Failures++
default:
continue
}
}
}()
return m
}