This repository was archived by the owner on May 12, 2026. It is now read-only.
Alert Resource Costs #717
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Alert Resource Costs | |
| on: | |
| schedule: | |
| - cron: '0 19 * * *' # Run daily at 7:00 PM UTC/3:00 PM EST | |
| env: | |
| ALERT_THRESHOLD: 60 | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| AZURE_CREDENTIALS: '{"clientId":"${{ secrets.REPO_AZURE_CLIENT_ID }}","clientSecret":"${{ secrets.REPO_AZURE_CLIENT_SECRET }}","subscriptionId":"${{ secrets.REPO_AZURE_SUBSCRIPTION_ID }}","tenantId":"${{ secrets.REPO_AZURE_TENANT_ID }}"}' | |
| jobs: | |
| alert_costs: | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| rg: [test] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check out changes | |
| uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 | |
| - name: Login into Azure | |
| uses: ./.github/actions/vpn-azure | |
| with: | |
| sp-creds: ${{ env.AZURE_CREDENTIALS }} | |
| - name: Run Az Cost CLI | |
| id: az-cost | |
| uses: ./.github/actions/az-cost | |
| with: | |
| rg: ${{ matrix.rg }} | |
| days_ago: 1 | |
| total_format: summary | |
| - name: Get Last Pusher and Last Change Date | |
| id: last-pusher | |
| run: | | |
| branch_name=$(echo "${{ matrix.rg }}" | sed 's/prime-data-hub-//') | |
| last_pusher=$(gh api repos/CDCgov/prime-reportstream/commits/$branch_name --jq '.author.login') | |
| last_change_date=$(gh api repos/CDCgov/prime-reportstream/commits/$branch_name --jq '.commit.author.date') | |
| echo "username=$last_pusher" >> $GITHUB_OUTPUT | |
| echo "last_change_date=$last_change_date" >> $GITHUB_OUTPUT | |
| - name: Check Environment Age | |
| id: env-age | |
| run: | | |
| current_date=$(date +%s) | |
| last_change_date=$(date -d "${{ steps.last-pusher.outputs.last_change_date }}" +%s) | |
| age_in_days=$(( (current_date - last_change_date) / 86400 )) | |
| echo "age_in_days=$age_in_days" >> $GITHUB_OUTPUT | |
| - name: Slack Notification | |
| if: ${{ fromJSON(steps.az-cost.outputs.result) > fromJSON(env.ALERT_THRESHOLD) && fromJSON(steps.env-age.outputs.age_in_days) > 2 }} | |
| uses: ./.github/actions/notifications | |
| with: | |
| method: slack | |
| title: Azure Costs | |
| message: | | |
| Resource Group \`${{ matrix.rg }}\` is exceeding the cost threshold and is ${{ steps.env-age.outputs.age_in_days }} days old. | |
| If still running and no longer needed, please [destroy](https://github.com/CDCgov/prime-reportstream/actions/workflows/destroy_demo_environment.yml). | |
| * **Cost per day: 💲${{ steps.az-cost.outputs.result }}** | |
| * **Provisioned by: \`${{ steps.last-pusher.outputs.username }}\`** | |
| * **Last Change Date: \`${{ steps.last-pusher.outputs.last_change_date }}\`** | |
| icon-emoji: ':money_with_wings:' | |
| channel: cdc-reportstream-bot-notifications | |
| webhook-url: ${{ secrets.SLACK_WEBHOOK_URL_NAVA_BOT_NOTIFICATIONS_CHANNEL }} | |
| color: failure | |
| slackify-markdown: true |