Merge ~jacekn/charm-prometheus-alertmanager:fixes into ~prometheus-charmers/charm-prometheus-alertmanager:master

Proposed by Jacek Nykis
Status: Merged
Merged at revision: ca499e551821bd682e35bdf336541724b3e08d09
Proposed branch: ~jacekn/charm-prometheus-alertmanager:fixes
Merge into: ~prometheus-charmers/charm-prometheus-alertmanager:master
Diff against target: 219 lines (+12/-124)
2 files modified
config.yaml (+0/-26)
templates/alertmanager.yml.j2 (+12/-98)
Reviewer Review Type Date Requested Status
JuanJo Ciarlante (community) lgtm Approve
Stuart Bishop (community) Approve
Review via email: mp+322458@code.launchpad.net

Description of the change

Remove redundant enable_* config options. Rework receivers config so that alerts go to all of them not just first one

To post a comment you must log in.
Revision history for this message
Stuart Bishop (stub) wrote :

Looks good to me. I'm not familiar with alertmanager config, but the changes appear sensible and are understandable.

review: Approve
Revision history for this message
JuanJo Ciarlante (jjo) :
review: Approve (lgtm)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/config.yaml b/config.yaml
2index 415ad67..04be6f7 100644
3--- a/config.yaml
4+++ b/config.yaml
5@@ -22,74 +22,48 @@ options:
6 It's templatized to accept the following vars: {private_address},
7 {public_address}, {port}, thus you can use e.g.:
8 juju set alertmanager external_url="http://{private_address}:{port}/"
9-
10 repeat_interval:
11 default: "30m"
12 type: string
13 description: |
14 If an alert has successfully been sent, wait 'repeat_interval' to
15 resend them.
16-
17 smtp_smarthost:
18 default: 'localhost:25'
19 type: string
20 description: "SMTP relay"
21-
22 smtp_from:
23 default: 'root@localhost'
24 type: string
25 description: "SMTP from"
26-
27 smtp_to:
28 default: 'root@localhost'
29 type: string
30 description: "Default email recipient for all alerts"
31-
32- enable_pagerduty:
33- default: False
34- type: boolean
35- description: "Enable PagerDuty notifications for critical alerts"
36-
37 pagerduty_url:
38 default: ""
39 type: string
40 description: "Override default, use default from alertmanager ( global.pagerduty_url) if unset"
41-
42 pagerduty_service_key:
43 type: string
44 description: "PagerDuty service key"
45 default: ""
46-
47- enable_slack:
48- default: False
49- type: boolean
50- description: "Enable Slack.com notifications for critical alerts, requires slack_api_url and slack_channel to be set"
51-
52 slack_api_url:
53 default: ""
54 type: string
55 description: "Your slack.com Webhook URL, see https://api.slack.com/incoming-webhooks (required)"
56-
57 slack_channel:
58 default: ""
59 type: string
60 description: "slack channel (required)"
61-
62- enable_webhook:
63- default: False
64- type: boolean
65- description: "Enable generic webhook receiver for critical alerts"
66-
67 webhook_url:
68 default: ""
69 type: string
70 description: "Your webhook url"
71-
72 extra_routes:
73 type: string
74 description: "YAML string containing a list of alertmanager 'routes' to add"
75 default: ""
76-
77 extra_receivers:
78 type: string
79 description: "YAML string containing a list of alertmanager 'receivers' to add"
80diff --git a/templates/alertmanager.yml.j2 b/templates/alertmanager.yml.j2
81index 7427e78..a79f1f3 100644
82--- a/templates/alertmanager.yml.j2
83+++ b/templates/alertmanager.yml.j2
84@@ -37,123 +37,37 @@ route:
85 # overwritten on each.
86
87 routes:
88-{%- if config.enable_pagerduty and config.pagerduty_service_key is defined %}
89- - match_re:
90- severity: critical|page
91- receiver: juju_pagerduty_receiver
92+{%- if config.pagerduty_service_key or config.slack_api_url or config.webhook_url or config.extra_receivers %}
93+ - receiver: juju_receiver
94 {% endif %}
95-{%- if config.enable_slack and config.slack_api_url is defined and config.slack_channel is defined %}
96- - match_re:
97- severity: critical|page
98- receiver: juju_slack_receiver
99-{% endif %}
100-{%- if config.enable_webhook and config.webhook_url is defined %}
101- - match_re:
102- severity: critical|page
103- receiver: juju_webhook_receiver
104-{% endif %}
105-{%- if config.extra_routes is defined %}
106+{%- if config.extra_routes %}
107 {{ config.extra_routes|indent(4) }}
108 {% endif %}
109
110-# # The child route trees.
111-# routes:
112-# # This routes performs a regular expression match on alert labels to
113-# # catch alerts that are related to a list of services.
114-# - match_re:
115-# service: ^(foo1|foo2|baz)$
116-# receiver: team-X-mails
117-#
118-# # The service has a sub-route for critical alerts, any alerts
119-# # that do not match, i.e. severity != critical, fall-back to the
120-# # parent node and are sent to 'team-X-mails'
121-# routes:
122-# - match:
123-# severity: critical
124-# receiver: team-X-pager
125-#
126-# - match:
127-# service: files
128-# receiver: team-Y-mails
129-#
130-# routes:
131-# - match:
132-# severity: critical
133-# receiver: team-Y-pager
134-#
135-# # This route handles all alerts coming from a database service. If there's
136-# # no team to handle it, it defaults to the DB team.
137-# - match:
138-# service: database
139-#
140-# receiver: team-DB-pager
141-# # Also group alerts by affected database.
142-# group_by: [alertname, cluster, database]
143-#
144-# routes:
145-# - match:
146-# owner: team-X
147-# receiver: team-X-pager
148-#
149-# - match:
150-# owner: team-Y
151-# receiver: team-Y-pager
152-
153-# Inhibition rules allow to mute a set of alerts given that another alert is
154-# firing.
155-# We use this to mute any warning-level notifications if the same alert is
156-# already critical.
157-inhibit_rules:
158-- source_match:
159- severity: 'critical'
160- target_match:
161- severity: 'warning'
162- # Apply inhibition if the alertname is the same.
163- equal: ['alertname']
164-
165-
166 receivers:
167 - name: 'default-email-recipient'
168 email_configs:
169 - to: '{{ config.smtp_to }}'
170-
171-{%- if config.enable_pagerduty and config.pagerduty_service_key is defined %}
172-- name: juju_pagerduty_receiver
173+{%- if config.pagerduty_service_key or config.slack_api_url or config.webhook_url or config.extra_receivers %}
174+- name: 'juju_receiver'
175+{%- if config.pagerduty_service_key %}
176 pagerduty_configs:
177 - service_key: '{{ config.pagerduty_service_key }}'
178 {%- if config.pagerduty_url %}
179- - url: '{{ config.pagerduty_url }}'
180+ url: '{{ config.pagerduty_url }}'
181 {% endif %}
182 {% endif %}
183-{%- if config.enable_slack and config.slack_api_url is defined and config.slack_channel is defined %}
184-- name: juju_slack_receiver
185+{%- if config.slack_api_url and config.slack_channel %}
186 slack_configs:
187 - api_url: '{{ config.slack_api_url }}'
188 channel: '{{ config.slack_channel }}'
189 {% endif %}
190-{%- if config.enable_webhook and config.webhook_url is defined %}
191-- name: juju_webhook_receiver
192+{%- if config.webhook_url %}
193 webhook_configs:
194 - url: '{{ config.webhook_url }}'
195 {% endif %}
196-{%- if config.extra_receivers is defined %}
197-{{ config.extra_receivers }}
198+{%- if config.extra_receivers %}
199+{{ config.extra_receivers|indent(2) }}
200+{% endif %}
201 {% endif %}
202
203-# - name: 'team-X-pager'
204-# email_configs:
205-# - to: 'team-X+alerts-critical@example.org'
206-# pagerduty_configs:
207-# - service_key: <team-X-key>
208-#
209-# - name: 'team-Y-mails'
210-# email_configs:
211-# - to: 'team-Y+alerts@example.org'
212-#
213-# - name: 'team-Y-pager'
214-# pagerduty_configs:
215-# - service_key: <team-Y-key>
216-#
217-# - name: 'team-DB-pager'
218-# pagerduty_configs:
219-# - service_key: <team-DB-key>

Subscribers

People subscribed via source and target branches