M README.md => README.md +3 -0
@@ 29,6 29,9 @@ Example:
http-address :8080
# Log level (either debug, info, warning, error)
log-level info
+# When multiple alerts are grouped together by Alertmanager, they can either be sent
+# each on their own (single mode) or be kept together (multi mode) (either single or multi; default is single)
+alert-mode single
# Optionally protect with HTTP basic authentication
user webhookUser
password webhookPass
M config.go => config.go +28 -0
@@ 7,9 7,17 @@ import (
"git.sr.ht/~emersion/go-scfg"
)
+type alertMode int
+
+const (
+ single alertMode = iota
+ multi
+)
+
type config struct {
HTTPAddress string
LogLevel string
+ alertMode alertMode
User string
Password string
ntfy ntfyConfig
@@ 42,6 50,7 @@ func readConfig(path string) (*config, error) {
// Set default values
config.HTTPAddress = "127.0.0.1:8080"
config.LogLevel = "info"
+ config.alertMode = single
d := cfg.Get("log-level")
if d != nil {
@@ 57,6 66,25 @@ func readConfig(path string) (*config, error) {
}
}
+ d = cfg.Get("alert-mode")
+ if d != nil {
+ var mode string
+ if err := d.ParseParams(&mode); err != nil {
+ return nil, err
+ }
+
+ switch strings.ToLower(mode) {
+ case "single":
+ config.alertMode = single
+
+ case "multi":
+ config.alertMode = multi
+
+ default:
+ return nil, fmt.Errorf("%q directive: illegal mode %q", d.Name, mode)
+ }
+ }
+
d = cfg.Get("user")
if d != nil {
if err := d.ParseParams(&config.User); err != nil {
M config_test.go => config_test.go +4 -1
@@ 13,6 13,9 @@ func TestReadConfig(t *testing.T) {
http-address :8080
# Log level (either debug, info, warning, error)
log-level info
+# When multiple alerts are grouped together by Alertmanager, they can either be sent
+# each on their own (single mode) or be kept together (multi mode) (either single or multi; default is single)
+alert-mode multi
# Optionally protect with HTTP basic authentication
user webhookUser
password webhookPass
@@ 44,7 47,7 @@ ntfy {
`
expectedCfg := &config{
- HTTPAddress: ":8080", LogLevel: "info", User: "webhookUser", Password: "webhookPass",
+ HTTPAddress: ":8080", LogLevel: "info", alertMode: multi, User: "webhookUser", Password: "webhookPass",
ntfy: ntfyConfig{Topic: "https://ntfy.sh/alertmanager-alerts", User: "user", Password: "pass"},
labels: labels{Order: []string{"severity", "instance"},
Label: map[string]labelConfig{