Hello,
I want to do math in my watcher, but i am not able to do it.
I have already configured a watcher, that works as it should but the output in the email (ctx.payload.result) looks like this:
16.236
Is it possible to do math on the value of ctx.payload.result ? something like "ctx.payload.result / 1024" ?
here are my watcher settings:
{ "watch" : { "trigger" : { "schedule" : { "interval" : "15m" } }, "input" : { "search" : { "request" : { "search_type" : "query_then_fetch", "indices" : [ "test-*" ], "rest_total_hits_as_int" : true, "body" : { "size" : 0, "query" : { "bool" : { "filter" : { "range" : { "@timestamp" : { "gte" : "{{ctx.trigger.scheduled_time}}||-8m", "lte" : "{{ctx.trigger.scheduled_time}}", "format" : "strict_date_optional_time||epoch_millis" } } } } }, "aggs" : { "metricAgg" : { "sum" : { "field" : "bytes" } } } } } } }, "condition" : { "script" : { "source" : "if (ctx.payload.aggregations.metricAgg.value > params.threshold) { return true; } return false;", "lang" : "painless", "params" : { "threshold" : 300000000 } } }, "transform" : { "script" : { "**source" : "ctx.payload.result = ctx.payload.result / 1024 ; return ctx.payload.result**", "lang" : "painless" } }, "actions" : { "email_1" : { "email" : { "profile" : "standard", "to" : [ "my-email@test.com" ], "subject" : "Watch [{{ctx.metadata.name}}] has exceeded the threshold", "body" : { "text" : "{{ctx.payload.result}}" } } } }, "metadata" : { "name" : "traffic-test", "watcherui" : { "trigger_interval_unit" : "m", "agg_type" : "sum", "time_field" : "@timestamp", "trigger_interval_size" : 15, "term_size" : 5, "time_window_unit" : "m", "threshold_comparator" : ">", "term_field" : null, "index" : [ "test-*" ], "time_window_size" : 8, "threshold" : 300000000, "agg_field" : "bytes" }, "xpack" : { "type" : "threshold" } } } }
Maybe someone can help me.
Best regards