Substring in watcher action

Hi,
I've created a watcher which monitors for the keywords "result address" and returns the following line. Is there a way to extract the "doorno" part out of this line to display in an email through the watcher action?

"The result address is /continent/country/province/county/city/street/doorno"

Tried playing around with Moustache, that didn't seem to help thou'. Any other pointers?

Hey,

check out this example

POST _xpack/watcher/watch/_execute
{
  "watch": {
    "trigger": {
      "schedule": {
        "interval": "10h"
      }
    },
    "input": {
      "simple": {
        "foo": " /continent/country/province/county/city/street/doorno"
      }
    },
    "actions": {
      "logme": {
        "transform" : {
          "script": "def lastSlashPosition = ctx.payload.foo.lastIndexOf('/') ; return ctx.payload.foo.substring(lastSlashPosition+1)"
        },
        "logging": {
          "text": "{{ctx.payload}}"
        }
      }
    }
  }
}

note, that the transformation is super simple and not fool proof. There are no boundary checks (last character being a slash for example), but it should get you started.

--Alex

1 Like

Thanks. Will give it a try now.

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