Case independent/insensitive matching with MATCH

Issue #707 new
Former user created an issue

Some log files I monitor for keywords contain error messages generated by the far end, which is not under my control - and some servers use capitalized letters in the errors they send, while others use lower case, and others use firs upper case only. The Posix regular expressions man page mentions "If case-independent matching is specified, the effect is much as if all case distinctions had vanished from the alphabet". However, I can't figure out how to turn on case independent matching in the Monit MATCH syntax. Does Monit support this - and if not, would it be possible to add it? I tried all sorts of syntax variations, but couldn't find anything that works so far.

Comments (4)

  1. Tildeslash repo owner

    Monit regex is currently case sensitive ... if you want case insensitive, you can:

    1.) either rewrite the regex to case-insensitive, for example:

    if match "(?i)[bB][aA][nN][eE][dD][|L][bB][lL][aA][cC][kK][lL][iI][sS][tT]" then alert

    2.) or modify the regcomp() flags in src/p.y addmatch() function to include REG_ICASE flag and recompile monit:

    regcomp(m->regex_comp, ms->match_string, REG_NOSUB|REG_EXTENDED|REG_ICASE);

    Maybe it could be useful to extend the content match check with case sensitivity option to make the configuration simpler.

  2. Sebastian Arcus

    Thank you. In your first example, does it still need the (?i) flag at the beginning, if you are including all the upper and lower case characters?

    Maybe in the long term there could be an IMATCH option to complement MATCH, which would do a case-insensitive match?

    Also, it would be really nice if the fact that the current Monit regex is case sensitive would be added somewhere in the docs or wiki. I've spent days and days on this, and I haven't found the answer anywhere. Just knowing that the Monit regex is case sensitive and there is no option to enable the case-independent modifier would have saved a lot of time.

  3. Tildeslash repo owner

    the (?i) shouldn't be necessary

    we'll think about the case-insensitive match syntax and add it in the future

  4. Log in to comment