Use painless variable across watch segments

i want to set name_of_server in condition area and use it inside logging action.
is this possible?

"actions": {
    "my-logging-action": {
        "condition":{
            "script": {
                "source": "
                name_of_server='';
                for(int i=0; i < ctx.payload.aggregations.range_by_date.buckets[0].blades.buckets.length; i++){
                      if(ctx.payload.aggregations.range_by_date.buckets[0].blades.buckets[i][ctx.metadata.element].value > params.threshold){
                          name_of_server = ctx.payload.aggregations.range_by_date.buckets[0].blades.buckets[i][blade_name];
                          return true;
                      }
                  }",
                "lang":"painless",
                "params": { "threshold": 5 }
            }
        },
      "logging": {
        "level": "info",
        "text": "{name_of_server} alert"
      }
    }
  }

if you set name of server in the context, it will be available in the logging action, like

ctx.payload.name_of_server = 'foo-bar

then you can access that one via ctx.payload.name_of_server in your logging action.

1 Like

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