Adding conditions on action in watcher

alerting

(Shantanu Deshpande) #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.


(Guillaume Dufrenne) #2

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

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

(Shantanu Deshpande) #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.


(Shantanu Deshpande) #4

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


(Alexander Reelsen) #5

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


(system) #6

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