-
Notifications
You must be signed in to change notification settings - Fork 51
/
monitor.go
77 lines (66 loc) · 2.1 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// +build windows
package windowsmonitor
import (
"context"
"fmt"
"regexp"
"go.aporeto.io/enforcerd/trireme-lib/common"
"go.aporeto.io/enforcerd/trireme-lib/monitor/config"
"go.aporeto.io/enforcerd/trireme-lib/monitor/registerer"
)
// WindowsMonitor hold state for the windows monitor
type WindowsMonitor struct {
proc *windowsProcessor
}
// New returns a new implmentation of a monitor implmentation
func New(context.Context) *WindowsMonitor {
return &WindowsMonitor{
proc: &windowsProcessor{},
}
}
// Run implements Implementation interface
func (w *WindowsMonitor) Run(ctx context.Context) error {
if err := w.proc.config.IsComplete(); err != nil {
return fmt.Errorf("windows %t: %s", w.proc.host, err)
}
return w.Resync(ctx)
}
// SetupHandlers sets up handlers for monitors to invoke for various events such as
// processing unit events and synchronization events. This will be called before Start()
// by the consumer of the monitor
func (w *WindowsMonitor) SetupHandlers(m *config.ProcessorConfig) {
w.proc.config = m
}
// SetupConfig sets up the config for the monitor
func (w *WindowsMonitor) SetupConfig(registerer registerer.Registerer, cfg interface{}) error {
if cfg == nil {
cfg = DefaultConfig(false)
}
windowsConfig, ok := cfg.(*Config)
if !ok {
return fmt.Errorf("Invalid configuration specified")
}
if registerer != nil {
if err := registerer.RegisterProcessor(common.HostPU, w.proc); err != nil {
return err
}
if err := registerer.RegisterProcessor(common.HostNetworkPU, w.proc); err != nil {
return err
}
if err := registerer.RegisterProcessor(common.WindowsProcessPU, w.proc); err != nil {
return err
}
}
windowsConfig = SetupDefaultConfig(windowsConfig)
w.proc.host = windowsConfig.Host
w.proc.regStart = regexp.MustCompile("^[a-zA-Z0-9_]{1,11}$")
w.proc.metadataExtractor = windowsConfig.EventMetadataExtractor
if w.proc.metadataExtractor == nil {
return fmt.Errorf("Unable to setup a metadata extractor")
}
return nil
}
// Resync instructs the monitor to do a resync.
func (w *WindowsMonitor) Resync(ctx context.Context) error {
return w.proc.Resync(ctx, nil)
}