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:
@@ -34,6 +34,12 @@ def test_raw_fields_give_bare_json_values():
|
||||
assert json.loads(n.render_webhook(tpl, {**ALERT, "value": None}))["value"] is None
|
||||
|
||||
|
||||
def test_the_names_behind_a_count_read_as_a_list_or_as_an_array():
|
||||
alert = {**ALERT, "which": ["a (0 of 1 running)", 'b "q"']}
|
||||
body = json.loads(n.render_webhook('{"w": "{{ alert.which }}", "raw": {{ raw.which | tojson }}}', alert))
|
||||
assert body == {"w": 'a (0 of 1 running), b "q"', "raw": ["a (0 of 1 running)", 'b "q"']}
|
||||
|
||||
|
||||
def test_a_missing_value_reads_no_data():
|
||||
body = n.render_webhook('{"v": "{{ alert.value }}", "note": "{{ alert.note }}"}', {**ALERT, "value": None})
|
||||
assert json.loads(body) == {"v": "no data", "note": ""}
|
||||
|
||||
Reference in New Issue
Block a user