zgrab2/monitor.go

58 lines
1.2 KiB
Go
Raw Normal View History

package zgrab2
2017-10-04 03:57:56 +00:00
// 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
}
2017-10-04 03:57:56 +00:00
// 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 (
2017-10-04 03:57:56 +00:00
statusSuccess status = iota
statusFailure status = iota
)
2017-10-04 03:57:56 +00:00
// 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
}
2017-10-04 03:57:56 +00:00
// 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)
}
switch s.st {
2017-10-04 03:57:56 +00:00
case statusSuccess:
m.states[s.name].Successes++
2017-10-04 03:57:56 +00:00
case statusFailure:
m.states[s.name].Failures++
default:
continue
}
}
}()
return m
}