[packages/nagios-notify] Fix notification templates; rel 2

arekm arekm at pld-linux.org
Tue Aug 11 09:18:39 CEST 2026


commit 0d35bceb1172852d1c295bd31a99e3be9ec0e506
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Mon Aug 10 15:18:38 2026 +0200

    Fix notification templates; rel 2
    
    Alerts carried only relative durations, so a delayed SMS never said when the event actually happened.

 nagios-notify-duration-filter.patch         |  36 ++++++
 nagios-notify-email-conditions-jinja2.patch |  63 ++++++++++
 nagios-notify-email-message-id.patch        |  48 ++++++++
 nagios-notify-filter-undefined-macro.patch  |  60 ++++++++++
 nagios-notify-jabber-xhtml-escaping.patch   |  31 +++++
 nagios-notify-notification-content.patch    | 178 ++++++++++++++++++++++++++++
 nagios-notify-timestamp-timezone.patch      |  17 +++
 nagios-notify.spec                          |  16 ++-
 8 files changed, 448 insertions(+), 1 deletion(-)
---
diff --git a/nagios-notify.spec b/nagios-notify.spec
index 7d3944d..4ca6187 100644
--- a/nagios-notify.spec
+++ b/nagios-notify.spec
@@ -2,11 +2,18 @@ Summary:	Nagios Notify Script
 Summary(pl.UTF-8):	Skrypt powiadamiający dla Nagiosa
 Name:		nagios-notify
 Version:	0.16.1
-Release:	1
+Release:	2
 License:	GPL v2
 Group:		Applications
 Source0:	https://github.com/glensc/nagios-notify/releases/download/%{version}/%{name}-%{version}.tar.xz
 # Source0-md5:	d010b82b0038c6496bfbd46413561d9a
+Patch0:		%{name}-duration-filter.patch
+Patch1:		%{name}-filter-undefined-macro.patch
+Patch2:		%{name}-timestamp-timezone.patch
+Patch3:		%{name}-email-message-id.patch
+Patch4:		%{name}-notification-content.patch
+Patch5:		%{name}-email-conditions-jinja2.patch
+Patch6:		%{name}-jabber-xhtml-escaping.patch
 URL:		https://github.com/glensc/nagios-notify
 Requires:	nagios-common
 Requires:	python3
@@ -55,6 +62,13 @@ Powody, dla których dobrze jest używać tego skryptu:
 
 %prep
 %setup -q
+%patch -P0 -p1
+%patch -P1 -p1
+%patch -P2 -p1
+%patch -P3 -p1
+%patch -P4 -p1
+%patch -P5 -p1
+%patch -P6 -p1
 %{__sed} -i -e '1s,^#!.*python3,#!%{__python3},' %{name}.py
 
 %install
