Open roneetshaw opened 5 years ago
Do you want to pass the the value of age and the threshold both in the event digest? You can change the pattern then, to capture that value in a variable. But in the sample even digest, you are passing only the value of age. So 8 will be compared to which value? I think you want to pass both the threshold and the value in the event. e.g.
{
"location": "here",
"event": {
"age": "8",
"age_threshold": "6",
"name": "sonu"
}
}
Then your rule can be,
{
"location": "here",
"rule": {
"action": {
"code": "var msg ='Name :' + who + ' age : '+x; console.log(msg); msg;"
},
"condition": {
"and": [
{
"pattern": {
"age": "?x",
"age_threshold": "?t",
"name": "?who"
}
},
{
"code": "x > t"
}
]
},
"when": {
"pattern": {
"age": "?x",
"age_threshold": "?t",
"name": "?who"
}
}
}
}
One thing, in the ingest you are passing the value as string so the comparison will be string comparison. I think in the code you should convert the value and threshold to numeric explicitly for numeric comparison.
Thanks @rakesh-roshan for the suggestion. I will try it out and let you know about the result. Thank you so much.
Hi Rakesh, Your solution worked great. Thanks for sharing. However, can we perform comparisons (>, <, etc) at the "pattern" level? and not on "code" level
This is my rule
In the above JSON, I am checking with constant 6 where age> 6 in my condition, but is there a way where I can pass a variable instead of fix values from the uri: /api/loc/events/ingest For example uri: /api/loc/events/ingest request
The age passed here i.e. 8 should be used in the rule condition and the result should be according to that?