Send mustach tag in Weebhook call without having it interpreted?

Hi the community,

I am looking a way to send via webhook mustach tab (like {{ctx.payload.total_assets.hits.total}} that should not be interpreted.

The reason:
The main watcher create new watchers using the webhook. The new created watchers will have to perform their own search and send mail with resultats of the research. I am blocked since I need in the webhook payload to have mustach tag that needs to be interpreted (to create the new watcher) and some that should not be interpred since they will be use by the new watcher itself. Can't find a way so far to do it.

Exemple of code of main watcher:

{
  "trigger": {
    "schedule": {
      "interval": "1h"
    }
  },
  "input": {
    "chain": {
      "inputs": [
        {
          "deployments_list" : {
            "search" : {
              "request": {
                "search_type": "query_then_fetch",
                "indices" : [
                  "scopetest"
                ],
                "rest_total_hits_as_int": true,
                "body": {
                  "size": 1000,
                  "query": {
                    "bool": {
                      "must": [],
                      "filter": [
                        {
                          "match_phrase": {
                            "type": "Generic"
                          }
                        }
                      ],
                      "should": [],
                      "must_not": []
                    }
                  }
                }
              }
            }
          }
        },
        {
          "deployment_watchers": {
            "search": {
              "request": {
                "search_type": "query_then_fetch",
                "indices": [
                  ".watches"
                ],
                "rest_total_hits_as_int": true,
                "body": {
                  "size": 1000,
                  "query": {
                    "match": {
                      "metadata.type.keyword": "test-deployment-watcher"
                    }
                  },
                  "_source": "metadata"
                }
              }
            }
          }
        }
      ]
    }
  },
  "condition": {
    "always": {}
  },
  "actions": {
    "create-action": {
      "condition": {
        "script": {
          "source": "return !ctx.payload.to_be_created.isEmpty();",
          "lang": "painless"
        }
      },
      "foreach": "ctx.payload.to_be_created",
      "max_iterations": 60,
      "webhook": {
        "scheme": "https",
        "host": "xxxx",
        "port": xxx,
        "method": "put",
        "path": "_watcher/watch/{{ctx.payload._source.watchername}}",
        "body": """{"trigger": {"schedule": {"weekly" : { ""at" : "{{ctx.payload._source.scheduletime}}"}}},"input": {"chain": {"inputs": [{"Total_Assets": {"search":{"request": {"search_type": "query_then_fetch","indices": ["team_report_assets"],"rest_total_hits_as_int": true,"body": {"query": {"bool": {"filter": [{"match_phrase": {"Scope": "Team"}},{"range": {"DateScan": {"gte": "now-6d/d","lte": "now/d","format": "strict_date_optional_time"}}}]}}}}}}}]}},"condition": {"always": {}},"actions": {"email_1": {"email": {"profile": "standard","to": ["{{ctx.payload._source.emailto}}" ],"subject": "[Test] Weekly Test Audit","body": {"html": "total number of asset per team: {{ctx.payload.Total_Assets"}}}}}"""
      }
    }
  },
  "transform": {
   ...
  }
}

The result expected is

{
	"trigger": {
		"schedule": {
			"weekly" : { 
				"on" : "{{ctx.payload._source.scheduleday}}",
				"at" : "{{ctx.payload._source.scheduletime}}"
			}
		}
	},
	"input": {
		"chain": {
			"inputs": [
				{
					"Total_Assets": {
						"search": {
							"request": {
								"search_type": "query_then_fetch",
								"indices": ["team_report_assets"],
								"rest_total_hits_as_int": true,
								"body": {
									"query": {
										"bool": {
											"filter": [
												{
													"match_phrase": {"Scope": "Team"}
												},
												{
													"range": {
														"DateScan": {
															"gte": "now-6d/d",
															"lte": "now/d",
															"format": "strict_date_optional_time"
														}
													}
												}
											]
										}
									}
								}
							}
						}
					}
				}
			]
		}
	},
	"condition": {"always": {}},
	"actions": {
		"email_1": {"
			email": {
				"profile": "standard",
				"to": ["{{ctx.payload._source.emailto}}" ],
				"subject": "[Test] Weekly Test Audit",
				"body": {"html": "total number of asset per team: {{ctx.payload.Total_Assets"}}}
			}
		}
	}
}

but the Body of the created watcher is in fact
"body": {"html": "total number of asset per team: }
which is logical since {{ctx.payload.Total_Assets"}} is interpreted during the execution of the main watcher.

A friend find me the answer.
For those who might be interested it's in the chapter "delimiter" here: mustache(5) - Logic-less templates.

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