{"id":221,"date":"2024-01-19T15:37:30","date_gmt":"2024-01-19T15:37:30","guid":{"rendered":"https:\/\/wordpress.debian.social\/jlines\/?p=221"},"modified":"2024-01-19T15:37:31","modified_gmt":"2024-01-19T15:37:31","slug":"monitoring-for-email-delivery-problems","status":"publish","type":"post","link":"https:\/\/wordpress.debian.social\/jlines\/2024\/01\/19\/monitoring-for-email-delivery-problems\/","title":{"rendered":"Monitoring for email delivery problems"},"content":{"rendered":"\n<p>This post describes how I monitor for mail delivery issues, in particular mails where delivery is blocked by recipients policy, on a small server running Debian Bookworm, with Postfix and the <a href=\"https:\/\/tracker.debian.org\/pkg\/monitoring-plugins-check-logfiles\" target=\"_blank\" rel=\"noreferrer noopener\">monitoring-plugins-check-logfiles<\/a> package.<\/p>\n\n\n\n<p>If the system you are delivering to is RFC compliant, i.e. follows the normal internet rules, then if it does not accept an email from you due to policy (such as denying email from your IP address), it should <a rel=\"noreferrer noopener\" href=\"https:\/\/en.wikipedia.org\/wiki\/List_of_SMTP_server_return_codes\" target=\"_blank\">return a status code which starts with 5.7<\/a> This will show up in your \/var\/log\/mail.log as a status containing <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">'dsn=5.7'<\/pre>\n\n\n\n<p>I run an icinga2 system to monitor systems for errors, and whenever I discover a problem which had not been picked up by monitoring, and it was one which could have been detected earlier, I don&#8217;t consider the issue resolved until I have added a check to look for it in future. For this particular case I use <a href=\"https:\/\/labs.consol.de\/nagios\/check_logfiles\/\" target=\"_blank\" rel=\"noreferrer noopener\">check_logfiles<\/a> &#8211; which can be found in the Debian package <a href=\"https:\/\/tracker.debian.org\/pkg\/monitoring-plugins-check-logfiles\" target=\"_blank\" rel=\"noreferrer noopener\">monitoring-plugins-check-logfiles<\/a>, installed on the outgoing mail server, with these configuration items.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Mail server with \/var\/log\/mail.log<\/h3>\n\n\n\n<p>Here are the items I added to a mail server running postfix with logs going to \/var\/log\/mail.log, with other items already being monitored.<\/p>\n\n\n\n<div class=\"wp-block-group is-vertical is-layout-flex wp-container-core-group-is-layout-8cf370e7 wp-block-group-is-layout-flex\">\n<pre class=\"wp-block-code\"><code><strong>\/etc\/nagios\/nrpe.d\/check_logfiles_dsn57.cfg<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>command&#091;check_logfiles_dsn57]=\/usr\/bin\/sudo \/usr\/local\/bin\/check_logfiles_dsn57<\/code><\/pre>\n<\/div>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\/etc\/sudoers.d\/nagios_check_logfiles_dsn57<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>nagios ALL=(root) NOPASSWD:\/usr\/local\/bin\/check_logfiles_dsn57<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\/usr\/local\/bin\/check_logfiles_dsn57<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>#\/bin\/sh\n\n\/usr\/lib\/nagios\/plugins\/check_logfiles --tag=dsn57 --criticalpattern=\"dsn=5.7\" --logfile=\/var\/log\/mail.log\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Mail server with journald<\/h3>\n\n\n\n<p>Transitioning away from traditional syslog, with postfix logs in journald needs a slight tweak to the monitoring check_logfiles, which I patched as shown in the patch attached to Debian bug <a href=\"https:\/\/bugs.debian.org\/cgi-bin\/bugreport.cgi?bug=1060859\" target=\"_blank\" rel=\"noreferrer noopener\">#1060859<\/a>. I also changed the local script to be<\/p>\n\n\n\n<pre id=\"block-99e71f22-15e7-4b4f-b01b-4010e064f699\" class=\"wp-block-code\"><code><strong>\/usr\/local\/bin\/check_logfiles_dsn57<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>#\/bin\/sh\n\n\/usr\/lib\/nagios\/plugins\/check_logfiles_journal_identifier --tag=dsn57 --type=journald:identifier='postfix\/smtp' --criticalpattern=\"dsn=5.7\"\n\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Icinga2 server configuration<\/h3>\n\n\n\n<p>The service check for check_logfiles_dsn57 is likely not to find a new adminstratively denied mail the next time it is run (I have a check_interval of 1h), so I use the following non standard parameters for the nrpe service which does the check<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  check_command = \"nrpe\"\n  check_interval = 1h\n  retry_interval = 24h\n  volatile = true\n  vars.nrpe_command = \"check_logfiles_dsn57\"<\/code><\/pre>\n\n\n\n<p>The &#8216;retry_interval = 24h&#8217; leaves the critical alert for the problem visible until it has been investigated, and will then be cleared by re-running the test.<\/p>\n\n\n\n<p>I have &#8216;<a href=\"https:\/\/nagstamon.de\/\" target=\"_blank\" rel=\"noreferrer noopener\">nagstamon<\/a>&#8216; (from the <a href=\"https:\/\/tracker.debian.org\/pkg\/nagstamon\" target=\"_blank\" rel=\"noreferrer noopener\">Debian package<\/a>) running on my desktop as a constant overview which needs less screen space than the icingaweb page, which provides more information for a detailed investigation.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post describes how I monitor for mail delivery issues, in particular mails where delivery is blocked by recipients policy, on a small server running Debian Bookworm, with Postfix and the monitoring-plugins-check-logfiles package. If the system you are delivering to is RFC compliant, i.e. follows the normal internet rules, then if it does not accept &hellip; <a href=\"https:\/\/wordpress.debian.social\/jlines\/2024\/01\/19\/monitoring-for-email-delivery-problems\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Monitoring for email delivery problems&#8221;<\/span><\/a><\/p>\n","protected":false},"author":30,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":3,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-221","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/wordpress.debian.social\/jlines\/wp-json\/wp\/v2\/posts\/221","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.debian.social\/jlines\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wordpress.debian.social\/jlines\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.debian.social\/jlines\/wp-json\/wp\/v2\/users\/30"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.debian.social\/jlines\/wp-json\/wp\/v2\/comments?post=221"}],"version-history":[{"count":4,"href":"https:\/\/wordpress.debian.social\/jlines\/wp-json\/wp\/v2\/posts\/221\/revisions"}],"predecessor-version":[{"id":235,"href":"https:\/\/wordpress.debian.social\/jlines\/wp-json\/wp\/v2\/posts\/221\/revisions\/235"}],"wp:attachment":[{"href":"https:\/\/wordpress.debian.social\/jlines\/wp-json\/wp\/v2\/media?parent=221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordpress.debian.social\/jlines\/wp-json\/wp\/v2\/categories?post=221"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wordpress.debian.social\/jlines\/wp-json\/wp\/v2\/tags?post=221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}