|
| 1 | +Introduction |
| 2 | +============= |
| 3 | + |
| 4 | +``check_mail_loop.py`` is a Nagios/Icinga plugin that checks an e-mail flow from |
| 5 | +sending an e-mail via SMTP to retrieving it from an IMAP server. |
| 6 | + |
| 7 | +Testing mail delivery is not only a matter of SMTP server availability, but nowadays |
| 8 | +also a matter of mail server reputation. If your mail server's reputation is poor, |
| 9 | +delivered e-mails may end up in spam folders. |
| 10 | + |
| 11 | +The plugin creates an E-mail with a UUID tag in the E-mail header and tries to |
| 12 | +find it later via IMAP. It checks the Inbox and if necessary also the Junk mail box. |
| 13 | +E-mails are deleted by default in the test box. |
| 14 | + |
| 15 | +The script returns OK if the expected UUID was found (exit code 0). If the E-mail |
| 16 | +was not found at all, the ERROR is returned (exit code 2). If the E-mail ended |
| 17 | +up in the Spam box, a WARNING is returned (exit code 1). |
| 18 | + |
| 19 | +You may want to use this check script with: |
| 20 | + |
| 21 | +- `check_rbl <https://github.com/matteocorti/check_rbl>`_ |
| 22 | +- `check_dnssec_expiry <https://github.com/mrimann/check_dnssec_expiry>`_ |
| 23 | +- and other modules for SMTP and IMAP |
| 24 | + |
| 25 | +Installation |
| 26 | +============= |
| 27 | + |
| 28 | +* Install dependencies: |
| 29 | + |
| 30 | +:: |
| 31 | + |
| 32 | + apt install python3-imaplib2 |
| 33 | + |
| 34 | +* Install the script `check_mail_loop.py` on your monitoring station under `/usr/local/bin/check_mail_loop.py`. |
| 35 | + |
| 36 | +* Now, define the check command. Depending on your setup, edit for example `/etc/icinga2/conf.d/commands_check_mail_loop.conf`: |
| 37 | + |
| 38 | +:: |
| 39 | + |
| 40 | + object CheckCommand "mail_loop" { |
| 41 | + import "plugin-check-command" |
| 42 | + |
| 43 | + env.SMTP_PASS = "$mail_loop_smtp_pass$" |
| 44 | + env.IMAP_PASS = "$mail_loop_imap_pass$" |
| 45 | + |
| 46 | + command = [ "/usr/local/bin/check_mail_loop.py", |
| 47 | + "--mail-from", "$mail_loop_mail_from$", |
| 48 | + "--mail-to", "$mail_loop_mail_to$", |
| 49 | + "--smtp-host", "$mail_loop_smtp_host$", |
| 50 | + "--smtp-port", "$mail_loop_smtp_port$", |
| 51 | + "--smtp-user", "$mail_loop_smtp_user$", |
| 52 | + "--imap-host", "$mail_loop_imap_host$", |
| 53 | + "--imap-port", "$mail_loop_imap_port$", |
| 54 | + "--imap-user", "$mail_loop_imap_user$", |
| 55 | + "--imap-spam", "$mail_loop_imap_spam$", |
| 56 | + "--imap-cleanup" ] |
| 57 | + } |
| 58 | + |
| 59 | +* Set up dedicated E-mail accounts. The flag `--imap-cleanup` instructs the plugin to remove all E-mails from the IMAP account. |
| 60 | + |
| 61 | +* Add a configuration file for Icinga, for example `/etc/icinga2/conf.d/services_mail_loop.conf`: |
| 62 | + |
| 63 | +:: |
| 64 | + |
| 65 | + object Service "mail-loop-mail.example.org" { |
| 66 | + import "generic-service-internet" |
| 67 | + host_name = "mail.example.org" |
| 68 | + check_command = "mail_loop" |
| 69 | + |
| 70 | + vars.mail_loop_mail_from = "test-smtp@example.org" |
| 71 | + vars.mail_loop_mail_to = "mytestaccount@gmail.com" |
| 72 | + |
| 73 | + # Configuration for E-mail delivery. |
| 74 | + vars.mail_loop_smtp_host = "mail.example.org" |
| 75 | + vars.mail_loop_smtp_port = "465" |
| 76 | + vars.mail_loop_smtp_user = "test-smtp@example.org" |
| 77 | + vars.mail_loop_smtp_pass = "secret" |
| 78 | + |
| 79 | + # IMAP configuration on the Receiving side. |
| 80 | + # If you use Gmail, you need to enable IMAP with password. |
| 81 | + vars.mail_loop_imap_host = "imap.gmail.com" |
| 82 | + vars.mail_loop_imap_port = "993" |
| 83 | + vars.mail_loop_imap_user = "mytestaccount@gmail.com" |
| 84 | + vars.mail_loop_imap_pass = "secret" |
| 85 | + vars.mail_loop_imap_spam = "[Gmail]/Spam" |
| 86 | + |
| 87 | + # Be polite and do not send too frequently. |
| 88 | + check_interval = 24h |
| 89 | + max_check_attempts = 4 |
| 90 | + retry_interval = 4h |
| 91 | + } |
| 92 | + |
| 93 | + |
| 94 | + |
| 95 | +* Fix permissions of your config file. Otherwise passwords may leak. |
| 96 | + |
| 97 | +:: |
| 98 | + |
| 99 | + chown root.icinga /etc/icinga2/conf.d/services_mail_loop.conf |
| 100 | + chmod 640 /etc/icinga2/conf.d/services_mail_loop.conf |
| 101 | + |
| 102 | + |
| 103 | +Copyright and Licence |
| 104 | +===================== |
| 105 | + |
| 106 | +``check_mail_loop.py`` is developed by Martin Schobert <martin@pentagrid.ch> and |
| 107 | +published under a BSD licence with a non-military clause. Please read |
| 108 | +``LICENSE.txt`` for further details. |
| 109 | + |
0 commit comments