Adding conditions on action in watcher

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.

You can add data into the context like this ctx.vars._value='0.44380686824204707';

  "transform": {
  "script" :  "ctx.vars._value=0.44380686824204707"
},

@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.

Okay. I think I got this working. I didn't need to use transform, I just needed condition.

just to clear things up: the transform is always executed after the condition - and only if the condition is true.

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