X-Pack Watcher: multiple emails in to/cc fields via template


Hello all,
Brief intro: I'm creating watcher alerts with send email actions.
Email fields TO and CC are calculatable, so known only after watch execution and can be transformed before the action.
As noted in the documentation here to field can be either array or email address from template https://www.elastic.co/guide/en/x-pack/current/actions-email.html#email-action-attributes .

Am I right, that I have no chance to format an output with Mustache template with several emails to be successfully executed?
Or there is some hidden feature inside?

Thanks in advance

Watcher: ERROR with multiple emails in to/cc fields via template
(Alexander Reelsen) #2


a possible trick here might be to have an array of email addresses, that are concatenated using the mustache {{join}} operator, that was added recently.

"to" : "{{#join}}ctx.payload.emails{{/join}}"

See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-template.html#_concatenating_array_of_values



Hi Alexander,
Thank you for the idea.
However according to the documentation it's still about rendering data as string, so I can just replace it with
"to": "email1@mail.com,email2@mail.com" to receive the same result.
And in such cases I receive Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 501 5.1.3 Invalid address exception from mail client


(Alexander Reelsen) #4


sorry, that was me typing late in the evening. I thought this works, but it does not. I do not have any better idea for now, other that storing the info statically in the watch metadata. I assume you will get that information during the execution? Can you explain your use-case?



Regarding metadata I guess it won't work for my use case, please check it below.

Some time ago I've extracted tasks from a bug tracker (JIRA) to elastic, connected with Kibana and everything is perfect.
Now I'm trying to integrate watcher in the process to automatically control issue attributes.
For example use-case: search in elastic issues with invalid label, then send email notification to assignees keeping informed team leamer and project manager.

In transform section I can calculate array of issue assignees as well as dynamic list of team leaders emails, however I wasn't able to provide this info as an recipients array via templating.
So before search query execution I don't know recipient list.


(Alexander Reelsen) #6


so I dug a bit and it seems there is support for comma separated email addresses in the email component, except for one place, where it is not supported. I will try to add this as soon as possible. Will keep you posted!



Hi Alex,
Is there any updates on this topic or may be you have some public issue tracker to subscribe on updates?


Watcher: ERROR with multiple emails in to/cc fields via template
(system) #8

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

(Lee Drengenberg) #9

(Lee Drengenberg) #10

@pabloc Please ask your question here.


(Pablo) #11

I'm running version 2.4.1 and having the same problem with multiple email addresses in a Mustache template.

Any news on this topic?

Thank you,

(Alexander Reelsen) #12

This is fixed in 5.4.0 onwards.