-
Notifications
You must be signed in to change notification settings - Fork 3
/
monitor.go
53 lines (44 loc) · 1.12 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
package shimesaba
import (
"fmt"
"time"
)
type Monitor struct {
id string
name string
monitorType string
evaluator func(hostID string, timeFrame time.Duration, startAt, endAt time.Time) (Reliabilities, bool)
}
func NewMonitor(id, name, monitorType string) *Monitor {
return &Monitor{
id: id,
name: name,
monitorType: monitorType,
}
}
func (m *Monitor) WithEvaluator(evaluator func(hostID string, timeFrame time.Duration, startAt, endAt time.Time) (Reliabilities, bool)) *Monitor {
return &Monitor{
id: m.id,
name: m.name,
monitorType: m.monitorType,
evaluator: evaluator,
}
}
func (m *Monitor) ID() string {
return m.id
}
func (m *Monitor) Name() string {
return m.name
}
func (m *Monitor) Type() string {
return m.monitorType
}
func (m *Monitor) String() string {
return fmt.Sprintf("[%s]%s", m.monitorType, m.name)
}
func (m *Monitor) EvaluateReliabilities(hostID string, timeFrame time.Duration, startAt, endAt time.Time) (Reliabilities, bool) {
if m.evaluator == nil {
return nil, false
}
return m.evaluator(hostID, timeFrame, startAt, endAt)
}