Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions contrib/templates/sql-alert-trigger/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# SQL Alert Trigger

The 'sql-alert-trigger' project contains a databricks job and a Python notebook that connects to your **Jira** environment and creates an issue when run.

![Worklow UI example](images/sql-alert-workflow.png)

### Databricks Asset Bundle Template: Alert-Triggered Job

This template creates a job that:
1. Runs a SQL alert query
2. Checks if the alert was triggered
3. Executes a notebook if the condition is met

Common use case: Monitor data quality, send notifications, or trigger remediation


## Getting started

1. Install the Databricks CLI from https://docs.databricks.com/dev-tools/cli/install.html

2. Authenticate to your Databricks workspace (if you have not done so already):
```
$ databricks configure
```

3. Initialize this template in your environment

```
databricks bundle init https://github.com/databricks/bundle-examples --template-dir contrib/templates/sql-alert-trigger
```
You will be prompted to provide the following details to tailor the template to your preference:
- Project name
- SQL warehouse ID
- SQL alert ID

Ensure you update the Python notebook to include your Jira connection details.



4. To deploy a development copy of this project, type:
```
$ databricks bundle deploy --target dev
```
(Note that "dev" is the default target, so the `--target` parameter
is optional here.)

This deploys everything that's defined for this project.
For example, the default template would deploy a job called
`[dev yourname] Alert-Workflow` to your workspace.
You can find that job by opening your workpace and clicking on **Jobs & Pipelines**.

4. Similarly, to deploy a production copy, type:
```
$ databricks bundle deploy --target prod
```

5. To run a job, use the "run" command:
```
$ databricks bundle run
```

6. Optionally, install developer tools such as the Databricks extension for Visual Studio Code from
https://docs.databricks.com/dev-tools/vscode-ext.html.

7. For documentation on the Databricks Asset Bundles format used
for this project, and for CI/CD configuration, see
https://docs.databricks.com/dev-tools/bundles/index.html.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"welcome_message": "\nWelcome to the sql-trigger-app template for Databricks Asset Bundles!",
"properties": {

"project_name": {
"type": "string",
"default": "my_sql_alert_job",
"description": "Please provide the following details to tailor the template to your preferences.\n\nUnique name for this project\nproject_name",
"order": 1,
"pattern": "^[A-Za-z0-9_]+$",
"pattern_match_failure_message": "Name must consist of letters, numbers, and underscores."
},

"warehouse_id": {
"type": "string",
"description": "SQL Warehouse ID to run the alert query",
"order": 2
},
"alert_id": {
"type": "string",
"description": "ID of the existing SQL alert to execute",
"order": 3
}
},
"success_message": "\n\nYour new project has been created in the '{{.project_name}}' directory!"
}

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
bundle:
name: {{.project_name}}

include:
- resources/*.yml

# Variable declarations. These variables are assigned in the dev/prod targets below.
variables:
warehouse_id:
description: The warehouse to use
alert_id:
description: The ID of the SQL alert

targets:
dev:
# The default target uses 'mode: development' to create a development copy.
# - Deployed resources get prefixed with '[dev my_user_name]'
# - Any job schedules and triggers are paused by default.
# See also https://docs.databricks.com/dev-tools/bundles/deployment-modes.html.
mode: development
default: true
workspace:
host: {{workspace_host}}
variables:
warehouse_id: {{.warehouse_id}}
alert_id: {{.alert_id}}
prod:
mode: production
workspace:
host: {{workspace_host}}
# We explicitly specify /Workspace/Users/{{user_name}} to make sure we only have a single copy.
root_path: /Workspace/Users/{{user_name}}/.bundle/${bundle.name}/${bundle.target}
variables:
warehouse_id: 1234abcd
alert_id: abcd-1234-abcd

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

resources:
jobs:
alert_workflow_job:
name: Alert-Workflow
tasks:
# Task 1: SQL Alert Query
- task_key: sql_alert_check
email_notifications: {}
sql_task:
warehouse_id: ${var.warehouse_id}
alert:
subscriptions:
- user_name: {{user_name}} # dynamically retrieved
alert_id: ${var.alert_id}
webhook_notifications: {}
run_if: ALL_SUCCESS

# Task 2: Conditional Check
- task_key: condition
depends_on:
- task_key: sql_alert_check
webhook_notifications: {}
condition_task:
left: '{{ "{{" }}tasks.`sql_alert_check`.output.alert_state{{ "}}" }}'
op: EQUAL_TO
right: TRIGGERED
run_if: ALL_SUCCESS

# Task 3: Action Notebook
- task_key: trigger-action-notebook
depends_on:
- outcome: "true"
task_key: condition
notebook_task:
notebook_path: "../src/create_jira_issue.ipynb"
source: WORKSPACE
webhook_notifications: {}
run_if: ALL_SUCCESS

queue:
enabled: true
webhook_notifications: {}
Loading