Skip to content

Commit 018ee42

Browse files
18927 notifications(mail): handle undefined vars
Mail notifications failed when the following variables were undefined: - `PREVIOUSHOSTHARDSTATE` - `PREVIOUSSERVICEHARDSTATE` These variables now default to `UNKNOWN` when undefined. Closes: #857 JIRA-Ref: SUP-26054 Co-authored-by: Logan Connolly <logan.connolly@checkmk.com> Change-Id: I0809202931f353058ae64415d7bacfc0a792f251
1 parent 0ab82f5 commit 018ee42

3 files changed

Lines changed: 27 additions & 6 deletions

File tree

.werks/18927.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[//]: # (werk v2)
2+
# Notifications: handle undefined mail variables
3+
4+
key | value
5+
---------- | ---
6+
date | 2025-10-21T08:52:12+00:00
7+
version | 2.5.0b1
8+
class | fix
9+
edition | cre
10+
component | notifications
11+
level | 1
12+
compatible | yes
13+
14+
Mail notifications failed when the following variables were undefined:
15+
16+
- `PREVIOUSHOSTHARDSTATE`
17+
- `PREVIOUSSERVICEHARDSTATE`
18+
19+
These variables now default to `UNKNOWN` when undefined.
20+
21+
No action is required from users to benefit from this improvement.

notifications/templates/mail/bulk.html.jinja

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@
2929
<td style="padding: 0; vertical-align: middle;">
3030
<div class="mobile_event_marker_bulk"
3131
style="{{ macros.event_marker_bulk_style() }};
32-
{% if service_notification %} {{ state_mapping[entry.PREVIOUSSERVICEHARDSTATE] }} {% else %} {{ state_mapping[entry.PREVIOUSHOSTHARDSTATE] }} {% endif %};
32+
{% if service_notification %} {{ state_mapping[(entry.PREVIOUSSERVICEHARDSTATE|default("UNKNOWN") )] }} {% else %} {{ state_mapping[(entry.PREVIOUSHOSTHARDSTATE|default("UNKNOWN") )] }} {% endif %};
3333
display: inline-block;
3434
/* Inline block to respect width */">
3535
{% if service_notification %}
36-
{{ entry.PREVIOUSSERVICEHARDSTATE[:4] }}
36+
{{ (entry.PREVIOUSSERVICEHARDSTATE|default("UNKNOWN") )[:4] }}
3737
{% else %}
38-
{{ entry.PREVIOUSHOSTHARDSTATE[:4] }}
38+
{{ (entry.PREVIOUSHOSTHARDSTATE|default("UNKNOWN") )[:4] }}
3939
{% endif %}
4040
</div>
4141
</td>

notifications/templates/mail/summary.html.jinja

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@
3333
<tr>
3434
<td style=" line-height: 45px; padding: 0; ">
3535
<div style="{{ macros.event_marker_style() }};
36-
{% if service_notification %} {{ state_mapping[data.PREVIOUSSERVICEHARDSTATE] }} {% else %} {{ state_mapping[data.PREVIOUSHOSTHARDSTATE] }} {% endif %};
36+
{% if service_notification %} {{ state_mapping[(data.PREVIOUSSERVICEHARDSTATE|default("UNKNOWN") )] }} {% else %} {{ state_mapping[(data.PREVIOUSHOSTHARDSTATE|default("UNKNOWN") )] }} {% endif %};
3737
display: inline-block;
3838
/* Inline block to respect width */">
3939
{% if service_notification %}
40-
{{ data.PREVIOUSSERVICEHARDSTATE[:4] }}
40+
{{ (data.PREVIOUSSERVICEHARDSTATE|default("UNKNOWN") )[:4] }}
4141
{% else %}
42-
{{ data.PREVIOUSHOSTHARDSHORTSTATE[:4] }}
42+
{{ (data.PREVIOUSHOSTHARDSHORTSTATE|default("UNKNOWN") )[:4] }}
4343
{% endif %}
4444
</div>
4545
</td>

0 commit comments

Comments
 (0)