I am trying to set up slack monitors with datadog, based on the environment. For e.g. if the environment is production got to slack channel A and if it is uat go to slack channel B and all other environments should go to slack channel C.
message = <<EOF
{{#is_match "environment.name" "production"}}
{{#is_alert}} @slack-datadog-production {{/is_alert}}
{{/is_match}}
{{#is_match "environment.name" "uat"}}
{{#is_alert}} @slack-datadog-uat {{/is_alert}}
{{/is_match}}
else
{{#is_alert}} @slack-datadog {{/is_alert}}
EOF
But I can't find a way to do the last part where all others should go to slack channel B. Looked at the documentation in https://docs.datadoghq.com/monitors/notifications and googled but couldn't find anything that can do an else condition.
Starts to get messy, but you could nest two "does not" conditional variables, like this:
message = <<EOF
{{#is_match "environment.name" "production"}}
{{#is_alert}} @slack-datadog-production {{/is_alert}}
{{/is_match}}
{{#is_match "environment.name" "uat"}}
{{#is_alert}} @slack-datadog-uat {{/is_alert}}
{{/is_match}}
{{^is_match "environment.name" "production"}}
{{^is_match "environment.name" "uat"}}
{{#is_alert}} @slack-datadog {{/is_alert}}
{{/is_match}}
{{/is_match}}
EOF
You can actually just use:
EOF
@slack-datadog-{{environment.name}}
EOF
Datadog's monitor templating feature will fill in the blank and forward to the relevant channel as long as you whitelisted it in the integrations tile for Slack.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With