diff --git a/alertmanager/manager.go b/alertmanager/manager.go index 4b1e654c..1b9f9c99 100644 --- a/alertmanager/manager.go +++ b/alertmanager/manager.go @@ -54,6 +54,15 @@ func DefaultContactPoint(contactPoint string) Option { } } +// Templates defines templates that can be used when sending messages to +// contact points. +// See https://prometheus.io/blog/2016/03/03/custom-alertmanager-templates/ +func Templates(templates map[string]string) Option { + return func(manager *Manager) { + manager.builder.TemplateFiles = templates + } +} + // Routing configures the routing policies to apply on alerts. func Routing(policies ...RoutingPolicy) Option { return func(manager *Manager) { diff --git a/alertmanager/manager_test.go b/alertmanager/manager_test.go index 77ff31a0..4e3438d2 100644 --- a/alertmanager/manager_test.go +++ b/alertmanager/manager_test.go @@ -3,6 +3,7 @@ package alertmanager import ( "testing" + "github.com/K-Phoen/sdk" "github.com/stretchr/testify/require" ) @@ -61,6 +62,20 @@ func TestRouting(t *testing.T) { req.Len(manager.builder.Config.Route.Routes, 1) } +func TestTemplates(t *testing.T) { + req := require.New(t) + + manager := New( + Templates(map[string]string{ + "custom_template": "lala", + }), + ) + + req.Equal(sdk.MessageTemplate{ + "custom_template": "lala", + }, manager.builder.TemplateFiles) +} + func TestMarshalJSON(t *testing.T) { req := require.New(t)