-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtypes.go
More file actions
89 lines (76 loc) · 2.25 KB
/
types.go
File metadata and controls
89 lines (76 loc) · 2.25 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package syshealth
// Data stores metrics identified by key
type Data map[string]interface{}
// MetricBag is a container used to transport metrics and eventually some metadata
type MetricBag struct {
Metrics Data `json:"metrics"`
}
// Server represents server data
type Server struct {
ID string `json:"id"`
Name string `json:"name"`
IP string `json:"ip"`
}
// ServerRepository defines the behaviour of the server repository
type ServerRepository interface {
// GetServers returns the complete list of registered servers
GetServers() ([]Server, error)
// RegisterServer returns a JWT or an error
RegisterServer(server Server, jwtSecret string) (string, error)
// RevokeServer revokes a server token
RevokeServer(id string) error
// GetServer returns the server associated to the given id, if it is registered
GetServer(id string) (*Server, error)
}
// MetricRepository defines the behaviour of the metric repository
type MetricRepository interface {
Get(serverID string) (*Data, error)
Store(serverID string, data Data) error
}
// AdminUserRepository defines the behaviour of the admin user repository
type AdminUserRepository interface {
IsSetup() (bool, error)
Login(username string, password string) (bool, error)
GetUsers() ([]string, error)
Create(username string, password string) error
Delete(username string) error
}
// WatcherData represents data needed by watchers
type WatcherData struct {
Server Server
Metrics Data
}
// Alert represents data for sending alert
type Alert struct {
IssueTitle string
Server Server
Level ThresholdLevel
}
// ThresholdLevel represents a level of threshold
type ThresholdLevel int
const (
// None represents that everything is OK
None ThresholdLevel = 0
// Warning represents the warning threshold
Warning ThresholdLevel = 1
// Critical represents the critical threshold
Critical ThresholdLevel = 2
)
// Label returns a label representing the level
func (l ThresholdLevel) Label() string {
switch l {
case Critical:
return "Critical"
case Warning:
return "Warning"
default:
return ""
}
}
// WatcherKey represents a key to identify a watcher
type WatcherKey string
// Watcher defines the behaviour for watching metrics data
type Watcher interface {
GetKey() WatcherKey
Watch(data WatcherData)
}