fix(alerts): an alert on a count says how many of what, and names them (#6400)
"swarm services short on swarm is 6." becomes "6 swarm services are short of their replicas.", with a Which line naming each service and how many of its tasks run. The swarm figures get labels, and the counting figures (swarm, mounts, drives, updates) read as sentences in the email, its subject and the Alerts page. A plugin names what its count counts through core.alerts.names_behind; the Docker plugin does for the three swarm figures, from the stored swarm. Webhooks get alert.which too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -65,11 +65,13 @@ def render_webhook(template_str: str, alert: dict) -> str:
|
||||
|
||||
In the template, `alert.<field>` is escaped to sit inside a JSON string
|
||||
("{{ alert.rule_name }}" stays valid whatever the name holds), with a
|
||||
missing value reading "no data"; `raw.<field>` is the plain value for use
|
||||
with |tojson ({{ raw.value | tojson }} gives a number or null). The
|
||||
template runs sandboxed. ValueError says why a body could not be made.
|
||||
missing value reading "no data" and a list (`which`) its items joined by
|
||||
", "; `raw.<field>` is the plain value for use with |tojson
|
||||
({{ raw.value | tojson }} gives a number or null, {{ raw.which | tojson }}
|
||||
an array). The template runs sandboxed. ValueError says why a body could
|
||||
not be made.
|
||||
"""
|
||||
shown = dict(alert)
|
||||
shown = {k: ", ".join(map(str, v)) if isinstance(v, list) else v for k, v in alert.items()}
|
||||
if shown.get("value") is None:
|
||||
shown["value"] = "no data"
|
||||
env = SandboxedEnvironment()
|
||||
|
||||
Reference in New Issue
Block a user