-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers_test.go
58 lines (51 loc) · 965 Bytes
/
helpers_test.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
package main
import (
"fmt"
"sync"
)
type fakeMonSys struct {
sync.RWMutex
Alarms []string
}
func (m *fakeMonSys) generateEventID(server string, alarm string) int {
eventid := 0
switch server {
case "srv1":
eventid = 100
case "db1":
eventid = 200
case "backend1":
eventid = 300
case "frontend1":
eventid = 400
default:
panic("Unknown server, must be initiliazed")
}
switch alarm {
case "CPU":
eventid += 1
case "Memory":
eventid += 2
case "Disk":
eventid += 3
case "Ping":
eventid += 4
case "DBEngine":
eventid += 5
case "Proc":
eventid += 6
case "DBConnection":
eventid += 7
case "BackendConnection":
eventid += 8
default:
panic("Unknown alarm, must be initiliazed")
}
return eventid
}
func (m *fakeMonSys) handleAlarm(server string, alarm string, time float64) {
m.Lock()
defer m.Unlock()
// Get time in unix epoch format
m.Alarms = append(m.Alarms, fmt.Sprintf("%.0f,%s,%s", time, server, alarm))
}