1

我正在尝试从 AWS ElasticSearchService Monitor Alert Trigger 在 Slack 上发布详细消息。我尝试使用描述中的变量 https://opendistro.github.io/for-elasticsearch-docs/docs/alerting/monitors/

警报被触发并发布在 Slack 上,但是当我尝试在行动中使用它们时,大多数变量都是空的。我只从ctx.trigger.name, ctx.periodStart,获取信息ctx.periodEndctx.trigger.condition像, ctx.results[0], ctx.error,这样的变量ctx.results[0].hits.total是空的,而文档说如果是空的ctx.error将被填充。ctx.results[0]

如何获取更多数据?我的查询是否以某种方式限制了它?

我的监视器提取查询如下:

{
    "size": 20,
    "query": {
        "constant_score": {
            "filter": {
                "bool": {
                    "must": [
                        {
                            "range": {
                                "@timestamp": {
                                    "from": "now-1m",
                                    "to": null,
                                    "include_lower": true,
                                    "include_upper": true,
                                    "boost": 1
                                }
                            }
                        }
                    ],
                    "must_not": [
                        {
                            "match": {
                                "status": {
                                    "query": "200",
                                    "operator": "OR",
                                    "prefix_length": 0,
                                    "max_expansions": 50,
                                    "fuzzy_transpositions": true,
                                    "lenient": false,
                                    "zero_terms_query": "NONE",
                                    "auto_generate_synonyms_phrase_query": true,
                                    "boost": 1
                                }
                            }
                        }
                    ],
                    "adjust_pure_negative": true,
                    "boost": 1
                }
            },
            "boost": 1
        }
    }
}
4

1 回答 1

7

触发器语法使用 Mustache 模板(手册页),并不全面。诀窍是遍历结果并引用如下变量:

- Total hits: {{#ctx.results}}{{#hits}}{{total}}{{/hits}}{{/ctx.results}}
- Period start: {{ctx.periodStart}}
- Period end: {{ctx.periodEnd}}
- HTTP errors:
  {{#ctx.results}}
      {{#hits}}
          {{#hits}}
              {{#_source}} ip:{{ip}} status: {{status}} : {{error.message}} at path: {{path}} {{/_source}}
          {{/hits}}
      {{/hits}}
  {{/ctx.results}}
于 2019-07-10T13:36:13.270 回答