cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Administration & Architecture
Explore discussions on Databricks administration, deployment strategies, and architectural best practices. Connect with administrators and architects to optimize your Databricks environment for performance, scalability, and security.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

How to make different notifications based on target for alert as part of bundle

rvm1975
New Contributor III

My task is to make alert notification for prod target to pagerduty and e-mail, rest targets e-mail only.

It is very easy for job or pipeline. In target you may define something like:

databricks.yml
targets:
  prod:
    resources:
      jobs:
        main:
          webhook_notifications:
            on_failure:
              - id: "${var.pagerduty_notification_id}"

But same approach does not work for alert. Alert requires 5 more fields like name etc despite they already defined in another "resources/some_file.alert.yml"

Using empty string raises error "Expected UUID, found".
Is there any way to do that ?
Thanks

1 ACCEPTED SOLUTION

Accepted Solutions

balajij8
Contributor III

You can follow the same approach of using swapping out the subscriptions (alert subscriptions) based on the target for the alerts. You can follow below & change the alert subscriptions based on targets

Target Prod
     alert_subscriptions:
        - user_email: 'rvm@mosr.com'
        - pager_destination_id: 'a18db8fa-36ed-46d9-a085-6c3517daf232'โ€‹โ€‹

Target Rest
    alert_subscriptions:
        - user_email: 'rvm@mosr.com'โ€‹

You can setup the alert as below. It stays completely target agnostic as it references the alert_subscriptions setup earlier

resources:
  alerts:
    aalerts:
      display_name: aalerts
      evaluation:
        comparison_operator: EQUAL
        source:
          name: '1'
        threshold:
          value:
            double_value: 2
        notification:
          notify_on_ok: false
          subscriptions: ${var.alert_subscriptions}
      query_text: select 2
      schedule:
        quartz_cron_schedule: '44 19 */1 * * ?'
        timezone_id: Europe/Amsterdam
      warehouse_id: 460a05ed

You can use below to find UUID

w = WorkspaceClient()
destinations = w.notification_destinations.list()

for dest in destinations:
    print(dest)

Ensure the alert file containing alerts details is included under include in the yml. Ensure the UUID is sent for the pager duty as above to avoid the error "Expected UUID, found"

View solution in original post

2 REPLIES 2

balajij8
Contributor III

You can follow the same approach of using swapping out the subscriptions (alert subscriptions) based on the target for the alerts. You can follow below & change the alert subscriptions based on targets

Target Prod
     alert_subscriptions:
        - user_email: 'rvm@mosr.com'
        - pager_destination_id: 'a18db8fa-36ed-46d9-a085-6c3517daf232'โ€‹โ€‹

Target Rest
    alert_subscriptions:
        - user_email: 'rvm@mosr.com'โ€‹

You can setup the alert as below. It stays completely target agnostic as it references the alert_subscriptions setup earlier

resources:
  alerts:
    aalerts:
      display_name: aalerts
      evaluation:
        comparison_operator: EQUAL
        source:
          name: '1'
        threshold:
          value:
            double_value: 2
        notification:
          notify_on_ok: false
          subscriptions: ${var.alert_subscriptions}
      query_text: select 2
      schedule:
        quartz_cron_schedule: '44 19 */1 * * ?'
        timezone_id: Europe/Amsterdam
      warehouse_id: 460a05ed

You can use below to find UUID

w = WorkspaceClient()
destinations = w.notification_destinations.list()

for dest in destinations:
    print(dest)

Ensure the alert file containing alerts details is included under include in the yml. Ensure the UUID is sent for the pager duty as above to avoid the error "Expected UUID, found"

rvm1975
New Contributor III

@balajij8 Thanks for the solution. Tested it and it's working. Totally forgot that variable can be list.