TL;DR: Targeting Datadog Slack Alerts to Different Channels By Environment
After we spent months with all of our Datadog alerts for both staging and production routed to a single slack #alerts
channel, we all got tired of looking in that room with urgency to see something happening in staging again. The team asked me to figure out how to create environment-specific alert channels, so here’s what I did.
The Documentation
The slack integration document includes a mention of using message template variables interpolation to dynamically create @-mentions
Best practices for tagging your infrastructure and applications is a long read on the virtues of adding tags (like team ownership) to infrastructure so those tags can be used in alerts.
TL;DR
Once you’ve set up a monitor with a Slack alert, you’ll see something like this in the message: @slack-Prefab_Internal-alerts
. That’s a hyphen delimited integration name, integration install name, and then the channel.
To target specific environments by the env
tag that’s usually available, edit the monitor’s message like this @slack-Prefab_Internal-alerts-{{env.name}}
. The drop-down box below the message won’t be helpful, but this works.
Then setup a slack channel like #alerts-production
.
You may also want to specify the “Multi Alert” aggregation options we chose.