Accessing data of the watch itself

alerting

(Willemdh) #1

Hello,

We are working on some watches and wanted to add the condition threshold in hte output of the html email. Is there a way to access data of the watch itself somehow?

For example if this is the condition:

  "condition": {
    "compare": {
      "ctx.payload.hits.total": {
        "gte": 2
      }
    }
  }

How could we access the threshold key 'ctx.payload.hits.total' and value '2' so we can use this in for example an email action?

Grtz

Willem


(Alexander Reelsen) #2

you can use mustache to access parts of the payload like {{ctx.payload.hits.total}}

--Alex


(Willemdh) #3

Alex,

Yes, I know that, but data from the watch itself, such as the threshold in the condition is not in the payload...

Grtz

Willem


(Alexander Reelsen) #4

this is true. The payload represents only the input itself. If you want to do that, you could store the threshold in the metadata and use a script condition and do sth like return ctx.payload.hits.total > ctx.metadata.threshold

--Alex


(Willemdh) #5

Alex,

Ok, I see. And can I use the values in the metadata in the condition? Then I could add

"metadata" : { "threshold" : "5" }

And refer to it in the condition?

"condition" : { "compare" : { "ctx.payload.hits.total" : { "gt" : {{ctx.metadata.threshold}} }}

Willem


(Alexander Reelsen) #6

just use a script condition like I did above instead of a compare and everything will work.


(Willemdh) #7

Alex, We were able to use the Metadata in the condition. Thanks!


(system) #8

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