【问题标题】:How to format query result as json in Action message template如何在操作消息模板中将查询结果格式化为 json
【发布时间】:2020-11-04 20:25:29
【问题描述】:

我正在使用 Opendistro 创建警报并调用自定义 webhook 来发送警报。我希望 Opendistro 在消息中发送查询结果。唯一的问题是结果的格式不是 json,而是接近的格式。

例如,如果消息模板(Mustache)如下

{{{ctx.results.0}}}

我的 webhook 可能会收到类似的内容

{_shards={total=30, failed=0, successful=30, skipped=0}, hits={hits=[], total=3, max_score=0.0}, took=16, timed_out=false, aggregations={aggregation={doc_count_error_upper_bound=0, sum_other_doc_count=0, buckets=[{doc_count=3, key=1.1.1.1}]}}}

这是查询结果,但没有格式化为json。我想知道是否有办法在 mustache 模板中将复杂变量输出为 json,或者是否有办法解析上述格式。或者也许在上下文中还有另一个变量已经被字符串化了?

我在 Opendistro 论坛上发现了另一个 post,它暴露了同样的问题。

【问题讨论】:

    标签: kibana mustache elasticsearch-opendistro


    【解决方案1】:

    正如您在 OpenDistro 论坛中发布的更新链接一样,有一个可用的解决方案。 我已经测试过它运行良好。

    {{#toJson}}ctx.results.0{{/toJson}}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-08
      • 2011-01-19
      • 1970-01-01
      • 2020-05-24
      • 2021-08-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多