# Watcher not passing variables to an e-mail message

**URL:** https://discuss.elastic.co/t/watcher-not-passing-variables-to-an-e-mail-message/310932
**Category:** Kibana
**Created:** [July 28, 2022, 10:53pm UTC](https://discuss.elastic.co/t/watcher-not-passing-variables-to-an-e-mail-message/310932 "2022-07-28T22:53:14Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![srpmic](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/srpmic/32/109011_2.png) [@srpmic](https://discuss.elastic.co/u/srpmic)
#### Post date: [July 28, 2022, 10:53pm UTC](https://discuss.elastic.co/t/watcher-not-passing-variables-to-an-e-mail-message/310932/1 "2022-07-28T22:53:14Z")

</div>

Hello,  
I'm ingesting my Windows logs via WinlogBeat. I want to receive an e-mail when winlog.event\_id is equal to either 17, 34, 130, 21. The e-mail should contain the event.code, agent.name, time and the raw event message.

I created an advanced Watcher rule. The rule triggers when the event happens. It sends the e-mail, but the fields for event.code, agent.name and message are empty.

I'm not a programmer, but if someone has an example of how to create an alert and send an e-mail with hostname , event codes & raw message, that would be very helpful.  
Or shows me what I'm missing.

Thank You !

Here is my code;

```auto
{
  "trigger": {
    "schedule": {
      "interval": "5m"
    }
  },
  "input": {
    "search": {
      "request": {
        "search_type": "query_then_fetch",
        "indices": [
          "winlog*"
        ],
        "rest_total_hits_as_int": true,
        "body": {
          "size": 0,
          "query": {
            "bool": {
              "must": [
                {
                  "terms": {
                    "winlog.event_id": [
                      "17",
                      "34",
                      "130",
                      "21"
                    ]
                  }
                }
              ],
              "filter": {
                "range": {
                  "@timestamp": {
                    "gte": "now-5m"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "condition": {
    "compare": {
      "ctx.payload.hits.total": {
        "gt": 0
      }
    }
  },
  "actions": {
    "exchange_account": {
      "throttle_period_in_millis": 900000,
      "email": {
        "profile": "outlook",
        "from": "Elastic_Watcher_Alert@srpmic-nsn.gov",
        "to": [
          "example@abc.com"
        ],
        "cc": [
          "xyz@abc.com"
        ],
        "subject": "PKI - CRL issue : Event ID 17 or 21 or 34 or 130 ",
        "body": {
          "html": "Found event matching a potential CRL issue <br> Event ID {{event.code}} <br> on host {{agent.name}} <br> Message is: <br> {{message}} <br> There are {{ctx.payload.hits.total}} hits <br> Time of execution is {{ctx.execution_time}}"
        }
      }
    }
  }
}

```

---

<div class="post-metadata">

### Author: ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)
#### Post date: [August 12, 2022, 10:19pm UTC](https://discuss.elastic.co/t/watcher-not-passing-variables-to-an-e-mail-message/310932/2 "2022-08-12T22:19:22Z")

</div>

I would suggest you try the the Kibana Alerts and Rules instead of Watcher. It's a lot more use friendly and you can use a visual builder for the rules.

---

<div class="post-metadata">

### Author: ![srpmic](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/srpmic/32/109011_2.png) [@srpmic](https://discuss.elastic.co/u/srpmic)
#### Post date: [August 16, 2022, 12:32am UTC](https://discuss.elastic.co/t/watcher-not-passing-variables-to-an-e-mail-message/310932/3 "2022-08-16T00:32:21Z")

</div>

Marius,

Thanks for the reply.  
The Kibana Rules and Connectors only have visuals for the log thresholds. I need an alert when a certain event code appears within a log.

Thanks

ken

---

<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: [September 13, 2022, 12:32am UTC](https://discuss.elastic.co/t/watcher-not-passing-variables-to-an-e-mail-message/310932/4 "2022-09-13T00:32:35Z")

</div>

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