-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.go
56 lines (47 loc) · 1.34 KB
/
database.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
package main
// Database represents a database server with a database engine running (like postgres, mysql, etc)
type Database struct {
DBEngineAlarm AlarmStatus
Server
}
// NewDatabase create a new database server, start it and return the pointer to it
func NewDatabase(name string, mon MonitorSystem) *Database {
return &Database{
Server: Server{
Name: name,
mon: mon,
},
}
}
func (d *Database) GetName() string {
return d.Name
}
func (s *Database) GetAlarms() []string {
serverAlarms := s.Server.GetAlarms()
return append(serverAlarms, []string{"DBEngine"}...)
}
func (s *Database) GetType() string {
return string(DBNode)
}
// CheckAlarms print a message if the database engines is not working
// or the base server has alarms.
func (d *Database) CheckAlarms(t float64) {
if d.DBEngineAlarm == AlarmTriggered {
d.DBEngineAlarm = AlarmACK
d.mon.handleAlarm(d.Name, "DBEngine", t)
}
d.Server.CheckAlarms(t)
}
// Available return true if the db server is considered available, that is,
// if the db engine is available and the server is available.
func (d *Database) Available() bool {
return d.Server.Available() && d.DBEngineAlarm == AlarmEnabled
}
func (d *Database) SetAlarm(alarm string, status AlarmStatus) {
switch alarm {
case "DBEngine":
d.DBEngineAlarm = AlarmTriggered
default:
d.Server.SetAlarm(alarm, status)
}
}