File tree Expand file tree Collapse file tree
lung_cancer_screening/questions/management/commands Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -74,6 +74,7 @@ module "scheduled_jobs" {
7474 )
7575 secret_variables = merge (
7676 # { APPLICATIONINSIGHTS_CONNECTION_STRING = var.app_insights_connection_string },
77+ { SLACK_WEBHOOK_URL = var.slack_webhook_url },
7778 var. deploy_database_as_container ? { DATABASE_PASSWORD = resource.random_password.admin_password[0 ].result } : {}
7879 )
7980
Original file line number Diff line number Diff line change @@ -196,6 +196,11 @@ variable "infra_key_vault_rg" {
196196 type = string
197197}
198198
199+ variable "slack_webhook_url" {
200+ description = " slack_webhook_url is the URL used to send alerts to Slack. It should be stored as a secret in the infra key vault with the name 'slack-webhook-url'."
201+ type = string
202+ }
203+
199204locals {
200205 resource_group_name = " rg-${ var . app_short_name } -${ var . environment } -container-app-uks"
201206
Original file line number Diff line number Diff line change @@ -21,8 +21,3 @@ data "azurerm_key_vault_secret" "infra" {
2121 name = " monitoring-email-address"
2222 key_vault_id = data. azurerm_key_vault . infra . id
2323}
24-
25- data "azurerm_key_vault_secret" "slack_webhook_url" {
26- name = " slack-webhook-url"
27- key_vault_id = data. azurerm_key_vault . infra . id
28- }
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ module "logic_app_slack_alert" {
66 name = " logic-${ var . app_short_name } -${ var . environment } -slack-alerts"
77 resource_group_name = azurerm_resource_group. main . name
88 location = var. region
9- slack_webhook_url = data . azurerm_key_vault_secret . slack_webhook_url . value
9+ slack_webhook_url = var . slack_webhook_url
1010}
1111
1212resource "azurerm_monitor_action_group" "slack" {
Original file line number Diff line number Diff line change @@ -73,6 +73,11 @@ variable "enable_alerting" {
7373 type = bool
7474}
7575
76+ variable "slack_webhook_url" {
77+ description = " slack_webhook_url is the URL used to send alerts to Slack. It should be stored as a secret in the infra key vault with the name 'slack-webhook-url'."
78+ type = string
79+ }
80+
7681locals {
7782 hub_vnet_rg_name = " rg-hub-${ var . hub } -uks-bootstrap"
7883 hub_vnet_name = " vnet-hub-${ var . hub } -uks"
Original file line number Diff line number Diff line change @@ -49,3 +49,17 @@ data "azurerm_application_insights" "app_insights" {
4949 name = " appi-${ var . env_config } -uks-${ var . app_short_name } "
5050 resource_group_name = local. resource_group_name
5151}
52+
53+ data "azurerm_key_vault" "infra" {
54+ provider = azurerm. hub
55+
56+ name = local. infra_key_vault_name
57+ resource_group_name = local. infra_key_vault_rg
58+ }
59+
60+ data "azurerm_key_vault_secret" "slack_webhook_url" {
61+ name = " slack-webhook-url"
62+ key_vault_id = data. azurerm_key_vault . infra . id
63+ }
64+
65+ # git-sha-a85180497c23d742b5f92262b3b43069e44a4110
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ module "infra" {
2222 vnet_address_space = var. vnet_address_space
2323 cae_zone_redundancy_enabled = var. cae_zone_redundancy_enabled
2424 enable_alerting = var. enable_alerting
25+ slack_webhook_url = data. azurerm_key_vault_secret . slack_webhook_url . value
2526}
2627
2728module "container-apps" {
@@ -69,4 +70,5 @@ module "container-apps" {
6970 use_apex_domain = var. use_apex_domain
7071 container_memory = var. container_memory
7172 min_replicas = var. min_replicas
73+ slack_webhook_url = data. azurerm_key_vault_secret . slack_webhook_url . value
7274}
Original file line number Diff line number Diff line change 1+ import json
12import logging
3+ import os
24
5+ import requests
36from django .core .management .base import BaseCommand , CommandError
47from lung_cancer_screening .questions .services .request_summary import RequestSummary
58
@@ -9,13 +12,33 @@ class Command(BaseCommand):
912 help = "Counts the number of submitted requests."
1013
1114 def handle (self , * args , ** options ):
12- logger .info ("Command: SubmittedCount." )
15+
16+ logger .info ("Command: Request Summary." )
1317 try :
1418 rs = RequestSummary ()
1519 summary = rs .get_summary ()
1620
1721 self .stdout .write (str (summary ))
1822
23+ slack_webhook_url = os .environ .get ("SLACK_WEBHOOK_URL" )
24+
25+ if not slack_webhook_url :
26+ logger .warning ("SLACK_WEBHOOK_URL is not set; skipping Slack notification." )
27+ return
28+
29+ payload = {
30+ "text" : f"*Request summary*\n ```{ json .dumps (summary , indent = 2 , default = str )} ```"
31+ }
32+
33+ response = requests .post (
34+ slack_webhook_url ,
35+ json = payload ,
36+ timeout = 10 ,
37+ )
38+ response .raise_for_status ()
39+
40+ logger .info ("Request summary sent to Slack." )
41+
1942 except Exception as e :
2043 logger .error (e , exc_info = True )
2144 raise CommandError (e )
You can’t perform that action at this time.
0 commit comments