Skip to content

Commit

Permalink
Merge pull request #182 from K-Phoen/alertmanager-templates
Browse files Browse the repository at this point in the history
feat: support definition of templates in alertmanager
  • Loading branch information
K-Phoen committed Jun 8, 2022
2 parents 092b4d3 + 7367dd1 commit 74810a5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions alertmanager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
15 changes: 15 additions & 0 deletions alertmanager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package alertmanager
import (
"testing"

"github.com/K-Phoen/sdk"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 74810a5

Please sign in to comment.