Skip to content

Commit 1624150

Browse files
committed
initial import
0 parents  commit 1624150

3 files changed

Lines changed: 424 additions & 0 deletions

File tree

LICENSE.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Copyright (c) 2023, Martin Schobert, Pentagrid AG
2+
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
1. Redistributions of source code must retain the above copyright notice, this
9+
list of conditions and the following disclaimer.
10+
2. Redistributions in binary form must reproduce the above copyright notice,
11+
this list of conditions and the following disclaimer in the documentation
12+
and/or other materials provided with the distribution.
13+
14+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24+
25+
The views and conclusions contained in the software and documentation are those
26+
of the authors and should not be interpreted as representing official policies,
27+
either expressed or implied, of the project.
28+
29+
NON-MILITARY-USAGE CLAUSE
30+
Redistribution and use in source and binary form for military use and
31+
military research is not permitted. Infringement of these clauses may
32+
result in publishing the source code of the utilizing applications and
33+
libraries to the public. As this software is developed, tested and
34+
reviewed by *international* volunteers, this clause shall not be refused
35+
due to the matter of *national* security concerns.

README.rst

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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

Comments
 (0)