New Question
 
 
PRTG Network Monitor

Intuitive to Use.
Easy to manage.

200.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free PRTG
Download >>

 

What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

 

Top Tags


View all Tags


My IMAP sensor does not process HTML emails correctly using regex. What can I do?

Votes:

0

Your Vote:

Up

Down

We monitor several backup services that send emails about their status just as described in the article How can I monitor my backup software to be sure backup succeeded last night?. For the sensor to show an error as soon as a backup failed, we use regular expressions in the search text field. If the email body does not contain “Failed Backups: 0” (but a number bigger than 0), for example, we want the sensor to show an alarm.

For plain text emails, this works as expected. However, some solutions send HTML emails. The IMAP sensor obviously recognizes these emails but erroneously changes to a Down status even if the regex in the search text field does match the "successful backup" condition.

The sensor log shows that the sensor seems to analyze only a part of the HTML emails. Is there any solution to this issue?

backup-monitoring email email-sensor imap imap-sensor prtg regex regular-expression

Created on Jul 25, 2014 1:47:45 PM by  Gerald Schoch [Paessler Support]

Last change on Jul 30, 2019 5:13:26 AM by  Maike Behnsen [Paessler Support]



1 Reply

Accepted Answer

Votes:

0

Your Vote:

Up

Down

This article applies to PRTG Network Monitor 19 or later

IMAP Sensors with RegEx for HTML Emails

If you encounter issues regarding the correct matching of regular expressions, first check the correct definition of your regex with a test tool (for example, regex101.com). Then check which type of emails the IMAP sensor has to analyze. If the emails contain an HTML body, make sure that your regular expression also matches additional source code.

Analyze the HTML Content of the Email

In some cases, the email server (for example, Microsoft Exchange) creates additional HTML markups within the source code of an email, for example, line breaks or paragraph breaks. So you need to check what exactly the HTML code contains after the email has been delivered. You can view the HTML code of an email if you save it as .html and open it with an editor (in Outlook: File | Save as).

Depending on the additional HTML code in the email, adjust the regular expression of your IMAP sensor. Make sure that the regex also matches line breaks, paragraphs, or tables. The example below will give you an idea of what you have to consider.

Example

Take the example in the question part of this article. Let us assume that our IMAP sensor should show an alarm if the target email does not contain the expression Failed Backups: 0 because in this case, there has been at least one failed backup.

Then you might have the idea to define the following regular expression in the search text field of the sensor settings:
Failed Backups: [^\d]*0[^\d]

For plain text emails, this regex will work perfectly. If there is a number other than 0, the sensor will change to a Down status. However, the defined regular expression assumes that there is no other character between “Failed Backups:” and “0”. But if your service sends HTML-encoded emails, there might be some HTML tags in between. This could look like the following: <tr style='mso-yfti-irow:4'> <td width=350 valign=top style='width:262.5pt;padding:1.5pt 1.5pt 1.5pt 1.5pt'> <p class=MsoNormal>Failed Backups:</p> </td> <td valign=top style='padding:1.5pt 1.5pt 1.5pt 1.5pt'> <p class=MsoNormal>0</p> </td> </tr>

So, after analyzing the actual content of the HTML-encoded email body, you might have the idea to use a dot "." in your regex that matches all characters:
Last Failed Backups.*0

But this would not work either because the dot does not match line breaks, which the HTML code most likely contains.

Solution: Use the dot matches all regex option: You can switch it on with (?s) and off with (?-s). Furthermore, add the left angle bracket < of the HTML tag that follows “0” to your regex in octal notation to close the search space: \074

The resulting regular expression that matches Failed Backups: 0 will then be:
Failed Backups:(?s).*0(?-s)\074

Analyze your HTML-encoded emails and adjust your defined regular expression in a similar way if your IMAP sensor does not correctly recognize them. Always keep in mind that additional HTML markups may possibly appear.

Created on Jul 25, 2014 1:54:17 PM by  Gerald Schoch [Paessler Support]

Last change on Jul 30, 2019 5:15:48 AM by  Maike Behnsen [Paessler Support]



Please log in or register to enter your reply.


Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.