Watcher payload fields to be populated in email

Follwoing is what I am trying to display in email
###########################
Queue: $DstIn$ --> value: 86.0
Queue: FAG --> value: 30.0
############################
I have tried following however no luck.
Queue: {{#ctx.payload.aggregations.bucketAgg.buckets.0}}{{key}}{{/ctx.payload.aggregations.bucketAgg.buckets.0}} --> Value: {{#ctx.payload.aggregations.bucketAgg.buckets.0.metricAgg}}{{value}}{{/ctx.payload.aggregations.bucketAgg.buckets.0.metricAgg}}

Tying to list all top 5 results, any help on this would be highly appreciated.
Here is the POST result of watcher API
{
"_id" : "d1e82dfd-26ec-41ab-b0a0-47b9dab2430d_65edf162-8394-45ee-bed4-96bd38a5c625-2019-06-10T06:25:05.492Z",
"watch_record" : {
"watch_id" : "d1e82dfd-26ec-41ab-b0a0-47b9dab2430d",
"node" : "ZE2G-NvmQ72d5b_08LVueQ",
"state" : "execution_not_needed",
"user" : "ramic",
"status" : {
"state" : {
"active" : true,
"timestamp" : "2019-06-10T05:59:22.563Z"
},
"last_checked" : "2019-06-10T06:25:05.492Z",
"actions" : {
"email_1" : {
"ack" : {
"timestamp" : "2019-06-10T05:59:22.563Z",
"state" : "awaits_successful_execution"
}
}
},
"execution_state" : "execution_not_needed",
"version" : 144
},
"trigger_event" : {
"type" : "manual",
"triggered_time" : "2019-06-10T06:25:05.492Z",
"manual" : {
"schedule" : {
"scheduled_time" : "2019-06-10T06:25:05.492Z"
}
}
},
"input" : {
"search" : {
"request" : {
"search_type" : "query_then_fetch",
"indices" : [
"cougar-qlog-host-"
],
"rest_total_hits_as_int" : true,
"body" : {
"size" : 0,
"query" : {
"bool" : {
"filter" : {
"range" : {
"@timestamp" : {
"gte" : "{{ctx.trigger.scheduled_time}}||-5m",
"lte" : "{{ctx.trigger.scheduled_time}}",
"format" : "strict_date_optional_time||epoch_millis"
}
}
}
}
},
"aggs" : {
"bucketAgg" : {
"terms" : {
"field" : "queue.keyword",
"size" : 5,
"order" : {
"metricAgg" : "desc"
}
},
"aggs" : {
"metricAgg" : {
"max" : {
"field" : "all_current"
}
}
}
}
}
}
}
}
},
"condition" : {
"script" : {
"source" : "ArrayList arr = ctx.payload.aggregations.bucketAgg.buckets; for (int i = 0; i < arr.length; i++) { if (arr[i]['metricAgg'].value > params.threshold) { return true; } } return false;",
"lang" : "painless",
"params" : {
"threshold" : 50000
}
}
},
"metadata" : {
"name" : "Test",
"watcherui" : {
"trigger_interval_unit" : "m",
"agg_type" : "max",
"time_field" : "@timestamp",
"trigger_interval_size" : 1,
"term_size" : 5,
"time_window_unit" : "m",
"threshold_comparator" : ">",
"term_field" : "queue.keyword",
"index" : [
"cougar-qlog-host-
"
],
"time_window_size" : 5,
"threshold" : 50000,
"agg_field" : "all_current"
},
"xpack" : {
"type" : "threshold"
}
},
"result" : {
"execution_time" : "2019-06-10T06:25:05.492Z",
"execution_duration" : 16,
"input" : {
"type" : "search",
"status" : "success",
"payload" : {
"_shards" : {
"total" : 75,
"failed" : 0,
"successful" : 75,
"skipped" : 0
},
"hits" : {
"hits" : ,
"total" : 1557,
"max_score" : null
},
"took" : 16,
"timed_out" : false,
"aggregations" : {
"bucketAgg" : {
"doc_count_error_upper_bound" : -1,
"sum_other_doc_count" : 1312,
"buckets" : [
{
"doc_count" : 15,
"metricAgg" : {
"value" : 552.0
},
"key" : "000004D3"
},
{
"doc_count" : 25,
"metricAgg" : {
"value" : 197.0
},
"key" : "DstIn"
},
{
"doc_count" : 25,
"metricAgg" : {
"value" : 62.0
},
"key" : "000003F3"
},
{
"doc_count" : 24,
"metricAgg" : {
"value" : 60.0
},
"key" : "BridgeNV"
},
{
"doc_count" : 6,
"metricAgg" : {
"value" : 55.0
},
"key" : "SAT"
}
]
}
}
},
"search" : {
"request" : {
"search_type" : "query_then_fetch",
"indices" : [
"cougar-qlog-host-*"
],
"rest_total_hits_as_int" : true,
"body" : {
"size" : 0,
"query" : {
"bool" : {
"filter" : {
"range" : {
"@timestamp" : {
"gte" : "2019-06-10T06:25:05.492Z||-5m",
"lte" : "2019-06-10T06:25:05.492Z",
"format" : "strict_date_optional_time||epoch_millis"
}
}
}
}
},
"aggs" : {
"bucketAgg" : {
"terms" : {
"field" : "queue.keyword",
"size" : 5,
"order" : {
"metricAgg" : "desc"
}
},
"aggs" : {
"metricAgg" : {
"max" : {
"field" : "all_current"
}
}
}
}
}
}
}
}
},
"condition" : {
"type" : "script",
"status" : "success",
"met" : false
},
"actions" :
},
"messages" :
}
}

Was able to get the results by simply using the {{ctx.payload}} and its results displayed all 5 results that I was looking for.

1 Like

Welcome, and thanks for sharing your solution! :smiley:

Just as a future suggestion, please format your code/logs/config using the </> button, or markdown style back ticks. It helps to make things easy to read which helps us help you :slight_smile:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.