Is it possible to set a different slack channels f...
# ask-elementary-ai
o
Is it possible to set a different slack channels for various custom dbt tests where elementary would sent alert?
k
A message from kapa.ai
Yes, Elementary Data allows you to set different Slack channels for various custom dbt tests. There are several ways to configure this: ### Custom Slack Channels at Different Levels You can configure custom Slack channels at different levels in your dbt project: 1. Test Level: You can set a custom channel directly in the test configuration 2. Model Level: You can set a channel for a model, and all tests associated with that model will use that channel 3. Project Level: You can set default channels at the project level in your dbt_project.yml According to the documentation, if you configure a custom Slack channel for both a model and a test, the test channel overrides the model channel [Alerts Configuration](https://docs.elementary-data.com/guides/alerts-configuration#custom-channel). ### Configuration Examples Here's how you can configure custom channels in your dbt_project.yml:
Copy code
yaml models:   finance:     +meta:       channel: finance_data_ops   marketing:     +meta:       channel: marketing_data_ops
Or specifically for tests:
Copy code
yaml tests:   finance:     +meta:       channel: finance_data_ops   marketing:     +meta:       channel: marketing_data_ops
You can also configure channels at the model level with tags and then use selectors:
Copy code
edr monitor --select tag:finance --slack-channel-name finance_data_ops edr monitor --select tag:marketing --slack-channel-name marketing_data_ops
### Important Notes 1. You need to make sure the Elementary app is added to all the Slack channels you want to send alerts to. 2. When using custom channels, you still need to specify a default channel with
--slack-channel-name
for alerts that don't match any specific channel configuration. 3. Currently, Elementary doesn't support sending a single alert to multiple Slack channels simultaneously. If you're looking to differentiate between environments (dev/prod), you can use Jinja templating in your channel configuration:
Copy code
yaml meta:   alerts_config:     channel: "{{ 'prod-alerts' if target.name == 'prod' else 'dev-alerts' }}"
o
@kapa.ai So if i have a default channel in the —slack-channel-name and a different channel in the dbt singular test config, the channel in the dbt singular test config will overrride the default channel? Also give me example of such test config
k
A message from kapa.ai
Yes, that's correct. If you specify a custom channel in a singular test config, it will override the default channel specified in the
--slack-channel-name
parameter of the
edr monitor
command. Here's an example of how to configure a custom Slack channel in a singular test:
Copy code
sql {{ config(     severity = 'error',     meta = {         'channel': 'custom-test-alerts'     } ) }}  -- Your test SQL query here
However, there's an important step to make this work properly. After configuring your test, you need to run the following commands to ensure Elementary picks up your custom channel configuration: 1.
dbt run --select dbt_tests dbt_models
(to update Elementary's metadata tables with your new configuration) 2.
dbt test --select <your_singular_test>
(to run your test) 3.
edr monitor ...
(to send alerts) This is necessary because Elementary needs to reload your updated test configuration so it can be used properly by the
edr
command [Slack forum user question](https://slack.com/archives/C02CTC89LAX/p1663081786725149). Also note that if you have an
alerts_config
section at the test level without a channel, it will override any channel configuration at the model level. Elementary doesn't currently merge configurations from different hierarchies - the more granular level simply overrides the upper levels [Slack forum user question](https://slack.com/archives/C02CTC89LAX/p1675932347555719). The configuration hierarchy from least to most specific is: - edr command channel (default) - dbt_project.yml alerts config - specific model alerts config - specific test alerts config The more granular definition always overrides the less granular one. I hope this helps clarify how custom channel configuration works with Elementary Data! Is there anything else you'd like to know about configuring alerts in Elementary?