Normally to test Alertmanager templates you need to restart running Alertmanager and wait for alerts to arrive to Slack or email. To speed up this process parts of templates could be rendered locally using predefined alerts data without the need of the actual Alertmanager.
What you still need in this case is amtool
which is a part of Alertmanager delivery which could be downloaded here https://github.com/prometheus/alertmanager/releases
Some examples of templates rendering:
# navigate to the templates dir
cd path/to/alertmanager/templates
# run render for the email alert {{ template "email.custom.html" . }} template
amtool template render --template.glob='*.tmpl' --template.data=data.json --template.text='{{ template "email.custom.html" . }}'
# run render for the Slack alert title {{ template "slack.custom.title" . }} template
amtool template render --template.glob='*.tmpl' --template.data=data.json --template.text='{{ template "slack.custom.title" . }}'; echo
# run render for the Slack alert color {{ template "slack.custom.color" . }} template
amtool template render --template.glob='*.tmpl' --template.data=data.json --template.text='{{ template "slack.custom.color" . }}'; echo
# run render for the Slack alert text {{ template "slack.custom.text" . }} template
amtool template render --template.glob='*.tmpl' --template.data=data.json --template.text='{{ template "slack.custom.text" . }}'; echo
Sample alerts data lives in the data.json
attached and could be modified as per you needs. This alert data is used only by amtool
like in the examples above and does not impact runtime behaviour of the Alertmanager.