简体   繁体   English

Monit http响应内容正则表达式行为

[英]Monit http response content regex behavior

I am using a Logstash + Elasticsearch stack to aggregate logs from a few interrelated apps. 我正在使用Logstash + Elasticsearch堆栈来聚合一些相互关联的应用程序中的日志。

I am trying to get Monit to alert whenever the word 'ERROR' is returned as part of an Elasticsearch REST query from Monit, but the 'content' regex check does not seem to be working for me. 我试图让Monit在从Monit的Elasticsearch REST查询中返回“ ERROR”一词时发出警报,但是“ content”正则表达式检查似乎对我不起作用。 (I am sending email and SMS alerts from Monit via M/Monit.) (我正在通过M / Monit从Monit发送电子邮件和SMS警报。)

I know my Monit and M/Monit instances are configured properly because I can get alerts for server pings and file checksum changes, etc. just fine. 我知道我的Monit和M / Monit实例配置正确,因为我可以收到有关服务器ping和文件校验和更改等的警报。

My Monit Elasticsearch HTTP query looks like this: 我的Monit Elasticsearch HTTP查询如下所示:

check host elasticsearch_error with address 12.34.56.789
    if failed 
      url http://12.34.56.789:9200/_search?q=severity%3AERROR%20AND%20timestamp%3A>now-2d 
      and content = "ERROR" 
    then alert

BTW, %20 escapes 'space', %3A escapes ':' 顺便说一句, %20转义为'空格', %3A转义为':'

My logstash only has error log entries that are between one and two days old. 我的logstash仅包含一到两天的错误日志条目。 ie, when I run 即当我跑步时

http://12.34.56.789:9200/_search?q=severity%3AERROR%20AND%20timestamp%3A>now-2d

in the browser, I see errors (with the word 'ERROR') in the response body, but when I run 在浏览器中,我在响应正文中看到错误(带有单词“ ERROR”),但是当我运行时

http://12.34.56.789:9200/_search?q=severity%3AERROR%20AND%20timestamp%3A>now-1d

I do not. 我不。 (Note the one-day difference.) This is expected behavior. (请注意一天的差异。)这是预期的行为。 Note: my response body is a JSON with the "ERROR" string in a child element a few levels down. 注意:我的响应主体是一个JSON,其子元素中的“ ERROR”字符串向下几层。 I don't know if this affects how Monit processes the regex. 我不知道这是否会影响Monit处理正则表达式的方式。

When I run the check as above I see 当我如上所述运行检查时,我看到

'elasticsearch_error' failed protocol test [HTTP] at 
INET[12.34.56.789:9200/_search
q=severity%3AERROR%20AND%20timestamp%3A>now-2d] 
via TCP -- HTTP error: Regular expression doesn't match:
regexec() failed to match

in the log. 在日志中。 Good. 好。 Content == "ERROR" is true. 内容==“错误”为true。 I can alert from this (even though I find the Connection failed message in the Monit browser dashboard a little irritating...should be something like Regex failure .) 我可以从中发出警报(即使我在Monit浏览器仪表板中发现“ Connection failed消息也有点烦人……应该类似于Regex failure 。)

The Problem 问题

When I 'monit reload' and run the check with 当我“监控重新加载”并使用

url http://12.34.56.789:9200/_search?q=severity%3AERROR%20AND%20timestamp%3A>now-1d

I STILL get the regexec() failed to match error as above. 我仍然得到regexec() failed to match上述错误。 Note, I return no "ERROR" string in the response body. 注意,我在响应正文中没有返回“ ERROR”字符串。 Content == "ERROR" is false. 内容==“ ERROR”为假。 Why does this check fail? 为什么此检查失败? Any light shed on this issue will be appreciated! 任何对此问题的了解将不胜感激!

The Answer 答案

Turns out this problem is about URL encoding for the Elasticsearch query. 事实证明,此问题与Elasticsearch查询的URL编码有关。

I used url http://12.34.56.789:9200/_search?q=severity:ERROR&timestamp:>now-36d in the check to get Monit to make a request that looks like 12.34.56.789:9200/_search?q=severity:ERROR&timestamp:%3Enow-36d . 我在检查中使用了url http://12.34.56.789:9200/_search?q=severity:ERROR&timestamp:>now-36d来让12.34.56.789:9200/_search?q=severity:ERROR&timestamp:%3Enow-36d发出看起来像12.34.56.789:9200/_search?q=severity:ERROR&timestamp:%3Enow-36d的请求12.34.56.789:9200/_search?q=severity:ERROR&timestamp:%3Enow-36d Note change in encoding. 注意编码的变化。 This seems to work. 这似乎有效。

The actual URL used by monit can be seen by starting monit in debug mode using monit -vI . 可以通过使用monit -vI在调试模式下启动monit -vImonit -vI使用的实际URL。

Side Question 附带问题

The 'content' object seems to respect '=' and '==' and '!='. “内容”对象似乎尊重“ =”,“ ==”和“!=”。 '=' is referenced in the documentation, but a lot of third-party examples use '=='. 文档中引用了“ =”,但是许多第三方示例都使用“ ==”。 What is the most correct use? 最正确的用法是什么?

Side Question Answer 旁题答案

The helpful folks on the M/Monit team advise that "=" is an alias for "==" in the Monit configuration file. M / Monit团队的有用人员建议“ =”是Monit配置文件中“ ==”的别名。

我在上面的问题中添加了找到的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM