# How to include the hostname and location of the log within Watcher alerts?

**URL:** https://discuss.elastic.co/t/how-to-include-the-hostname-and-location-of-the-log-within-watcher-alerts/71539
**Category:** Elasticsearch
**Tags:** elastic-stack-alerting
**Created:** [January 13, 2017, 3:51pm UTC](https://discuss.elastic.co/t/how-to-include-the-hostname-and-location-of-the-log-within-watcher-alerts/71539 "2017-01-13T15:51:46Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![elkuser](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elkuser/32/13483_2.png) [@elkuser](https://discuss.elastic.co/u/elkuser)
#### Post date: [January 13, 2017, 3:51pm UTC](https://discuss.elastic.co/t/how-to-include-the-hostname-and-location-of-the-log-within-watcher-alerts/71539/1 "2017-01-13T15:51:46Z")

</div>

Hi,

I have a working watcher alert which I would like to update and include the hostname and path info within the same message - but I can't seem to get the correct syntax!!

## Currently, I have the following working:

"body": {

```
        "html": "There were {{ctx.payload.hits.total}} matches of \"some error string\" within the last N minutes at {{ctx.execution_time}}.<br><br>Here is an example message found:<br><br> {{ctx.payload.hits.hits.0._source.message}}<br><br>." 

```

## }

Supposing, if {{host}} and {{path}} would work, I'd like the above message to read as: "There were {{ctx.payload.hits.total}} matches of "some error string" within the last N minutes on {{host}} at {{ctx.execution\_time}}.  
  
Here is an example message found:  
  
 {{ctx.payload.hits.hits.0.\_source.message}}  
  
Please check the {{path}}."

Can someone please suggest how it can be done? Thanks in advance!

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [January 14, 2017, 10:50pm UTC](https://discuss.elastic.co/t/how-to-include-the-hostname-and-location-of-the-log-within-watcher-alerts/71539/2 "2017-01-14T22:50:20Z")

</div>

Hey,

I am sorry, but I was not able to extract your exact question from the post. Can you please include a sample document of your search and what you would like to extract from that? If it is just about extracting a field, you already used `ctx.payload.hits.hits.0._source.message` to access a field in the `body`. If you want to extract the hostname and the path from this field, you have to do that before indexing and not during watch execution.

--Alex

---

<div class="post-metadata">

### Author: ![elkuser](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elkuser/32/13483_2.png) [@elkuser](https://discuss.elastic.co/u/elkuser)
#### Post date: [January 19, 2017, 10:22pm UTC](https://discuss.elastic.co/t/how-to-include-the-hostname-and-location-of-the-log-within-watcher-alerts/71539/3 "2017-01-19T22:22:24Z")

</div>

Hi Alex,

thank you for the tip - I was able to retrieve the hostname and path info in the same way as the message, using ctx.payload.hits.hits.0.\_source.host and ctx.payload.hits.hits.0.\_source.path, which were already defined.

~elkuser

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [February 16, 2017, 10:22pm UTC](https://discuss.elastic.co/t/how-to-include-the-hostname-and-location-of-the-log-within-watcher-alerts/71539/4 "2017-02-16T22:22:44Z")

</div>

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