diff --git a/nagios-notify-duration-filter.patch b/nagios-notify-duration-filter.patch
new file mode 100644
index 0000000..9f82057
--- /dev/null
+++ b/nagios-notify-duration-filter.patch
@@ -0,0 +1,36 @@
+Add a duration filter formatting seconds the way Nagios formats $*DURATION$.
+
+Templates must subtract two epoch macros to say how long a state lasted. Clamped
+at zero because a passive result can date a state's end before its start.
+
+diff -urN base/nagios-notify.py work/nagios-notify.py
+--- base/nagios-notify.py	2023-01-09 16:40:55.000000000 +0100
++++ work/nagios-notify.py	2026-08-10 16:04:21.487119572 +0200
+@@ -20,6 +20,7 @@
+             autoescape=select_autoescape()
+         )
+         env.filters["timestamp_date"] = self.timestamp_date
++        env.filters["duration"] = self.duration
+         env.filters["encode_mime_header"] = self.encode_mime_header
+         env.filters["urlencode"] = self.urlencode
+         env.filters["base64"] = self.base64
+@@ -62,6 +63,19 @@
+         return datetime.fromtimestamp(int(timestamp)).strftime("%Y-%m-%d %H:%M:%S")
+ 
+     @staticmethod
++    def duration(seconds):
++        """
++        Format a number of seconds the way Nagios formats $*DURATION$
++        """
++        # a passive result or a restart without retention can date the end of a
++        # state before its start; report nothing rather than a negative duration
++        days, seconds = divmod(max(0, int(seconds)), 86400)
++        hours, seconds = divmod(seconds, 3600)
++        minutes, seconds = divmod(seconds, 60)
++
++        return f"{days}d {hours}h {minutes}m {seconds}s"
++
++    @staticmethod
+     def encode_mime_header(data: str, charset: str = "utf-8"):
+         """
+         Encode email header as rfc2047 (using base64 encoding)
diff --git a/nagios-notify-email-conditions-jinja2.patch b/nagios-notify-email-conditions-jinja2.patch
new file mode 100644
index 0000000..3f56ee5
--- /dev/null
+++ b/nagios-notify-email-conditions-jinja2.patch
@@ -0,0 +1,63 @@
+Port the conditional example template to jinja2.
+
+0.16.0 switched engines but left this template on the old #if/#endif syntax, which
+has been going out as literal text in the mail body ever since.
+
+diff -urN base/templates/notify-service-by-email-conditions.tmpl work/templates/notify-service-by-email-conditions.tmpl
+--- base/templates/notify-service-by-email-conditions.tmpl	2026-08-10 16:04:21.511192773 +0200
++++ work/templates/notify-service-by-email-conditions.tmpl	2026-08-10 16:04:21.524328985 +0200
+@@ -14,33 +14,24 @@
+ Address: {{ HOSTADDRESS }}
+ 
+ {{ NOTIFICATIONTYPE }} :: {{ HOSTNAME }}/{{ SERVICEDESC }} is {{ SERVICESTATE }}
+-#if "{{ NOTIFICATIONTYPE }}" ~= /RECOVERY|ACKNOWLEDGEMENT/
+-    {{ NOTIFICATIONTYPE }} Message from Nagios
+-#endif
+-#if "{{ NOTIFICATIONTYPE }}" == "PROBLEM"
+-    {{ NOTIFICATIONTYPE }} Message #{{ NOTIFICATIONNUMBER }} from Nagios
+-#endif
+-Date/Time: {{ LONGDATETIME }}
+-
+-#if "{{ NOTIFICATIONTYPE }}" ~= /PROBLEM|ACKNOWLEDGEMENT/
+-    #if {{ NOTIFICATIONNUMBER }} > 1
+-        {{ HOSTNAME }}/{{ SERVICEDESC }} has been {{ SERVICESTATE }} for {{ SERVICEDURATION }}
+-    #else
+-        {{ HOSTNAME }}/{{ SERVICEDESC }} is {{ SERVICESTATE }}
+-    #endif
+-#endif
+-#if "{{ NOTIFICATIONTYPE }}" == "ACKNOWLEDGEMENT"
+-
+-    Problem has been acknowledged by {{ SERVICEACKAUTHOR }}: {{ SERVICEACKCOMMENT }}
+-#else
+-    #if "{{ NOTIFICATIONTYPE }}" != "RECOVERY"
+-        #if {{ NOTIFICATIONNUMBER }} >= 5
+-
+-            *** PLEASE ACKNOWLEDGE THIS PROBLEM IF YOU ARE WORKING ON IT
+-        #endif
+-    #endif
+-#endif
+-#if "{{ NOTIFICATIONTYPE }}" == "PROBLEM"
+-
+-    Probe Information: {{ SERVICEOUTPUT }}
+-#endif
++{% if NOTIFICATIONTYPE in ("RECOVERY", "ACKNOWLEDGEMENT") -%}
++{{ NOTIFICATIONTYPE }} Message from Nagios
++{%- elif NOTIFICATIONTYPE == "PROBLEM" -%}
++{{ NOTIFICATIONTYPE }} Message #{{ NOTIFICATIONNUMBER }} from Nagios
++{%- endif %}
++Date/Time: {{ TIMET|timestamp_date }}
++{% if NOTIFICATIONTYPE in ("PROBLEM", "ACKNOWLEDGEMENT") %}
++{% if NOTIFICATIONNUMBER|int > 1 -%}
++{{ HOSTNAME }}/{{ SERVICEDESC }} has been {{ SERVICESTATE }} for {{ SERVICEDURATION }}
++{%- else -%}
++{{ HOSTNAME }}/{{ SERVICEDESC }} is {{ SERVICESTATE }}
++{%- endif %}
++{% endif -%}
++{% if NOTIFICATIONTYPE == "ACKNOWLEDGEMENT" %}
++Problem has been acknowledged by {{ SERVICEACKAUTHOR }}: {{ SERVICEACKCOMMENT }}
++{% elif NOTIFICATIONTYPE != "RECOVERY" and NOTIFICATIONNUMBER|int >= 5 %}
++*** PLEASE ACKNOWLEDGE THIS PROBLEM IF YOU ARE WORKING ON IT
++{% endif -%}
++{% if NOTIFICATIONTYPE == "PROBLEM" %}
++Probe Information: {{ SERVICEOUTPUT }}
++{% endif -%}
diff --git a/nagios-notify-email-message-id.patch b/nagios-notify-email-message-id.patch
new file mode 100644
index 0000000..896280b
--- /dev/null
+++ b/nagios-notify-email-message-id.patch
@@ -0,0 +1,48 @@
+Emit RFC 5322 conformant message ids, and keep them unique.
+
+Angle brackets were missing and the macros contain spaces, so the ids were invalid.
+Message-Id was also identical all day, so MUAs that de-duplicate on it drop every
+alert but the first; the per-day thread anchor moves to In-Reply-To/References.
+
+diff -urN base/templates/notify-host-by-email.tmpl work/templates/notify-host-by-email.tmpl
+--- base/templates/notify-host-by-email.tmpl	2021-10-06 11:48:45.000000000 +0200
++++ work/templates/notify-host-by-email.tmpl	2026-08-10 16:04:21.510831305 +0200
+@@ -1,7 +1,8 @@
+ X-Mailer: Nagios Notify
+ Content-Type: text/plain; charset="utf-8"
+-Message-Id: {{ DATE }}@{{ HOSTNAME }}.nagios
+-In-Reply-To: {{ DATE }}@{{ HOSTNAME }}.nagios
++Message-Id: <{{ TIMET }}@{{ HOSTNAME|urlencode }}.nagios>
++In-Reply-To: <{{ DATE }}@{{ HOSTNAME|urlencode }}.nagios>
++References: <{{ DATE }}@{{ HOSTNAME|urlencode }}.nagios>
+ To: "{{ CONTACTALIAS|encode_mime_header }}" <{{ CONTACTEMAIL }}>
+ Subject: Host {{ HOSTSTATE }} alert for {{ HOSTNAME }}!
+ Precedence: bulk
+diff -urN base/templates/notify-service-by-email-conditions.tmpl work/templates/notify-service-by-email-conditions.tmpl
+--- base/templates/notify-service-by-email-conditions.tmpl	2021-10-05 10:01:33.000000000 +0200
++++ work/templates/notify-service-by-email-conditions.tmpl	2026-08-10 16:04:21.511192773 +0200
+@@ -1,7 +1,8 @@
+ X-Mailer: Nagios Notify
+ Content-Type: text/plain; charset="utf-8"
+-Message-Id: {{ SERVICEDESC }}.{{ DATE }}@{{ HOSTALIAS }}.nagios
+-In-Reply-To: {{ SERVICEDESC }}.{{ DATE }}@{{ HOSTALIAS }}.nagios
++Message-Id: <{{ SERVICEDESC|urlencode }}.{{ TIMET }}@{{ HOSTALIAS|urlencode }}.nagios>
++In-Reply-To: <{{ SERVICEDESC|urlencode }}.{{ DATE }}@{{ HOSTALIAS|urlencode }}.nagios>
++References: <{{ SERVICEDESC|urlencode }}.{{ DATE }}@{{ HOSTALIAS|urlencode }}.nagios>
+ To: "{{ CONTACTALIAS|encode_mime_header }}" <{{ CONTACTEMAIL }}>
+ Subject: ** {{ NOTIFICATIONTYPE }} alert - {{ HOSTALIAS }}/{{ SERVICEDESC }} is {{ SERVICESTATE }} **
+ Precedence: bulk
+diff -urN base/templates/notify-service-by-email.tmpl work/templates/notify-service-by-email.tmpl
+--- base/templates/notify-service-by-email.tmpl	2021-10-05 10:01:33.000000000 +0200
++++ work/templates/notify-service-by-email.tmpl	2026-08-10 16:04:21.511016568 +0200
+@@ -1,7 +1,8 @@
+ X-Mailer: Nagios Notify
+ Content-Type: text/plain; charset="utf-8"
+-Message-Id: {{ SERVICEDESC }}.{{ DATE }}@{{ HOSTALIAS }}.nagios
+-In-Reply-To: {{ SERVICEDESC }}.{{ DATE }}@{{ HOSTALIAS }}.nagios
++Message-Id: <{{ SERVICEDESC|urlencode }}.{{ TIMET }}@{{ HOSTALIAS|urlencode }}.nagios>
++In-Reply-To: <{{ SERVICEDESC|urlencode }}.{{ DATE }}@{{ HOSTALIAS|urlencode }}.nagios>
++References: <{{ SERVICEDESC|urlencode }}.{{ DATE }}@{{ HOSTALIAS|urlencode }}.nagios>
+ To: "{{ CONTACTALIAS|encode_mime_header }}" <{{ CONTACTEMAIL }}>
+ Subject: ** {{ NOTIFICATIONTYPE }} alert - {{ HOSTALIAS }}/{{ SERVICEDESC }} is {{ SERVICESTATE }} **
+ Precedence: bulk
diff --git a/nagios-notify-filter-undefined-macro.patch b/nagios-notify-filter-undefined-macro.patch
new file mode 100644
index 0000000..a6b5fbc
--- /dev/null
+++ b/nagios-notify-filter-undefined-macro.patch
@@ -0,0 +1,60 @@
+Render a macro Nagios did not export as empty instead of aborting.
+
+Output is piped into sendmail, so raising sends an empty mail and loses the alert.
+int() is what raises, and jinja2's own int filter does not catch it. timestamp_date
+now says "unknown" rather than 1970-01-01.
+
+diff -urN base/nagios-notify.py work/nagios-notify.py
+--- base/nagios-notify.py	2026-08-10 16:04:21.487119572 +0200
++++ work/nagios-notify.py	2026-08-10 16:04:21.499863425 +0200
+@@ -7,6 +7,21 @@
+ from functools import cached_property
+ 
+ from jinja2 import Environment, FileSystemLoader, select_autoescape
++from jinja2.runtime import Undefined
++
++
++class MissingMacro(Undefined):
++    """
++    Output is piped straight into sendmail, so a macro Nagios did not export
++    has to render empty rather than raise and turn the alert into an empty mail.
++    Undefined already renders as empty; int() and float() are what raise.
++    """
++
++    def __int__(self):
++        return 0
++
++    def __float__(self):
++        return 0.0
+ 
+ 
+ class NagiosNotify:
+@@ -17,7 +32,8 @@
+     def env(self):
+         env = Environment(
+             loader=FileSystemLoader(self.variables["TEMPLATEDIR"]),
+-            autoescape=select_autoescape()
++            autoescape=select_autoescape(),
++            undefined=MissingMacro
+         )
+         env.filters["timestamp_date"] = self.timestamp_date
+         env.filters["duration"] = self.duration
+@@ -60,7 +76,17 @@
+ 
+     @staticmethod
+     def timestamp_date(timestamp: str):
+-        return datetime.fromtimestamp(int(timestamp)).strftime("%Y-%m-%d %H:%M:%S")
++        try:
++            timestamp = int(timestamp)
++        except (TypeError, ValueError):
++            timestamp = 0
++
++        # nagios stores 0 for a state the object was never in, and a missing
++        # macro lands here too; either way 1970-01-01 would be a lie
++        if not timestamp:
++            return "unknown"
++
++        return datetime.fromtimestamp(timestamp).strftime("%Y-%m-%d %H:%M:%S")
+ 
+     @staticmethod
+     def duration(seconds):
diff --git a/nagios-notify-jabber-xhtml-escaping.patch b/nagios-notify-jabber-xhtml-escaping.patch
new file mode 100644
index 0000000..be2d378
--- /dev/null
+++ b/nagios-notify-jabber-xhtml-escaping.patch
@@ -0,0 +1,31 @@
+Produce parseable XHTML in the two richtext jabber templates.
+
+With -x the body goes through libxml2; a bare & in one href broke it always, and
+unescaped macros broke it whenever plugin output held & or <. Also drops the
+author's own nagios.dev.delfi.ee from an example URL.
+
+diff -urN base/templates/notify-service-by-jabber-embedimage.tmpl work/templates/notify-service-by-jabber-embedimage.tmpl
+--- base/templates/notify-service-by-jabber-embedimage.tmpl	2021-10-05 10:01:33.000000000 +0200
++++ work/templates/notify-service-by-jabber-embedimage.tmpl	2026-08-10 16:04:21.530447784 +0200
+@@ -1,11 +1,11 @@
+-<a href="{{ SERVICECMDURL }}&cmd_typ=7">
++<a href="{{ SERVICECMDURL|e }}&cmd_typ=7">
+ <img width="20" height="20" border="0" title="Re-schedule Next Service Check"
+  src="data:image/gif;base64,{{ (DATADIR ~ "/images/delay.gif")|base64 }}" />
+ </a>
+-<a href="{{ SERVICECMDURL }}&cmd_typ=56">
++<a href="{{ SERVICECMDURL|e }}&cmd_typ=56">
+ <img width="20" height="20" border="0" title="Schedule downtime for this service"
+  src="data:image/gif;base64,{{ (DATADIR ~ "/images/downtime.gif")|base64 }}" />
+ </a>
+ 
+- <a href="{{ SERVICEINFOURL }}">{{ SERVICEDESC }}/{{ HOSTNAME }}</a>
+- <strong>{{ NOTIFICATIONTYPE }}</strong>: {{ SERVICESTATE }} <kbd>{{ SERVICEOUTPUT }}</kbd>
++ <a href="{{ SERVICEINFOURL|e }}">{{ SERVICEDESC|e }}/{{ HOSTNAME|e }}</a>
++ <strong>{{ NOTIFICATIONTYPE|e }}</strong>: {{ SERVICESTATE|e }} <kbd>{{ SERVICEOUTPUT|e }}</kbd>
+diff -urN base/templates/notify-service-by-jabber-richtext.tmpl work/templates/notify-service-by-jabber-richtext.tmpl
+--- base/templates/notify-service-by-jabber-richtext.tmpl	2021-10-05 10:01:33.000000000 +0200
++++ work/templates/notify-service-by-jabber-richtext.tmpl	2026-08-10 16:04:21.531072922 +0200
+@@ -1 +1 @@
+-<a href="https://nagios.example.org/nagios/cgi-bin/extinfo.cgi?type=2&host={{ HOSTNAME }}&service={{ SERVICEDESC|urlencode }}" title="See service state information">{{ SERVICEDESC }}/{{ HOSTNAME }}</a> [<a href="https://nagios.dev.delfi.ee/nagios/cgi-bin/history.cgi?host={{ HOSTNAME }}&service={{ SERVICEDESC|urlencode }}&nosystem=on" title="See service event history log">log</a>] <strong>{{ NOTIFICATIONTYPE }}</strong>: {{ SERVICESTATE }} <kbd>{{ SERVICEOUTPUT }}</kbd>
++<a href="https://nagios.example.org/nagios/cgi-bin/extinfo.cgi?type=2&host={{ HOSTNAME|urlencode }}&service={{ SERVICEDESC|urlencode }}" title="See service state information">{{ SERVICEDESC|e }}/{{ HOSTNAME|e }}</a> [<a href="https://nagios.example.org/nagios/cgi-bin/history.cgi?host={{ HOSTNAME|urlencode }}&service={{ SERVICEDESC|urlencode }}&nosystem=on" title="See service event history log">log</a>] <strong>{{ NOTIFICATIONTYPE|e }}</strong>: {{ SERVICESTATE|e }} <kbd>{{ SERVICEOUTPUT|e }}</kbd>
diff --git a/nagios-notify-notification-content.patch b/nagios-notify-notification-content.patch
new file mode 100644
index 0000000..84c4428
--- /dev/null
+++ b/nagios-notify-notification-content.patch
@@ -0,0 +1,178 @@
+Say what broke, where, since when, for how long, and when the message was sent.
+
+Only a relative duration was carried, so a delayed SMS never said when the event
+happened, and at RECOVERY that duration is ~0. Recovery works because
+record_last_service_state_ended() (nagios base/checks.c:576) keys off the state that
+just ended, so LASTSERVICEOK/LASTHOSTUP still hold the outage start. "Not OK for"
+rather than the previous state's name: the span covers every non-OK state.
+
+eggdrop and slack get the same data in their own shape, but no send time: IRC
+clients stamp the line on arrival and slack renders the "ts" field itself.
+
+diff -urN base/templates/notify-host-by-eggdrop.tmpl work/templates/notify-host-by-eggdrop.tmpl
+--- base/templates/notify-host-by-eggdrop.tmpl	2021-10-05 10:01:33.000000000 +0200
++++ work/templates/notify-host-by-eggdrop.tmpl	2026-08-10 16:04:21.518059757 +0200
+@@ -1 +1 @@
+-{{ NOTIFICATIONTYPE }} alert - Host {{ HOSTNAME }} is {{ HOSTSTATE }}
++{{ NOTIFICATIONTYPE }} alert - Host {{ HOSTNAME }} is {{ HOSTSTATE }} since {{ LASTHOSTSTATECHANGE|timestamp_date }}{% if NOTIFICATIONTYPE == "RECOVERY" and LASTHOSTUP|int %}, not UP for {{ (LASTHOSTSTATECHANGE|int - LASTHOSTUP|int)|duration }}{% else %} ({{ HOSTDURATION }}){% endif %}: {{ HOSTOUTPUT }}
+diff -urN base/templates/notify-host-by-email.tmpl work/templates/notify-host-by-email.tmpl
+--- base/templates/notify-host-by-email.tmpl	2026-08-10 16:04:21.510831305 +0200
++++ work/templates/notify-host-by-email.tmpl	2026-08-10 16:04:21.517758000 +0200
+@@ -16,6 +16,11 @@
+ Address: {{ HOSTADDRESS }}
+ Info: {{ HOSTOUTPUT }}
+ 
+-Current state since: {{ HOSTDURATION }}
+-Last service OK: {{ LASTHOSTUP|timestamp_date }}
+-Date/Time: {{ LONGDATETIME }}
++{% if NOTIFICATIONTYPE == "RECOVERY" and LASTHOSTUP|int -%}
++Since: {{ LASTHOSTSTATECHANGE|timestamp_date }}
++Not UP for {{ (LASTHOSTSTATECHANGE|int - LASTHOSTUP|int)|duration }}
++{%- else -%}
++Since: {{ LASTHOSTSTATECHANGE|timestamp_date }} ({{ HOSTDURATION }})
++Last UP: {% if LASTHOSTUP|int %}{{ LASTHOSTUP|timestamp_date }}{% else %}never{% endif %}
++{%- endif %}
++Sent: {{ TIMET|timestamp_date }}
+diff -urN base/templates/notify-host-by-jabber.tmpl work/templates/notify-host-by-jabber.tmpl
+--- base/templates/notify-host-by-jabber.tmpl	2021-10-05 10:01:33.000000000 +0200
++++ work/templates/notify-host-by-jabber.tmpl	2026-08-10 16:04:21.517323592 +0200
+@@ -1,2 +1,10 @@
+-{{ HOSTNAME }} {{ NOTIFICATIONTYPE }}: {{ HOSTSTATE }} (Current state since: {{ HOSTDURATION }}; Last host UP: {{ LASTHOSTUP|timestamp_date }})
++{{ HOSTNAME }} {{ NOTIFICATIONTYPE }}: {{ HOSTSTATE }}
++{% if NOTIFICATIONTYPE == "RECOVERY" and LASTHOSTUP|int -%}
++Since: {{ LASTHOSTSTATECHANGE|timestamp_date }}
++Not UP for {{ (LASTHOSTSTATECHANGE|int - LASTHOSTUP|int)|duration }}
++{%- else -%}
++Since: {{ LASTHOSTSTATECHANGE|timestamp_date }} ({{ HOSTDURATION }})
++Last UP: {% if LASTHOSTUP|int %}{{ LASTHOSTUP|timestamp_date }}{% else %}never{% endif %}
++{%- endif %}
++Sent: {{ TIMET|timestamp_date }}
+ {{ HOSTOUTPUT }}
+diff -urN base/templates/notify-host-by-sms.tmpl work/templates/notify-host-by-sms.tmpl
+--- base/templates/notify-host-by-sms.tmpl	2021-10-05 10:01:33.000000000 +0200
++++ work/templates/notify-host-by-sms.tmpl	2026-08-10 16:04:21.516962923 +0200
+@@ -1,10 +1,16 @@
+ X-Mailer: Nagios Notify
+ To: {{ CONTACTPAGER }}
+-Date: {{ LONGDATETIME }}
+ From: {{ HOSTNAME }}@nagios.0
+ Subject: {{ HOSTSTATE }}
+ 
+-Current state since: {{ HOSTDURATION }}
+-Last Host UP: {{ LASTHOSTUP|timestamp_date }}
++{{ HOSTSTATE }} {{ HOSTNAME }}
++{% if NOTIFICATIONTYPE == "RECOVERY" and LASTHOSTUP|int -%}
++Since: {{ LASTHOSTSTATECHANGE|timestamp_date }}
++Not UP for {{ (LASTHOSTSTATECHANGE|int - LASTHOSTUP|int)|duration }}
++{%- else -%}
++Since: {{ LASTHOSTSTATECHANGE|timestamp_date }} ({{ HOSTDURATION }})
++Last UP: {% if LASTHOSTUP|int %}{{ LASTHOSTUP|timestamp_date }}{% else %}never{% endif %}
++{%- endif %}
++Sent: {{ TIMET|timestamp_date }}
+ 
+ {{ HOSTOUTPUT }}
+diff -urN base/templates/notify-service-by-eggdrop.tmpl work/templates/notify-service-by-eggdrop.tmpl
+--- base/templates/notify-service-by-eggdrop.tmpl	2021-10-05 10:01:33.000000000 +0200
++++ work/templates/notify-service-by-eggdrop.tmpl	2026-08-10 16:04:21.517892286 +0200
+@@ -1 +1 @@
+-{{ NOTIFICATIONTYPE }}: {{ HOSTALIAS }}/{{ SERVICEDESC }} is {{ SERVICESTATE }}: {{ SERVICEOUTPUT }}
++{{ NOTIFICATIONTYPE }}: {{ HOSTALIAS }}/{{ SERVICEDESC }} is {{ SERVICESTATE }} since {{ LASTSERVICESTATECHANGE|timestamp_date }}{% if NOTIFICATIONTYPE == "RECOVERY" and LASTSERVICEOK|int %}, not OK for {{ (LASTSERVICESTATECHANGE|int - LASTSERVICEOK|int)|duration }}{% else %} ({{ SERVICEDURATION }}){% endif %}: {{ SERVICEOUTPUT }}
+diff -urN base/templates/notify-service-by-email.tmpl work/templates/notify-service-by-email.tmpl
+--- base/templates/notify-service-by-email.tmpl	2026-08-10 16:04:21.511016568 +0200
++++ work/templates/notify-service-by-email.tmpl	2026-08-10 16:04:21.517556845 +0200
+@@ -17,9 +17,14 @@
+ Address: {{ HOSTADDRESS }}
+ State: {{ SERVICESTATE }}
+ 
+-Current state since: {{ SERVICEDURATION }}
+-Last service OK: {{ LASTSERVICEOK|timestamp_date }}
+-Date/Time: {{ LONGDATETIME }}
++{% if NOTIFICATIONTYPE == "RECOVERY" and LASTSERVICEOK|int -%}
++Since: {{ LASTSERVICESTATECHANGE|timestamp_date }}
++Not OK for {{ (LASTSERVICESTATECHANGE|int - LASTSERVICEOK|int)|duration }}
++{%- else -%}
++Since: {{ LASTSERVICESTATECHANGE|timestamp_date }} ({{ SERVICEDURATION }})
++Last OK: {% if LASTSERVICEOK|int %}{{ LASTSERVICEOK|timestamp_date }}{% else %}never{% endif %}
++{%- endif %}
++Sent: {{ TIMET|timestamp_date }}
+ 
+ Additional Info:
+ 
+diff -urN base/templates/notify-service-by-jabber.tmpl work/templates/notify-service-by-jabber.tmpl
+--- base/templates/notify-service-by-jabber.tmpl	2021-10-05 10:01:33.000000000 +0200
++++ work/templates/notify-service-by-jabber.tmpl	2026-08-10 16:04:21.517130370 +0200
+@@ -1,2 +1,10 @@
+-{{ SERVICEDESC }}/{{ HOSTNAME }} {{ NOTIFICATIONTYPE }}: {{ SERVICESTATE }} (Current state since: {{ SERVICEDURATION }}; Last service OK: {{ LASTSERVICEOK|timestamp_date }})
++{{ SERVICEDESC }}/{{ HOSTNAME }} {{ NOTIFICATIONTYPE }}: {{ SERVICESTATE }}
++{% if NOTIFICATIONTYPE == "RECOVERY" and LASTSERVICEOK|int -%}
++Since: {{ LASTSERVICESTATECHANGE|timestamp_date }}
++Not OK for {{ (LASTSERVICESTATECHANGE|int - LASTSERVICEOK|int)|duration }}
++{%- else -%}
++Since: {{ LASTSERVICESTATECHANGE|timestamp_date }} ({{ SERVICEDURATION }})
++Last OK: {% if LASTSERVICEOK|int %}{{ LASTSERVICEOK|timestamp_date }}{% else %}never{% endif %}
++{%- endif %}
++Sent: {{ TIMET|timestamp_date }}
+ {{ SERVICEOUTPUT }}
+diff -urN base/templates/notify-service-by-slack.tmpl work/templates/notify-service-by-slack.tmpl
+--- base/templates/notify-service-by-slack.tmpl	2023-01-09 16:40:55.000000000 +0100
++++ work/templates/notify-service-by-slack.tmpl	2026-08-10 16:04:21.518551241 +0200
+@@ -9,6 +9,12 @@
+ {% endif %}
+ 
+ {%- set text = SERVICEOUTPUT -%}
++{%- set since = LASTSERVICESTATECHANGE|timestamp_date -%}
++{%- if NOTIFICATIONTYPE == "RECOVERY" and LASTSERVICEOK|int -%}
++    {%- set held = "not OK for {}".format((LASTSERVICESTATECHANGE|int - LASTSERVICEOK|int)|duration) -%}
++{%- else -%}
++    {%- set held = SERVICEDURATION -%}
++{%- endif -%}
+ {%- set title = "Service {}: {}".format(NOTIFICATIONTYPE, SERVICESTATE) -%}
+ 
+ {%- if NOTIFICATIONTYPE == "PROBLEM" -%}
+@@ -40,6 +46,16 @@
+           "title": "Service",
+           "value": "<{{ SERVICEINFOURL }}|{{ SERVICEDESC }}>",
+           "short": true
++        },
++        {
++          "title": "Since",
++          "value": {{ since | tojson }},
++          "short": true
++        },
++        {
++          "title": "Duration",
++          "value": {{ held | tojson }},
++          "short": true
+ {% if SERVICESTATE != "OK" %}
+         },
+         {
+diff -urN base/templates/notify-service-by-sms.tmpl work/templates/notify-service-by-sms.tmpl
+--- base/templates/notify-service-by-sms.tmpl	2021-12-29 14:59:04.000000000 +0100
++++ work/templates/notify-service-by-sms.tmpl	2026-08-10 16:04:21.516481434 +0200
+@@ -1,14 +1,20 @@
+ X-Mailer: Nagios Notify
+ To: {{ CONTACTPAGER }}
+-Date: {{ LONGDATETIME }}
+ From: {{ SERVICEDESC }}@{{ HOSTNAME }}.0
+ Subject: {{ SERVICESTATE }}
+ 
+-Current state since: {{ SERVICEDURATION }}
+-Last service OK: {{ LASTSERVICEOK|timestamp_date }})
++{{ SERVICESTATE }} {{ HOSTNAME }} / {{ SERVICEDESC }}
++{% if NOTIFICATIONTYPE == "RECOVERY" and LASTSERVICEOK|int -%}
++Since: {{ LASTSERVICESTATECHANGE|timestamp_date }}
++Not OK for {{ (LASTSERVICESTATECHANGE|int - LASTSERVICEOK|int)|duration }}
++{%- else -%}
++Since: {{ LASTSERVICESTATECHANGE|timestamp_date }} ({{ SERVICEDURATION }})
++Last OK: {% if LASTSERVICEOK|int %}{{ LASTSERVICEOK|timestamp_date }}{% else %}never{% endif %}
++{%- endif %}
++Sent: {{ TIMET|timestamp_date }}
+ 
+-{% if NOTIFICATIONTYPE == "ACKNOWLEDGEMENT" %}
++{% if NOTIFICATIONTYPE == "ACKNOWLEDGEMENT" -%}
+ Acknowledged by {{ SERVICEACKAUTHOR }}: {{ SERVICEACKCOMMENT }}
+-{% else %}
++{%- else -%}
+ {{ SERVICEOUTPUT }}
+-{% endif %}
++{%- endif %}
diff --git a/nagios-notify-timestamp-timezone.patch b/nagios-notify-timestamp-timezone.patch
new file mode 100644
index 0000000..c1cb0b6
--- /dev/null
+++ b/nagios-notify-timestamp-timezone.patch
@@ -0,0 +1,17 @@
+State the timezone in timestamp_date output.
+
+Bare server-local time is unreadable on a phone in another zone or across a DST
+change, and disagrees with $LONGDATETIME$ in the same message.
+
+diff -urN base/nagios-notify.py work/nagios-notify.py
+--- base/nagios-notify.py	2026-08-10 16:04:21.499863425 +0200
++++ work/nagios-notify.py	2026-08-10 16:04:21.505569032 +0200
+@@ -86,7 +86,7 @@
+         if not timestamp:
+             return "unknown"
+ 
+-        return datetime.fromtimestamp(timestamp).strftime("%Y-%m-%d %H:%M:%S")
++        return datetime.fromtimestamp(timestamp).astimezone().strftime("%Y-%m-%d %H:%M:%S %Z")
+ 
+     @staticmethod
+     def duration(seconds):
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/nagios-notify.git/commitdiff/0d35bceb1172852d1c295bd31a99e3be9ec0e506



More information about the pld-cvs-commit mailing list