如何在Kibana ElasticSearch开放发行版中使用引发警报的消息中的触发变量



我正在使用弹性搜索开放发行版。这是我的触发条件:

for (int i = 0; i < ctx.results[0].hits.hits.length; i++) {
if(2 < ctx.results[0].hits.hits[i]._source.responseTime) {
score = true;
} else {
score = false;
}
}
return score;

我正在尝试发送带有API url和响应时间的消息,其中包含我的来源的具体详细信息,如下所示,仅针对所有引发的警报(我们如何确保这一点(:

Monitor {{ctx.monitor.name}} just entered alert status. Please investigate the issue.
- **API Url : {{ctx.results.0.hits.hits.0._source.msg}} and response time {{ctx.results.0.hits.hits.0._source.responseTime}}** -- **need details only for raised alerts**
- Trigger: {{ctx.trigger.name}}
- Severity: {{ctx.trigger.severity}}
//painless trigger script
def errorCodes = new ArrayList();
for (def item : ctx.results[0].aggregations.mystats.bysats.buckets) {
if(item.val1 > 5) {
resMessate.add(item.key);
}
} 
// at the end..
ctx.results[0].hits["customerror"] = errorCodes;  `


//Now the custom error can be accessed from trigger Action template message format
//i.e
{
{{#ctx.results.0.hits.customerror}}
"erroIn": {{.}}     
{{/ctx.results.0.hits.customerror}}
}

最新更新