-
Notifications
You must be signed in to change notification settings - Fork 116
/
action.go
53 lines (44 loc) · 1.16 KB
/
action.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 alerts
// Action is something that runs for an alerts manager.
type Action interface {
Run(manager Manager) error
}
// ActionType defines categories of actions.
type ActionType int
// ActionType constants
const (
// Deletes alert entries.
deleteAction ActionType = iota
// Alerts get marked for deletion.
clearAction
// Custom user action.
CustomAction
)
// action implements Action interface.
type action struct {
action ActionType
filters []Filter
f func(manager Manager, filter ...Filter) error
}
func (a *action) Run(manager Manager) error {
return a.f(manager, a.filters...)
}
func deleteActionFunc(manager Manager, filters ...Filter) error {
return manager.Delete(filters...)
}
// clearActionFunc first enumerates, then changes Cleared flag to true,
// then updates it.
// Raise method determines if ttlOption needs to be applied based on clear flag.
func clearActionFunc(manager Manager, filters ...Filter) error {
myAlerts, err := manager.Enumerate(filters...)
if err != nil {
return err
}
for _, myAlert := range myAlerts {
myAlert.Cleared = true
if err := manager.Raise(myAlert); err != nil {
return err
}
}
return nil
}