-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathplugin.go
More file actions
57 lines (48 loc) · 1.32 KB
/
plugin.go
File metadata and controls
57 lines (48 loc) · 1.32 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
package plugin
import (
"time"
logging "github.com/ipfs/go-log/v2"
"github.com/filecoin-project/curio/deps/config"
)
var log = logging.Logger("curio/alertplugins")
type Plugin interface {
SendAlert(data *AlertPayload) error
}
type AlertPayload struct {
Summary string
Severity string
Source string
Details map[string]interface{}
Time time.Time
}
var TestPlugins []Plugin
func LoadAlertPlugins(cfg config.CurioAlertingConfig) *config.Dynamic[[]Plugin] {
pluginsDynamic := config.NewDynamic([]Plugin{})
collectPlugins := func() []Plugin {
var plugins []Plugin
if cfg.PagerDuty.Enable.Get() {
plugins = append(plugins, NewPagerDuty(cfg.PagerDuty))
}
if cfg.PrometheusAlertManager.Enable.Get() {
plugins = append(plugins, NewPrometheusAlertManager(cfg.PrometheusAlertManager))
}
if cfg.SlackWebhook.Enable.Get() {
plugins = append(plugins, NewSlackWebhook(cfg.SlackWebhook))
}
if len(TestPlugins) > 0 {
plugins = append(plugins, TestPlugins...)
}
return plugins
}
pluginsDynamic.Set(collectPlugins())
cfg.PagerDuty.Enable.OnChange(func() {
pluginsDynamic.Set(collectPlugins())
})
cfg.PrometheusAlertManager.Enable.OnChange(func() {
pluginsDynamic.Set(collectPlugins())
})
cfg.SlackWebhook.Enable.OnChange(func() {
pluginsDynamic.Set(collectPlugins())
})
return pluginsDynamic
}