-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotifier.go
More file actions
47 lines (39 loc) · 1.04 KB
/
notifier.go
File metadata and controls
47 lines (39 loc) · 1.04 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
package manager
import "fmt"
import "crypto/sha1"
// Notifier defines methods required to notify alerts
type Notifier interface {
Notify(statement ProjectErrorStatement) error
}
// ProjectErrorStatement stores global error state for a project
type ProjectErrorStatement struct {
Project Project
Count int
Reasons map[RuleStateErrorType]string
MaxLevel AlertLevel
}
// GetUniqueID returns an ID representing the statement
func (stmt *ProjectErrorStatement) GetUniqueID() string {
str := fmt.Sprintf("n:%vc:%dr:%vl:%d", stmt.Project.Name, stmt.Count, stmt.Reasons, stmt.MaxLevel)
d := sha1.Sum([]byte(str))
return fmt.Sprintf("%x", d)
}
// AlertLevel represents a level of alert
type AlertLevel int
const (
// Warning is a level to catch attention, but with no impact of the process
Warning AlertLevel = iota
// Critic is a level sent when the issue requires an action
Critic
)
func (a *AlertLevel) String() string {
if a != nil {
switch *a {
case Critic:
return "critic"
case Warning:
return "warning"
}
}
return "ok"
}