M README.md => README.md +2 -0
@@ 96,6 96,8 @@ alertmanager {
# When the alert-mode is set to single, ntfy-alertmanager will cache each single alert
# to avoid sending recurrences.
cache {
+ # The type of cache that will be used (default is memory).
+ type memory
# How long messages stay in the cache for
duration 24h
# Interval in which the cache is cleaned up
M config.go => config.go +23 -0
@@ 16,6 16,12 @@ const (
multi
)
+type cacheType int
+
+const (
+ memory cacheType = iota
+)
+
type config struct {
BaseURL string
HTTPAddress string
@@ 49,6 55,7 @@ type labelConfig struct {
}
type cacheConfig struct {
+ Type cacheType
CleanupInterval time.Duration
Duration time.Duration
}
@@ 77,6 84,7 @@ func readConfig(path string) (*config, error) {
config.LogLevel = "info"
config.alertMode = single
+ config.cache.Type = memory
config.cache.CleanupInterval = time.Hour
config.cache.Duration = time.Hour * 24
@@ 238,6 246,21 @@ func readConfig(path string) (*config, error) {
cacheDir := cfg.Get("cache")
if cacheDir != nil {
+ d = cacheDir.Children.Get("type")
+ if d != nil {
+ var cacheType string
+ if err := d.ParseParams(&cacheType); err != nil {
+ return nil, err
+ }
+
+ switch strings.ToLower(cacheType) {
+ case "memory":
+ config.cache.Type = memory
+ default:
+ return nil, fmt.Errorf("cache: illegal type %q", cacheType)
+ }
+ }
+
var durationString string
d = cacheDir.Children.Get("duration")
if d != nil {