Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

does else exist on datadog is_match

Tags:

datadog

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.

like image 471
Gayan Chathuranga Avatar asked Jul 24 '26 10:07

Gayan Chathuranga


2 Answers

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
like image 119
Steve Kehlet Avatar answered Jul 28 '26 13:07

Steve Kehlet


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.

like image 20
ziquan miao Avatar answered Jul 28 '26 13:07

ziquan miao



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!