Sending context variable values as a parameter to a stored script

(Juan de la Cámara) #1

I'm copying this message here since I sended it to ElasticSearch support on 9/4 but I have still no answers.



I'm creating watchers on ES. Since they will post a standard structure to a webhook I've created a stored script that takes a few parameters and stores them JSON structured in a context var.

Sometimes I need to use a context value to form a parameter. Let's see a case.

This is my script:

POST _scripts/jmdlcbtestscript001
"script": {
"lang": "painless",
"source": "ArrayList whbody = new ArrayList(); whbody.add(['alert_name':params.alert_name]); return ['cuerpo': whbody[0]]"

And this is the way I'm calling it:

"actions": {
"my-logging-action": {
"transform": {
"script": {
"lang": "painless",
"source": "jmdlcbtestscript001",
"params": {
"alert_name": "Alert Name",
"webhook" : {
"method" : "POST",
"url" : "https://myurl/api/alarms/push/",
"body" : "{{[#toJson](javascript:void(0);)}}ctx.payload.cuerpo{{/toJson}}"

So, now I want to name my alert like this:

"alert_name": "Limit reached - {{}} hits.",

If I add this to params "{{}}" is sent as string. I tried using keyword script in various ways without success.

How can I do what I need?

Juan Matías

(Grant Murphy) #2

Hi Juan,

See: Watcher Hits in Script Params for a discussion around this. Where the comment was that there is no need to pass parameters around, you have full access to the ctx field in a script transform anyway.


(system) #3

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