Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add slack template
Browse files Browse the repository at this point in the history
swibrow committed Sep 23, 2024
1 parent 184827c commit 16586de
Showing 3 changed files with 40 additions and 57 deletions.
30 changes: 0 additions & 30 deletions files/helm/prometheus/alertmanager-template.yaml

This file was deleted.

65 changes: 39 additions & 26 deletions monitoring.tf
Original file line number Diff line number Diff line change
@@ -253,7 +253,7 @@ module "prometheus_stack" {
# https://github.com/prometheus-community/helm-charts/blob/main/charts/kube-prometheus-stack/values.yaml
values = [
file("${path.module}/files/helm/prometheus/common.yaml"),
file("${path.module}/files/helm/prometheus/alertmanager-template.yaml"),
file("${path.module}/files/helm/prometheus/alertmanager-templates.yaml"),
<<-EOT
prometheus:
serviceAccount:
@@ -320,6 +320,8 @@ module "prometheus_stack" {
- ${var.slack.kubernetes_secret_name}
%{endif}
config:
global:
slack_api_url: https://slack.com/api/chat.postMessage
route:
receiver: "null"
group_by: [...]
@@ -332,6 +334,12 @@ module "prometheus_stack" {
matchers:
- alertname="Watchdog"
continue: false
%{if var.enable_slack}
- receiver: it-pts-dai-monitoring
matchers:
- severity=~"info|warning|critical"
continue: true
%{endif}
%{if var.enable_pagerduty}
- receiver: pagerduty-critical
matchers:
@@ -346,14 +354,35 @@ module "prometheus_stack" {
- severity="info"
continue: false
%{endif}
%{if var.enable_slack}
- receiver: it-pts-dai-monitoring
matchers:
- severity=~"info|warning|critical"
continue: false
%{endif}
receivers:
- name: "null"
%{if var.enable_slack}
- name: it-pts-dai-monitoring
slack_configs:
- send_resolved: true
api_url_file: /etc/alertmanager/secrets/${var.slack.kubernetes_secret_name}/it_pts_dai_monitoring
http_config:
follow_redirects: true
enable_http2: true
color: '{{ template "slack.color" . }}'
title: '{{ template "slack.title" . }}'
text: '{{ template "slack.text" . }}'
channel: '#it_pts_dai_monitoring'
actions:
- type: button
text: 'Runbook :green_book:'
url: '{{ (index .Alerts 0).Annotations.runbook_url }}'
- type: button
text: 'Query :mag:'
url: '{{ (index .Alerts 0).GeneratorURL }}'
- type: button
text: 'Dashboard :chart_with_upwards_trend:'
url: '{{ (index .Alerts 0).Annotations.dashboard_url }}'
- type: button
text: 'Silence :no_bell:'
url: '{{ template "__alert_silence_link" . }}'
%{endif}
%{if var.enable_pagerduty}
- name: pagerduty-critical
pagerduty_configs:
@@ -365,7 +394,7 @@ module "prometheus_stack" {
url: https://events.pagerduty.com/v2/enqueue
client: '{{ template "pagerduty.default.client" . }}'
client_url: '{{ template "pagerduty.default.clientURL" . }}'
description: '{{ template "pagerduty.default.description" .}}'
description: '{{ template "pagerduty.default.description" . }}'
details:
alertname: '{{ .CommonLabels.alertname }}'
description: '{{ .CommonAnnotations.description }}'
@@ -387,7 +416,7 @@ module "prometheus_stack" {
url: https://events.pagerduty.com/v2/enqueue
client: '{{ template "pagerduty.default.client" . }}'
client_url: '{{ template "pagerduty.default.clientURL" . }}'
description: '{{ template "pagerduty.default.description" .}}'
description: '{{ template "pagerduty.default.description" . }}'
details:
alertname: '{{ .CommonLabels.alertname }}'
description: '{{ .CommonAnnotations.description }}'
@@ -409,7 +438,7 @@ module "prometheus_stack" {
url: https://events.pagerduty.com/v2/enqueue
client: '{{ template "pagerduty.default.client" . }}'
client_url: '{{ template "pagerduty.default.clientURL" . }}'
description: '{{ template "pagerduty.default.description" .}}'
description: '{{ template "pagerduty.default.description" . }}'
details:
alertname: '{{ .CommonLabels.alertname }}'
description: '{{ .CommonAnnotations.description }}'
@@ -422,22 +451,6 @@ module "prometheus_stack" {
source: '{{ template "pagerduty.default.client" . }}'
severity: info
%{endif}
%{if var.enable_slack}
- name: it-pts-dai-monitoring
slack_configs:
- send_resolved: true
api_url_file: /etc/alertmanager/secrets/${var.slack.kubernetes_secret_name}/it_pts_dai_monitoring
http_config:
follow_redirects: true
enable_http2: true
channel: '#it-pts-dai-monitoring'
title: '{{ template "slack.default.title" . }}'
text: '{{ template "slack.default.text" . }}'
footer: '{{ template "slack.default.footer" . }}'
icon_url: '{{ template "slack.default.iconURL" . }}'
username: '{{ template "slack.default.username" . }}'
color: '{{ template "slack.default.color" . }}'
%{endif}
EOT
]

2 changes: 1 addition & 1 deletion tests/main/main.tf
Original file line number Diff line number Diff line change
@@ -132,7 +132,7 @@ module "k8s_platform" {

enable_downscaler = true

enable_pagerduty = true
enable_pagerduty = false
pagerduty = {
secrets_manager_secret_name = "dai/platform/pagerduty"
}

0 comments on commit 16586de

Please sign in to comment.