Skip to content

Commit 7ae4cab

Browse files
committed
fix(notify-*-mail): render Icinga logo inline on hosts with long FQDNs
On hosts with a long FQDN (>80 characters, typically with multiple hyphens), the Icinga logo in notification mails used to show up as a base64-encoded attachment instead of the embedded banner image inside the HTML body. Root cause: `email.utils.make_msgid()` defaults to `socket.getfqdn()` for the Content-ID domain. Long FQDNs push the resulting header past 80 characters, at which point Python's quoted-printable encoder wraps it across multiple lines and breaks the `cid:<...>` reference that the HTML body uses to pull the inline logo image. See python/cpython#100293 for the upstream limitation. Fix: pin the domain to `socket.gethostname()` (the short hostname), which keeps the Content-ID well under the 80-char limit. The short hostname is already imported in both notify plugins for the HTML template's `icinga_host=gethostname()` substitution, so no new imports are needed. Closes #790
1 parent c32e20b commit 7ae4cab

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ Monitoring Plugins:
163163
* needs-restarting: the "Running Kernel X != Installed Kernel Y" line now shows up on Debian-based systems when `needrestart` reports a pending kernel upgrade
164164
* network-connections: the plugin now exits with the correct WARN/CRIT state when any threshold is violated; previously it always reported OK regardless of the loop's accumulated state ([#1070](https://github.com/Linuxfabrik/monitoring-plugins/issues/1070))
165165
* nextcloud-security-scan: only trigger a rescan for scans that are actually in the past; future-dated scans caused by clock skew no longer trigger an unnecessary rescan ([#1070](https://github.com/Linuxfabrik/monitoring-plugins/issues/1070))
166+
* notify-host-mail, notify-service-mail: the Icinga logo now renders inline again in notification mails sent from hosts with long FQDNs. On such hosts the logo used to appear as a base64 attachment instead of the embedded banner image ([#790](https://github.com/Linuxfabrik/monitoring-plugins/issues/790))
166167
* ntp-\*: prevent `TypeError: ''=' not supported between instances of 'int' and 'str'`
167168
* ntp-w32tm: show the correct state label (WARNING or CRITICAL) in the "Time since Last Good Sync Time" line; it was hardcoded to WARNING even when the actual state was CRITICAL ([#1070](https://github.com/Linuxfabrik/monitoring-plugins/issues/1070))
168169
* openstack-swift-stat: "bytes used" is now shown for any account with non-zero usage, regardless of whether a quota is set ([#1070](https://github.com/Linuxfabrik/monitoring-plugins/issues/1070))

notification-plugins/notify-host-mail/notify-host-mail

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import lib.url # pylint: disable=C0413
4343
from lib.globals import STATE_UNKNOWN # pylint: disable=C0413
4444

4545
__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
46-
__version__ = '2026040801'
46+
__version__ = '2026041301'
4747

4848
DESCRIPTION = 'Sends notifications for hosts using mail.'
4949

@@ -458,7 +458,13 @@ def main():
458458
mail_msg.set_content(plain)
459459

460460
else: # no args.SHORT
461-
logo_cid = make_msgid()
461+
# Pin the domain to the short hostname so make_msgid() does not
462+
# fall back to socket.getfqdn(). On hosts with a long FQDN the
463+
# resulting Content-ID header overflows 80 characters and gets
464+
# wrapped by Python's quoted-printable encoder, which breaks the
465+
# cid:<...> reference in the HTML body and turns the inline logo
466+
# into an attachment (see python/cpython#100293 and issue #790).
467+
logo_cid = make_msgid(domain=gethostname())
462468
plain, html = generate_mail_content(args, logo_cid)
463469

464470
subject = f'Host "{args.HOST_DISPLAYNAME}" is {args.HOST_STATE}'

notification-plugins/notify-service-mail/notify-service-mail

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import lib.url # pylint: disable=C0413
4343
from lib.globals import STATE_UNKNOWN # pylint: disable=C0413
4444

4545
__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
46-
__version__ = '2026040801'
46+
__version__ = '2026041301'
4747

4848
DESCRIPTION = 'Sends notifications for services using mail.'
4949

@@ -478,7 +478,13 @@ def main():
478478
mail_msg.set_content(plain)
479479

480480
else: # no args.SHORT
481-
logo_cid = make_msgid()
481+
# Pin the domain to the short hostname so make_msgid() does not
482+
# fall back to socket.getfqdn(). On hosts with a long FQDN the
483+
# resulting Content-ID header overflows 80 characters and gets
484+
# wrapped by Python's quoted-printable encoder, which breaks the
485+
# cid:<...> reference in the HTML body and turns the inline logo
486+
# into an attachment (see python/cpython#100293 and issue #790).
487+
logo_cid = make_msgid(domain=gethostname())
482488
plain, html = generate_mail_content(args, logo_cid)
483489

484490
subject = f'Service "{args.SERVICE_DISPLAYNAME}" on "{args.HOST_DISPLAYNAME}" is {args.SERVICE_STATE}'

0 commit comments

Comments
 (0)