diff --git a/.github/workflows/dbt_docs_update.yml b/.github/workflows/dbt_docs_update.yml index 736e7cc..7e886b2 100644 --- a/.github/workflows/dbt_docs_update.yml +++ b/.github/workflows/dbt_docs_update.yml @@ -71,3 +71,10 @@ jobs: - name: push changes to docs run: | git push -f --set-upstream origin docs + + notify-failure: + needs: [scheduled_run] + if: failure() + uses: ./.github/workflows/slack_notify.yml + secrets: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} diff --git a/.github/workflows/dbt_run_adhoc.yml b/.github/workflows/dbt_run_adhoc.yml index bd823b7..8d823d8 100644 --- a/.github/workflows/dbt_run_adhoc.yml +++ b/.github/workflows/dbt_run_adhoc.yml @@ -64,3 +64,10 @@ jobs: - name: Run DBT Jobs run: | ${{ inputs.dbt_command }} + +notify-failure: + needs: [run_dbt_jobs] + if: failure() + uses: ./.github/workflows/slack_notify.yml + secrets: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} diff --git a/.github/workflows/dbt_run_deployment.yml b/.github/workflows/dbt_run_deployment.yml index d904e0e..1739173 100644 --- a/.github/workflows/dbt_run_deployment.yml +++ b/.github/workflows/dbt_run_deployment.yml @@ -69,3 +69,10 @@ jobs: path: | logs target + +notify-failure: + needs: [dbt] + if: failure() + uses: ./.github/workflows/slack_notify.yml + secrets: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} diff --git a/.github/workflows/dbt_run_dev_refresh.yml b/.github/workflows/dbt_run_dev_refresh.yml index 0ca49a7..f4ae0f4 100644 --- a/.github/workflows/dbt_run_dev_refresh.yml +++ b/.github/workflows/dbt_run_dev_refresh.yml @@ -51,3 +51,10 @@ jobs: path: | logs target + +notify-failure: + needs: [dbt] + if: failure() + uses: ./.github/workflows/slack_notify.yml + secrets: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} diff --git a/.github/workflows/dbt_run_full_observability.yml b/.github/workflows/dbt_run_full_observability.yml index f501d90..067411e 100644 --- a/.github/workflows/dbt_run_full_observability.yml +++ b/.github/workflows/dbt_run_full_observability.yml @@ -4,7 +4,7 @@ run-name: dbt_run_full_observability on: workflow_dispatch: schedule: - # Runs “At 00:00 on day-of-month 1.” (see https://crontab.guru) + # Runs "At 00:00 on day-of-month 1." (see https://crontab.guru) - cron: "0 0 1 * *" env: @@ -45,3 +45,10 @@ jobs: - name: Run DBT Jobs run: | dbt run --threads 2 --vars '{"OBSERV_FULL_TEST":True}' -m tag:observability + +notify-failure: + needs: [run_dbt_jobs] + if: failure() + uses: ./.github/workflows/slack_notify.yml + secrets: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} diff --git a/.github/workflows/dbt_run_observability.yml b/.github/workflows/dbt_run_observability.yml index 5f5f5ea..75fba5b 100644 --- a/.github/workflows/dbt_run_observability.yml +++ b/.github/workflows/dbt_run_observability.yml @@ -45,3 +45,10 @@ jobs: - name: Run DBT Jobs run: | dbt run --threads 2 --vars '{"OBSERV_FULL_TEST":False}' -m tag:observability + +notify-failure: + needs: [run_dbt_jobs] + if: failure() + uses: ./.github/workflows/slack_notify.yml + secrets: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} diff --git a/.github/workflows/dbt_run_scheduled_core.yml b/.github/workflows/dbt_run_scheduled_core.yml index 746ee42..0392f8e 100644 --- a/.github/workflows/dbt_run_scheduled_core.yml +++ b/.github/workflows/dbt_run_scheduled_core.yml @@ -51,3 +51,10 @@ jobs: path: | logs target + +notify-failure: + needs: [dbt] + if: failure() + uses: ./.github/workflows/slack_notify.yml + secrets: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} diff --git a/.github/workflows/dbt_run_scheduled_non_core.yml b/.github/workflows/dbt_run_scheduled_non_core.yml index f2d6185..978905e 100644 --- a/.github/workflows/dbt_run_scheduled_non_core.yml +++ b/.github/workflows/dbt_run_scheduled_non_core.yml @@ -51,3 +51,10 @@ jobs: path: | logs target + +notify-failure: + needs: [dbt] + if: failure() + uses: ./.github/workflows/slack_notify.yml + secrets: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} diff --git a/.github/workflows/dbt_run_streamline_blocks_realtime.yml b/.github/workflows/dbt_run_streamline_blocks_realtime.yml index 59df9e8..4ea51e1 100644 --- a/.github/workflows/dbt_run_streamline_blocks_realtime.yml +++ b/.github/workflows/dbt_run_streamline_blocks_realtime.yml @@ -51,3 +51,10 @@ jobs: path: | logs target + +notify-failure: + needs: [dbt] + if: failure() + uses: ./.github/workflows/slack_notify.yml + secrets: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} diff --git a/.github/workflows/dbt_run_streamline_chunks_realtime.yml b/.github/workflows/dbt_run_streamline_chunks_realtime.yml index 6466b41..21b3b76 100644 --- a/.github/workflows/dbt_run_streamline_chunks_realtime.yml +++ b/.github/workflows/dbt_run_streamline_chunks_realtime.yml @@ -51,3 +51,10 @@ jobs: path: | logs target + +notify-failure: + needs: [dbt] + if: failure() + uses: ./.github/workflows/slack_notify.yml + secrets: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} diff --git a/.github/workflows/dbt_run_streamline_non_core_weekly.yml b/.github/workflows/dbt_run_streamline_non_core_weekly.yml index 9d48d3b..dc55f7c 100644 --- a/.github/workflows/dbt_run_streamline_non_core_weekly.yml +++ b/.github/workflows/dbt_run_streamline_non_core_weekly.yml @@ -51,3 +51,10 @@ jobs: path: | logs target + +notify-failure: + needs: [dbt] + if: failure() + uses: ./.github/workflows/slack_notify.yml + secrets: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} diff --git a/.github/workflows/dbt_run_streamline_transactions_realtime.yml b/.github/workflows/dbt_run_streamline_transactions_realtime.yml index 7a53974..2722024 100644 --- a/.github/workflows/dbt_run_streamline_transactions_realtime.yml +++ b/.github/workflows/dbt_run_streamline_transactions_realtime.yml @@ -51,3 +51,10 @@ jobs: path: | logs target + +notify-failure: + needs: [dbt] + if: failure() + uses: ./.github/workflows/slack_notify.yml + secrets: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} diff --git a/.github/workflows/dbt_test.yml b/.github/workflows/dbt_test.yml index c3466d2..bc494c1 100644 --- a/.github/workflows/dbt_test.yml +++ b/.github/workflows/dbt_test.yml @@ -49,3 +49,10 @@ jobs: - name: Log test results run: | python python_scripts/test_alert/dbt_test_alert.py + +notify-failure: + needs: [run_dbt_jobs] + if: failure() + uses: ./.github/workflows/slack_notify.yml + secrets: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} diff --git a/.github/workflows/slack_notify.yml b/.github/workflows/slack_notify.yml new file mode 100644 index 0000000..2dc6d14 --- /dev/null +++ b/.github/workflows/slack_notify.yml @@ -0,0 +1,27 @@ +name: Slack Notification +on: + workflow_call: + secrets: + SLACK_WEBHOOK_URL: + required: true + +jobs: + notify: + runs-on: ubuntu-latest + environment: workflow_prod + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.10" + + - name: Install dependencies + run: pip install requests + + - name: Send Slack notification + run: python python/slack_alert.py + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} diff --git a/python/slack_alert.py b/python/slack_alert.py new file mode 100644 index 0000000..c738857 --- /dev/null +++ b/python/slack_alert.py @@ -0,0 +1,74 @@ +import requests +import os +import sys + +def create_message(): + """Creates a simple failure notification message with repo, workflow name, and URL""" + + # Get GitHub environment variables + repository = os.environ.get('GITHUB_REPOSITORY', 'Unknown repository') + repo_name = repository.split('/')[-1] if '/' in repository else repository + workflow_name = os.environ.get('GITHUB_WORKFLOW', 'Unknown workflow') + run_id = os.environ.get('GITHUB_RUN_ID', '') + server_url = os.environ.get('GITHUB_SERVER_URL', 'https://github.com') + + # Build the workflow URL + workflow_url = f"{server_url}/{repository}/actions/runs/{run_id}" + + message_body = { + "text": f"Failure in {repo_name}", + "attachments": [ + { + "color": "#f44336", # Red color for failures + "fields": [ + { + "title": "Repository", + "value": repository, + "short": True + }, + { + "title": "Workflow", + "value": workflow_name, + "short": True + } + ], + "actions": [ + { + "type": "button", + "text": "View Workflow Run", + "style": "primary", + "url": workflow_url + } + ], + "footer": "GitHub Actions" + } + ] + } + + return message_body + +def send_alert(webhook_url): + """Sends a failure notification to Slack""" + + message = create_message() + + try: + response = requests.post(webhook_url, json=message) + + if response.status_code == 200: + print("Successfully sent Slack notification") + else: + print(f"Failed to send Slack notification: {response.status_code} {response.text}") + sys.exit(1) + except Exception as e: + print(f"Error sending Slack notification: {str(e)}") + sys.exit(1) + +if __name__ == '__main__': + webhook_url = os.environ.get("SLACK_WEBHOOK_URL") + + if not webhook_url: + print("ERROR: SLACK_WEBHOOK_URL environment variable is required") + sys.exit(1) + + send_alert(webhook_url)