-
Notifications
You must be signed in to change notification settings - Fork 14
/
server.go
50 lines (40 loc) · 874 Bytes
/
server.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
package main
type Server struct {
Config *Config
LogChan chan *Log
Monitors []*Monitor
Notifiers []Notifier
}
func NewServer(config *Config) (*Server, error) {
s := &Server{
Config: config,
LogChan: make(chan *Log, 50),
}
for _, monitorConf := range config.MonitorConfs {
monitor, err := NewMonitor(monitorConf)
if err != nil {
return nil, err
}
s.Monitors = append(s.Monitors, monitor)
}
s.Notifiers = append(s.Notifiers, NotifyViaStderr)
for _, notifierConf := range config.NotifierConfs {
notifier, err := NewNotifier(notifierConf)
if err != nil {
return nil, err
}
s.Notifiers = append(s.Notifiers, notifier)
}
return s, nil
}
func (s *Server) Loop() {
for _, monitor := range s.Monitors {
go monitor.Watch(s.LogChan)
}
for {
log := <-s.LogChan
for _, notifier := range s.Notifiers {
notifier(log)
}
}
}