Skip to content

Commit a25fd86

Browse files
authored
Merge pull request #5554 from raft-tech/5498-alermanager-chat-integration
Integrate PLG with Mattermost
2 parents 7f61b89 + a1463dd commit a25fd86

File tree

2 files changed

+30
-21
lines changed

2 files changed

+30
-21
lines changed

tdrs-backend/plg/alertmanager/alertmanager.yml

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,30 @@ global:
44
smtp_from: 'no-reply@tanfdata.acf.hhs.gov'
55
smtp_auth_username: 'apikey'
66
smtp_auth_password: '{{ sendgrid_api_key }}'
7-
7+
slack_api_url: '{{ mattermost_web_hook_url }}'
88
# The directory from which notification templates are read.
99
templates:
1010
- '/etc/alertmanager/template/*.tmpl'
11-
1211
# The root route on which each incoming alert enters.
1312
route:
1413
# The labels by which incoming alerts are grouped together. For example,
1514
# multiple alerts coming in for cluster=A and alertname=LatencyHigh would
1615
# be batched into a single group.
1716
group_by: ['alertname', 'env', 'service']
18-
1917
# When a new group of alerts is created by an incoming alert, wait at
2018
# least 'group_wait' to send the initial notification.
2119
# This way ensures that you get multiple alerts for the same group that start
2220
# firing shortly after another are batched together on the first
2321
# notification.
2422
group_wait: 30s
25-
2623
# When the first notification was sent, wait 'group_interval' to send a batch
2724
# of new alerts that started firing for that group.
2825
group_interval: 5m
29-
3026
# If an alert has successfully been sent, wait 'repeat_interval' to
3127
# resend them.
3228
repeat_interval: 5m
33-
3429
# A default receiver
35-
receiver: admin-team-emails
36-
30+
receiver: mattermost
3731
# All the above attributes are inherited by all child routes and can
3832
# overwritten on each.
3933

@@ -44,18 +38,20 @@ route:
4438
- alertname=~"UpTime"
4539
receiver: dev-team-emails
4640
repeat_interval: 24h
47-
48-
# Send all severity CRITICAL/ERROR alerts to OFA admins
41+
# Send all severity CRITICAL/ERROR alerts to OFA admin emails
4942
- matchers:
50-
- severity=~"ERROR|CRITICAL"
43+
- severity=~"ERROR|CRITICAL"
5144
receiver: admin-team-emails
5245
continue: true
53-
# Send all severity CRITICAL/ERROR/WARNING alerts to TDP Devs
46+
# Send all severity CRITICAL/ERROR/WARNING alerts to mattermost and dev team emails
47+
- matchers:
48+
- severity=~"ERROR|CRITICAL|WARNING"
49+
receiver: mattermost
50+
continue: true
5451
- matchers:
55-
- severity=~"ERROR|CRITICAL|WARNING"
52+
- severity=~"ERROR|CRITICAL|WARNING"
5653
receiver: dev-team-emails
5754
continue: true
58-
5955
# Inhibition rules allow to mute a set of alerts given that another alert is
6056
# firing.
6157
# We use this to mute any warning-level notifications if the same alert is
@@ -69,22 +65,34 @@ inhibit_rules:
6965
# from both the source and target alerts,
7066
# the inhibition rule will apply!
7167
equal: [alertname, env, service]
72-
73-
- source_matchers: [alertname=~"LocalBackendDown|DevEnvironmentBackendDown|
74-
StagingBackendDown|ProductionBackendDown"]
68+
- source_matchers: [alertname=~"LocalBackendDown|DevEnvironmentBackendDown| StagingBackendDown|ProductionBackendDown"]
7569
target_match:
7670
alertname: 'UpTime'
7771
equal: ['environment', 'service']
78-
79-
80-
8172
receivers:
8273
- name: 'admin-team-emails'
8374
email_configs:
8475
- to: '{{ admin_team_emails }}'
8576
send_resolved: true
86-
8777
- name: 'dev-team-emails'
8878
email_configs:
8979
- to: '{{ dev_team_emails }}'
9080
send_resolved: true
81+
- name: 'mattermost'
82+
slack_configs:
83+
- channel: 'guest-ofa-tdp-alerts'
84+
username: 'alertmanager'
85+
send_resolved: true
86+
text: |-
87+
{{ range .Alerts -}}
88+
{{ if or (eq .Labels.severity "CRITICAL") (eq .Labels.severity "ERROR") }}
89+
@here
90+
{{ end }}
91+
*Alert:* {{ .Annotations.title }}{{ if .Labels.severity }} - `{{ .Labels.severity }}`{{ end }}
92+
93+
*Description:* {{ .Annotations.description }}
94+
95+
*Details:*
96+
{{ range .Labels.SortedPairs }} • *{{ .Name }}:* `{{ .Value }}`
97+
{{ end }}
98+
{{ end }}

tdrs-backend/plg/deploy.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ deploy_alertmanager() {
102102
cp alertmanager.yml $CONFIG
103103
SENDGRID_API_KEY=$(cf env tdp-backend-prod | grep SENDGRID | cut -d " " -f2-)
104104
yq eval -i ".global.smtp_auth_password = \"$SENDGRID_API_KEY\"" $CONFIG
105+
yq eval -i ".global.slack_api_url = \"$MATTERMOST_WEBHOOK_URL\"" $CONFIG
105106
yq eval -i ".receivers[0].email_configs[0].to = \"${ADMIN_EMAILS}\"" $CONFIG
106107
yq eval -i ".receivers[1].email_configs[0].to = \"${DEV_EMAILS}\"" $CONFIG
107108
cf push --no-route -f manifest.yml -t 180 --strategy rolling

0 commit comments

Comments
 (0)