Modifying regex match in nagios logwarn which matches against string, to not match if followed by another string

倾然丶 夕夏残阳落幕 提交于 2019-12-01 11:06:28

The logwarn utility accepts a list of positive and negative regular expressions. From the manual page:

Each log message is compared against each pattern in the order given. Negative patterns are specified with a ``!'' prefix. If the log message matches a positive pattern before matching a negative !pattern, or if none of the patterns match, then it's printed to standard output.

So, each line is tested against the patterns in order.

  • If a positive pattern matches, the line is accepted and no more patterns are tested.
  • If a negative pattern matches, the line is rejected and no more patterns are tested.
  • If the end of the list is reached with no pattern matches, the line is rejected.

You are looking for lines that include A but do not include B which can be expressed with an AND function: A·!B

Specifying the pattern list as A !B will result in the function: A+!B

Whereas specifying the pattern in reverse order !B A will result in the function: A·!B

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!