watcher creation: mustach tag inside a webhook payload: preventing interpretation?

284 Views Asked by At

I have created a watcher that create new watcher or delete existing watcher based on an index. Basically it creates a watcher for each record of the index, those watcher then performing a weekly audit and send a eMail (html format) for the team identified in the index.

So far so good...I had issue with length of the payload in the webhook, but I solved it.

But now I am facing another issue:

The main watcher (the one that create the other watcher) perform search in some index. I use the mustach code to use the result to send the proper payload in each new watcher it create.

But the problem is that the watcher created will other perform search that will be used to populate the mail sent.

Unfortunately I cant use mustach reference, because it will be interpreted during the creation of the watcher itself.

Anyone has an idea on how to prevent the mustach tag in some part of the webhook payload to be interpreted?

exemple:

Main watcher:
create a set of new watchers using  the webhook:

      "foreach": "ctx.payload.to_be_created",
      "max_iterations": 60,
      "webhook": {
        "scheme": "https",
        "host": "xxxxx",
        "port": xxxxx,
        "method": "put",
        "path": "_watcher/watch/{{ctx.payload._source.watchername}}",
        "params": {},
        "headers": {},
        "auth": {
          "basic": {
            "username": "xxxx",
            "password": "xxxx"
          }
        },
        "body": """New Watchers to be created with mustach tag that needs to be interpreted, meaning value must be filled for the new watcher creation{{ctx.payload._source.watchername}} and mustach tag that should not be interpreted because they are part of the main code of the new watcher {{ctx.payload.bipbip.value}}"""
      }
    }
  },
and the new watcher should be like this:

Now, the new watcher when we edit it, once createc by the webhook shouyld look like this, with one tag interpreted, and the second one left so when this new watcher will be executed it could be interpreted.:

New Watchers to be created with mustach tag that needs to be interpreted, meaning value must be filled for the new watcher creation "this tag has been interpreted" and mustach tag that should not be interpreted because they are part of the main code of the new watcher {{ctx.payload.bipbip.value}}
1

There are 1 best solutions below

1
On

Got the answer, for those who might be interested:

delimiter chapter in : https://mustache.github.io/mustache.5.html