Negative Lookahead

Posted on
Mon Apr 19, 2021 8:54 am
InsteonDiego offline
Posts: 48
Joined: Dec 07, 2016

Negative Lookahead

Hi -

Does the trigger for Error in SQL Logger support negative lookahead in the regex matching? For example, I want to send an email for all errors in the log except for known items. For example, I don't want to receive alerts for "NOAA Weather Plus Error Unknown error getting weather" or "eggnog", however this known good pattern is still sending NOAA Matches: ^(?!(NOAA Weather Plus Error Unknown error getting weather|eggnog)$).+$

Thanks!

Posted on
Tue Apr 20, 2021 7:32 pm
matt (support) offline
Site Admin
User avatar
Posts: 21416
Joined: Jan 27, 2003
Location: Texas

Re: Negative Lookahead

I'm not 100% positive on this, but I don't believe so. The internals for that Trigger in the plugin uses the python re.search() function and not the re.match() function.

Image

Posted on
Tue Apr 20, 2021 11:19 pm
RogueProeliator offline
User avatar
Posts: 2501
Joined: Nov 13, 2012
Location: Baton Rouge, LA

Re: Negative Lookahead

Just to confirm, is the entire error in the log just "NOAA Weather Plus Error Unknown error getting weather"? I seem to remember errors when I was using that would have additional information at the end of the line (e.g. "for coordinate..") The way your regular expression is constructed it will only exclude the line if that text is the entire line in the log.

Posted on
Thu Apr 22, 2021 10:10 am
InsteonDiego offline
Posts: 48
Joined: Dec 07, 2016

Re: Negative Lookahead

Thank you Matt and RogueProeliator. I dug in further, and the error produced is as follows:

NOAA Weather Plus Error Unknown error getting weather for coordinates 32.986, -117.234: ('The read operation timed out',)

It seems the spacing in between the plugin name and the actual error was causing issues in the match. Additionally, RogueProeliator was correct and my regex would not have matched with text following the error. However, negative lookahead does seem to work properly and I have changed the regex to the following which matches correctlt, with the exception of the requirement to leave out the plugin name that triggered the error (which is fine as there may be other errors from the plugin that I do want to report on).

^(?:(?!Unknown error getting weather for coordinates|eggnog).)+$

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest