generated from ministryofjustice/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5473 from ministryofjustice/feature/op-alerting
📟 Observability Platform Slack alerting
- Loading branch information
Showing
8 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
builds | ||
contrib/*.json |
57 changes: 57 additions & 0 deletions
57
terraform/environments/observability-platform/contrib/delete-contact-point.sh
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Contact Points and the Notification Policy Tree are tightly coupled, and you cannot delete a Contact Point without first removing it from the Notification Policy Tree. | ||
# This script will delete a Contact Point from the Notification Policy Tree and then delete the Contact Point itself. | ||
# To run this script, you will need to provide the following arguments: | ||
# 1. The stage you are working in (e.g. development, production) | ||
# 2. The name of the Contact Point you want to delete (e.g. xxx-slack, yyy-pagerduty) | ||
# Example usage: bash contrib/delete-contact-point.sh development xxx-slack | ||
|
||
ENVIRONMENT=$(basename ${PWD}) | ||
STAGE="${1}" | ||
ROLE="modernisation-platform-developer" | ||
CONTACT_POINT="${2}" | ||
|
||
GRAFANA_API_KEY="$(aws-sso exec --profile ${ENVIRONMENT}-${STAGE}:${ROLE} -- aws secretsmanager get-secret-value --secret-id grafana/api-key --query SecretString --output text)" | ||
GRAFANA_WORKSPACE_ID="$(aws-sso exec --profile ${ENVIRONMENT}-${STAGE}:${ROLE} -- aws grafana list-workspaces | jq -r '.workspaces[] | select(.name=="observability-platform") | .id')" | ||
GRAFANA_ENDPOINT="https://${GRAFANA_WORKSPACE_ID}.grafana-workspace.eu-west-2.amazonaws.com" | ||
|
||
# Get Notification Policy Tree | ||
curl \ | ||
--silent \ | ||
--request GET \ | ||
--header "Accept: application/json" \ | ||
--header "Content-Type: application/json" \ | ||
--header "Authorization: Bearer ${GRAFANA_API_KEY}" \ | ||
--url "${GRAFANA_ENDPOINT}/api/v1/provisioning/policies" | jq > contrib/notification-policies-original.json | ||
|
||
# Delete Contact Point from Notification Policy Tree | ||
jq --arg CONTACT_POINT "${CONTACT_POINT}" 'del(.routes[] | select(.receiver==$CONTACT_POINT))' contrib/notification-policies-original.json > contrib/notification-policies-updated.json | ||
|
||
# Put modified Notification Policy Tree | ||
curl \ | ||
--silent \ | ||
--request PUT \ | ||
--header "Accept: application/json" \ | ||
--header "Content-Type: application/json" \ | ||
--header "Authorization: Bearer ${GRAFANA_API_KEY}" \ | ||
--data @contrib/notification-policies-updated.json \ | ||
--url "${GRAFANA_ENDPOINT}/api/v1/provisioning/policies" | ||
|
||
# Get Contact Point UID | ||
getContactPointUid=$(curl \ | ||
--silent \ | ||
--request GET \ | ||
--header "Accept: application/json" \ | ||
--header "Content-Type: application/json" \ | ||
--header "Authorization: Bearer ${GRAFANA_API_KEY}" \ | ||
--url "${GRAFANA_ENDPOINT}/api/v1/provisioning/contact-points" | jq -r --arg CONTACT_POINT "${CONTACT_POINT}" '.[] | select(.name==$CONTACT_POINT) | .uid') | ||
|
||
# Delete Contact Point | ||
curl \ | ||
--silent \ | ||
--request DELETE \ | ||
--header "Accept: application/json" \ | ||
--header "Content-Type: application/json" \ | ||
--header "Authorization: Bearer ${GRAFANA_API_KEY}" \ | ||
--url "${GRAFANA_ENDPOINT}/api/v1/provisioning/contact-points/${getContactPointUid}" |
This file contains 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
This file contains 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
This file contains 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
12 changes: 12 additions & 0 deletions
12
terraform/environments/observability-platform/modules/grafana/contact-point/slack/main.tf
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
data "aws_secretsmanager_secret_version" "github_token" { | ||
secret_id = "grafana/notifications/slack-token" | ||
} | ||
|
||
resource "grafana_contact_point" "this" { | ||
name = "${var.channel}-slack" | ||
|
||
slack { | ||
recipient = var.channel | ||
token = data.aws_secretsmanager_secret_version.github_token.secret_string | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...form/environments/observability-platform/modules/grafana/contact-point/slack/providers.tf
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
terraform { | ||
required_providers { | ||
grafana = { | ||
source = "grafana/grafana" | ||
version = "~> 2.0" | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...form/environments/observability-platform/modules/grafana/contact-point/slack/variables.tf
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
variable "channel" { | ||
type = string | ||
} |