-
Notifications
You must be signed in to change notification settings - Fork 291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve template to handle empty group labels #2794
Changes from 1 commit
e3aa573
9ec37c8
eef67a4
d38434a
5f5a92e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,26 +22,27 @@ | |
|
||
# Web | ||
web_title = """\ | ||
{%- set groupLabels = payload.groupLabels.copy() -%} | ||
{%- set alertname = groupLabels.pop('alertname') | default("") -%} | ||
{%- set groupLabels = payload.get("groupLabels", {}).copy() -%} | ||
{%- set alertname = groupLabels.pop('alertname', "") -%} | ||
|
||
|
||
[{{ payload.status }}{% if payload.status == 'firing' %}:{{ payload.numFiring }}{% endif %}] {{ alertname }} {% if groupLabels | length > 0 %}({{ groupLabels|join(", ") }}){% endif %} | ||
""" # noqa | ||
[{{ payload.status }}{% if payload.status == 'firing' and payload.numFiring %}:{{ payload.numFiring }}{% endif %}] {{ alertname }} {% if groupLabels | length > 0 %}({{ groupLabels|join(", ") }}){% endif %}""" # noqa | ||
|
||
web_message = """\ | ||
{%- set annotations = payload.commonAnnotations.copy() -%} | ||
{%- set annotations = payload.get("commonAnnotations", {}).copy() -%} | ||
{%- set groupLabels = payload.get("groupLabels", {}) -%} | ||
{%- set commonLabels = payload.get("commonLabels", {}) -%} | ||
{%- set severity = groupLabels.severity -%} | ||
|
||
{% set severity = payload.groupLabels.severity -%} | ||
{% if severity %} | ||
{%- set severity_emoji = {"critical": ":rotating_light:", "warning": ":warning:" }[severity] | default(":question:") -%} | ||
Severity: {{ severity }} {{ severity_emoji }} | ||
{% endif %} | ||
|
||
{%- set status = payload.status | default("Unknown") %} | ||
{%- set status = payload.get("status", "Unknown") %} | ||
{%- set status_emoji = {"firing": ":fire:", "resolved": ":white_check_mark:"}[status] | default(":warning:") %} | ||
Status: {{ status }} {{ status_emoji }} (on the source) | ||
{% if status == "firing" %} | ||
{% if status == "firing" and payload.numFiring %} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we add check for numResolved? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm checking the numFiring here to not to render empty ':', since alerts from migrated legacy alertmanager have no numFiring field. I'm still thinking how to do it better. |
||
Firing alerts – {{ payload.numFiring }} | ||
Resolved alerts – {{ payload.numResolved }} | ||
{% endif %} | ||
|
@@ -56,12 +57,14 @@ | |
{%- set _ = annotations.pop('runbook_url_internal') -%} | ||
{%- endif %} | ||
|
||
{% if groupLabels | length > 0 -%} | ||
GroupLabels: | ||
{%- for k, v in payload["groupLabels"].items() %} | ||
{%- for k, v in groupLabels.items() %} | ||
- {{ k }}: {{ v }} | ||
{%- endfor %} | ||
{% endif %} | ||
|
||
{% if payload["commonLabels"] | length > 0 -%} | ||
{% if commonLabels | length > 0 -%} | ||
CommonLabels: | ||
{%- for k, v in payload["commonLabels"].items() %} | ||
- {{ k }}: {{ v }} | ||
|
@@ -82,7 +85,7 @@ | |
# Slack | ||
slack_title = """\ | ||
{%- set groupLabels = payload.groupLabels.copy() -%} | ||
{%- set alertname = groupLabels.pop('alertname') | default("") -%} | ||
{%- set alertname = groupLabels.pop('alertname', "") -%} | ||
*<{{ grafana_oncall_link }}|#{{ grafana_oncall_incident_id }} {{ web_title }}>* via {{ integration_name }} | ||
{% if source_link %} | ||
(*<{{ source_link }}|source>*) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just curious, what is the difference here? I think previous version is more straightforward and clear for non-python developers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just aligned it with other
.get
usages. ( It was used in previous templates also)