forked from nathanielc/morgoth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
engine.go
54 lines (44 loc) · 1.13 KB
/
engine.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
package morgoth
import (
"errors"
"fmt"
"github.com/nathanielc/morgoth/config"
"time"
)
type Engine interface {
Initialize() error
GetWindows(query Query) ([]*Window, error)
NewQueryBuilder(queryTemplate string, groupByInterval time.Duration) (QueryBuilder, error)
RecordAnomalous(w Window) error
}
var EngineRegistery *config.Registery
func init() {
EngineRegistery = config.NewRegistry()
}
// Configuration
// The Data Engine subsection of the config
type EngineConf struct {
config.DynamicConfiguration
}
func (self *EngineConf) UnmarshalYAML(unmarshal func(interface{}) error) error {
return self.PerformUnmarshalYAML(EngineRegistery, unmarshal)
}
func EngineFromYAML(yaml string) (*EngineConf, error) {
conf := new(EngineConf)
err := config.PerformFromYAML(yaml, conf)
if err != nil {
return nil, err
}
return conf, nil
}
func (self *EngineConf) GetEngine() (Engine, error) {
instance, err := self.PerformGetInstance(EngineRegistery)
if err != nil {
return nil, err
}
engine, ok := instance.(Engine)
if !ok {
return nil, errors.New(fmt.Sprintf("Instance %v is not of type Engine", instance))
}
return engine, nil
}