monitoring-plugins icon indicating copy to clipboard operation
monitoring-plugins copied to clipboard

notify-{service,host}-mail: Icinga logo cannot be displayed

Open bence-haris opened this issue 1 year ago • 0 comments

This issue respects the following points:

  • [X] This is a bug, not a question or a setup/configuration issue.
  • [X] This issue is not already reported on Github (I've searched it).
  • [X] I use the latest release of the Monitoring Plugins (https://github.com/Linuxfabrik/monitoring-plugins/releases).
  • [X] I agree to follow Monitoring Plugins's Code of Conduct.

Which variant of the Monitoring Plugins do you use?

  • [X] .rpm/.deb package from repo.linuxfabrik.ch
  • [ ] Compiled for Linux (.tar/.zip from download.linuxfabrik.ch)
  • [ ] Compiled for Windows (from download.linuxfabrik.ch)
  • [ ] Source Code from GitHub

Bug description

When using both host and service notification plugins, sent mails don't have icinga image embedded in html, but rather sent as an attachment (base64 encoded string).

Issue seems to be systems having relatively long hostname (in our case it is a 92 character long name, including multiple hyphens), which results in incorrect Content-ID in the MIME Header, like the following:

Content-Type: icinga/png
Content-Transfer-Encoding: base64
Content-ID: =?utf-8?q?=3C173029044628=2E4046357=2E135608162032178388=40de136?=
=?utf-8?q?1-...SNIP....=3E?=
MIME-Version: 1.0
Content-Disposition: inline

There's however a correct Header for systems with shorter Hostnames (8 characters, without hyphens), such as below:

Content-Type: icinga/png
Content-Transfer-Encoding: base64
Content-ID: <173036783636.3431.18294001565118557038@SHORTER_HOSTNAME>
MIME-Version: 1.0
Content-Disposition: inline
  1. I believe issue is in the python script where logo_cid is generated (notify-host-mail: line 465)
  2. Function make_msgid() from email.utils without arguments is using socket.getfqdn() to get the domain, which has a known issue described here https://github.com/python/cpython/issues/100293

As a workaround, we're currently using the python scripts with make_msgid(domain="<shorter_name>"), that way images are embedded correctly.

Steps to reproduce - Plugin call

/usr/lib64/nagios/plugins/notifications/notify-host-mail --datetime --host-displayname <host_name> --mail-recipient <recipient_address> --mail-sender <sender_address> --host-state <state_num>

Steps to reproduce - Data

  1. Execute plugin

Environment

Ubuntu Linux 22.04.5 LTS x86_64

Plugin Version

v2023112901

Python version

No response

List of Python modules

No response

Additional Information

No response

bence-haris avatar Nov 20 '24 11:11 bence-haris