Do watcher watch scripts have the ability to add values to the result payload

I am using a few file scripts to influence my watch output. I see from the documentation that you can use mustache templates to get result and payload values into your conditions and transforms. However, can a condition file script add information to the result or payload of a watch.

What I would like to say in my condition file script is something like:

{{ctx.foo}}="bar"
{{ctx.baz}}="booze"
return true

Hey Dan,

you're right, that this is a task for transforms. Transforms though (on watch level, not on action level obviously) gets executed after the condition check.

PUT /_watcher/watch/cluster_health_watch
{
  "trigger": {
    "schedule": {
      "interval": "600s"
    }
  },
  "input": {
    "http": {
      "request": {
        "host": "localhost",
        "port": 9200,
        "path": "/_cluster/health"
      }
    }
  },
  "condition": {
    "script": "ctx.payload.my = new Date() ; return true"
  },
  "actions": {
    "log_error": {
      "logging": {
        "text": "Found {{ctx.payload}}"
      }
    }
  }
}

resulted in this output calling /_execute

...
    "actions": [
        {
          "id": "log_error",
          "type": "logging",
          "status": "success",
          "logging": {
            "logged_text": "Found {...all the health data... , my=Tue Mar 15 10:08:30 CET 2016}"
          }
        }
      ]
...

I'd still prefer using transforms to have scripting being only a reading component, but that might just be me.

--Alex

Thanks, very cool!

I am a Groovy newbie. Is there documentation on what is supported in a Watcher script file? Is it a plain Groovy script file?

I can see from my explorations that the following script file won't compile. Any way to import standard Java packages:

import java.text.DateFormat
def plainFormatter = DateFormat.instance
println plainFormatter.format(new Date())

Thanks, beckedo

Hey,

the docs about Scripting and Security should help you here.

--Alex

I did not know about the ClassPermission sandbox. However the article helped me discover the joda-time DateTime, DateTimeUtils, DateTimeZone, and Instant availability which is very helpful.

Thanks, beckerdo