Watcher email html body passed as a stored script

Hi,

I'd like to have my email action to retrieve the email body stored as a mustache script. Currently the email get sent with "mem-watch-warning" as a text instead of the html content stored in _scripts/mem-watch-warning.

Thanks for your help!

"actions": {
"send_mem_warning": {
"transform": {
"script": {
"lang": "painless",
"source": "def latest = ctx.payload.aggregations.minutes.buckets[-1]; return latest.nodes.buckets.stream().filter(item -> item.memory.value >= ctx.metadata.threshold).collect(Collectors.toList());"
}
},
"email": {
"profile": "standard",
"from": "watcher@your-company.com",
"to": [
"dude@your-company.com"
],
"subject": "Watcher Notification - HIGH MEMORY USAGE",
"body": {
"html": {
"id": "mem-watch-warning"
}
}
}
}
}

POST _scripts/mem-watch-warning
{
"script": {
"lang": "mustache",
"source": "

Nodes with HIGH MEMORY

Usage (above 60%):
    {{#ctx.payload._value}}
  • "{{key}}" - Memory Usage is at {{memory.value}}
  • {{/ctx.payload._value}}
"
}
}

Hey,

this is not possible currently, as the body is a TextTemplate object, but not a script, see https://github.com/elastic/elasticsearch/blob/master/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/notification/email/EmailTemplate.java#L33

Feel free to open an enhancement issue in github for this though!

--Alex

Hi Alex,

I appreciate you took the time to look at my request.
Thanks for your answer,

Cizz

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