The basic function of this check is to log in to an IMAP or POP3 mailbox to monitor whether or not the login is possible. An extended feature is, that the check can fetch all (or just some) from the mailbox and forward them as events to the Event Console. |
Add the steps involved:
Setup → Services → HTTP, TCP, EMail, ... → Check Email → Add Rule
Here you can type in a service description. Please make sure that this is unique per host and does not collide with other services.
Here you can select if you want to check your IMAP or POP3 login. You need your login credentials for your E-Mail Mailbox.
Here you can select if you want to send the events either to the EC or to a remote syslog host. If you want to send the events to the local EC, we would recommend using the spooling mechanism.
By using the spooling mechanism, the check will store all collected events in one file in ~/var/mkeventd/spool.
OMD[mysite]:~$ ll ~/var/mkeventd/spool/ total 3600 -rw-rw---- 1 mysite mysite 79124 Dec 7 15:36 mysite_407343_1607351778 -rw-rw---- 1 mysite mysite 79124 Dec 7 15:37 mysite_408329_1607351841 |
Use this option to not process all messages found in the inbox but only those whose subject matches the given regular expression. The text entered here is handled as a regular expression pattern. The pattern is matched from the beginning. Add a tailing $ to change it to a whole text match. The match is performed case-sensitive. Read more about regular expression matching in Checkmk in our user official guide.
.
You need to be aware that a subject field could contain line breaks. This is depending on your mail client and mail gateway. To find out how many line breaks you have, you could check the raw email
.
Now you can use regex platforms like regex101.com to create a regex
.
Copy the plugin to the local path
OMD[mysite]:~/lib/nagios/plugins$ cp check_mail ~/local/lib/nagios/plugins/ |
Add a print for the subject
for index, msg in sorted(mails.items()): subject = msg.get('Subject', 'None') print(subject) |
Run the script manually
OMD[mysite]:~/lib/nagios/plugins$ ./check_mail --pwstore=6@17@password_1 '--fetch-protocol=IMAP' '--fetch-server=imap.strato.de' '--fetch-tls' '--fetch-port=993' '--fetch-username=user@provider.com' '--fetch-password=*************' '--connect-timeout=10' '--forward-ec' '--match-subject=.*Incident.*\n.*assigned' =?utf-8?Q?Incident_INC000000XXXX_has_bee?= =?utf-8?Q?n_assigned_to_your_group_'XXXX= =?utf-8?Q?XXXXX'_=XXXXX:_Comuni?= =?utf-8?Q?XXXXX_-_Priority:_Low?= =?utf-8?Q?Incident_INC000000XXXX_has_bee?= =?utf-8?Q?n_assigned_to_your_group_'XXXX= =?utf-8?Q?XXXXX'_=XXXXX:_Comuni?= =?utf-8?Q?XXXXX_-_Priority:_Low?= Forwarded 2 messages to event console | messages=2 |
Use this syslog facility for all created events
Use this hostname for all created events instead of the name of the mailserver
When forwarding mails from the mailbox to the event console, the body of the mail is limited to the given number of characters.
The handled messages (see subject matching) can be cleaned up by either deleting them or moving them to a subfolder. By default nothing is cleaned up.
In the log of the EC you can see the processing messages from the spool file:
2020-12-07 12:51:18,078 [20] [cmk.mkeventd.EventServer] Processing message '<21>Dec 7 12:51:17 localhost Checkmk EC: Checkmk EC|Email to EC of Checkmk!' 2020-12-07 12:51:18,079 [20] [cmk.mkeventd.EventServer] Parsed message: application: Checkmk EC core_host: facility: 2 host: localhost host_in_downtime: False ipaddress: pid: 0 priority: 5 text: Checkmk EC|Email to EC of Checkmk! time: 1607341877.0 |
For debugging reasons it could be useful to run the check manually. Therefore, you need to open the service site of the E-Mail service and search for 'Service check command'. Now you can use the command for executing the check manually.
For a detailed log you can use --debug at the end of the command:
For more information you can use --help
One alternative:
|
The Event would look like this:
![]() |
Related articles appear here based on the labels you select. Click to edit the macro and add or change labels.
|