ishantanu
(Shantanu Deshpande)
June 1, 2018, 7:11am
1
Hi,
While I was going through docs for adding conditions on actions in Watcher, I had a few doubts.
Is there any way I can access the payload._value
of transform block inside the condition on watcher?
Ex.
"transform": {
"type": "script",
"status": "success",
"payload": {
"_value": 0.44380686824204707
}
},
Example condition:
"condition": {
"compare" : { "ctx.payload._value" : { "gt" : ctx.metadata.threshold } }
}
In other words, alert only when the above condition succeeds.
In case I am trying to add a condition to action, it is throwing an error saying invalid [compare]
.
The action I am performing is log
.
elastock
(Guillaume Dufrenne)
June 1, 2018, 9:24am
2
You can add data into the context like this ctx.vars._value='0.44380686824204707';
"transform": {
"script" : "ctx.vars._value=0.44380686824204707"
},
ishantanu
(Shantanu Deshpande)
June 1, 2018, 9:50am
3
@elastock This is not working. It gives:
Watcher: [parse_exception] could not parse action [inlined/transform]. unknown action type [type]
OK
This is my action:
"actions": {
"log": {
"transform": {
"type": "script",
"status": "success",
"script" : "ctx.vars._value=0.44380686824204707"
},
"logging": {
"level": "info",
"text": {
"source": "Percentage change for upstream from previous day: {{ctx.payload._value}}",
"lang": "mustache"
}
}
}
},
Let me know if something is wrong. Also, the value 0.44380686824204707
is not static, it will change after transformation.
ishantanu
(Shantanu Deshpande)
June 1, 2018, 10:13am
4
Okay. I think I got this working. I didn't need to use transform, I just needed condition
.
spinscale
(Alexander Reelsen)
June 5, 2018, 8:19am
5
just to clear things up: the transform is always executed after the condition - and only if the condition is true.
system
(system)
Closed
July 3, 2018, 8:19am
6
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.