# How to configure email settings in a Watcher which outputs desired data in an attachment

**URL:** https://discuss.elastic.co/t/how-to-configure-email-settings-in-a-watcher-which-outputs-desired-data-in-an-attachment/136964
**Category:** Kibana
**Created:** [June 22, 2018, 3:46am UTC](https://discuss.elastic.co/t/how-to-configure-email-settings-in-a-watcher-which-outputs-desired-data-in-an-attachment/136964 "2018-06-22T03:46:20Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![swathi](https://avatars.discourse-cdn.com/v4/letter/s/35a633/32.png) [@swathi](https://discuss.elastic.co/u/swathi)
#### Post date: [June 22, 2018, 3:46am UTC](https://discuss.elastic.co/t/how-to-configure-email-settings-in-a-watcher-which-outputs-desired-data-in-an-attachment/136964/1 "2018-06-22T03:46:20Z")

</div>

Hello,

I am trying to create a Watcher to alert me (via email attachment) whenever there are new errors in the logs in a certain period of time. I have written some email configuration inside the Watcher but I'm unable to figure out to how I can display the **type of errors** and their **count and average in last 2 weeks** next to it - all in the same email attachment. When I say type of errors, it could be any error/exception, it should just display the error description inside the attachment. Please help me understand how I can retrieve this information in a single email attachment through Watcher service.

Below is the current Watcher snippet I have written, please suggest how to configure this now to receive both error description and error count and average beside it.

```
  {
  "trigger": {
    "schedule": {
      "interval": "30s"
    }
  },
  "input": {
    "search": {
      "request": {
        "search_type": "query_then_fetch",
        "indices": [
          “my_index-*”
        ],
        "types": [],
        "body": {
          "query": {
            "bool": {
              "must": [
                {
                  "query_string": {
                    "query": "debugmessage : java*exception , ERROR"
                  }
                },
                {
                  "range": {
                    "@timestamp": {
                      "from": "now-1h"
                    }
                  }
                }
              ]
            }
          },
          "_source": [
            "message"
          ],
          "sort": [
            {
              "@timestamp": {
                "order": "desc"
              }
            }
          ]
        }
      }
    }
  },
  "condition": {
    "compare": {
      "ctx.payload.hits.total": {
        "gte": 1
      }
    }
  },
  "actions": {
    "send_email": {
      "throttle_period_in_millis": 120000,
      "email": {
        "profile": "standard",
        "attachments": {
          "attach_data": {
            "data": {
              "format": "json"
            }
          }
        },
        "priority": "high",
        "to": [
          “myemailID@mydomain.com”
        ],
        "subject": "Found exceptions in the logs",
        "body": {
          "text": "Found {{ctx.payload.hits.total}} errors in the logs“
        }
      }
    }
  }
}

```

Thanks in Advance!

---

<div class="post-metadata">

### Author: ![chrisronline](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chrisronline/32/28230_2.png) [@chrisronline](https://discuss.elastic.co/u/chrisronline)
#### Post date: [June 22, 2018, 1:31pm UTC](https://discuss.elastic.co/t/how-to-configure-email-settings-in-a-watcher-which-outputs-desired-data-in-an-attachment/136964/2 "2018-06-22T13:31:32Z")

</div>

Hey @swathi,

Can you send me a snippet of the mappings for the index, making sure to include the relevant fields you want included in the email?

---

<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: [July 20, 2018, 1:31pm UTC](https://discuss.elastic.co/t/how-to-configure-email-settings-in-a-watcher-which-outputs-desired-data-in-an-attachment/136964/3 "2018-07-20T13:31:32Z")

</div>

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