# Action message variable

**URL:** <https://discuss.elastic.co/t/action-message-variable/294908>\
**Category:** Kibana\
**Tags:** elastic-stack-alerting\
**Created:** [January 20, 2022, 8:40am UTC](https://discuss.elastic.co/t/action-message-variable/294908 "2022-01-20T08:40:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![eddieyee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eddieyee/32/98119_2.png) [@eddieyee](https://discuss.elastic.co/u/eddieyee)\
**Post date:** [January 20, 2022, 8:40am UTC](https://discuss.elastic.co/t/action-message-variable/294908/1 "2022-01-20T08:40:13Z")

</div>

In my Alert using Elasticsearch query, I'm building a URL pointing to Elastic Discover link in the action message and I'm able to include a time filter as seen below:

`time:(from:now-{{params.timeWindowSize}}{{params.timeWindowUnit}},to:now))`

Is it possible to do something in action message using Elasticsearch query and Log threshold as seen below:

`time:(from:'{{context.date}}-{{params.timeWindowSize}}{{params.timeWindowUnit}}',to:'{{context.date}}'))`

Please advise.

---

<div class="post-metadata">

**Author:** ![Patrick\_Mueller](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/patrick_mueller/32/109425_2.png) [@Patrick\_Mueller](https://discuss.elastic.co/u/Patrick_Mueller)\
**Post date:** [January 20, 2022, 3:37pm UTC](https://discuss.elastic.co/t/action-message-variable/294908/2 "2022-01-20T15:37:12Z")

</div>

I got pretty close!

`[discover link](https://localhost:5601/app/discover#/?_g=(filters:!(),refreshInterval:(pause:!t,value:0),time:(from:{{date}}-{{params.timeWindowSize}}{{params.timeWindowUnit}},to:{{date}}))&_a=(columns:!(),filters:!(),index:kibana-event-log,interval:auto,query:(language:kuery,query:''),sort:!(!('@timestamp',desc))))`

But Discover doesn't like the fact that I passed an `(ISO date)-5m` sort of expression as the `to`. I've got a question open to our Discover devs to find out if this is possible.

---

<div class="post-metadata">

**Author:** ![Patrick\_Mueller](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/patrick_mueller/32/109425_2.png) [@Patrick\_Mueller](https://discuss.elastic.co/u/Patrick_Mueller)\
**Post date:** [January 20, 2022, 4:05pm UTC](https://discuss.elastic.co/t/action-message-variable/294908/3 "2022-01-20T16:05:31Z")

</div>

Turns out it is possible! \o/

```auto
[discover link](https://localhost:5601/app/discover#/?_g=(filters:!(),refreshInterval:(pause:!t,value:0),time:(from:'{{date}}||-{{params.timeWindowSize}}{{params.timeWindowUnit}}',to:'{{date}}'))&_a=(columns:!(),filters:!(),index:kibana-event-log,interval:auto,query:(language:kuery,query:''),sort:!(!('@timestamp',desc))))

```

Note that I'm not sure how many rule types this will work with. All rule types have access to `{{date}}`, but probably many rule types have different names for the time window size/units, and it's possible the units won't match up exactly the same as the ones Discover is expecting. But you could hardcode the time window size/units, or both.

Tested this with an email connector and seemed to work fine. I'm a little afraid that the escaping done by other connectors may render the URL incorrectly, but ... not sure.

---

<div class="post-metadata">

**Author:** ![Patrick\_Mueller](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/patrick_mueller/32/109425_2.png) [@Patrick\_Mueller](https://discuss.elastic.co/u/Patrick_Mueller)\
**Post date:** [January 20, 2022, 4:09pm UTC](https://discuss.elastic.co/t/action-message-variable/294908/4 "2022-01-20T16:09:57Z")

</div>

Also note, if you've configured your Kibana base URL, you can use the `{{kibanaBaseUrl}}` instead of hard-coding your server address. `{{rule.spaceId}}` is also available, so you can append `/s/{{rule.spaceId}}` to the kibana base URL, and the URL would take you to the appropriate Kibana space.

---

<div class="post-metadata">

**Author:** ![eddieyee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eddieyee/32/98119_2.png) [@eddieyee](https://discuss.elastic.co/u/eddieyee)\
**Post date:** [February 9, 2022, 8:44am UTC](https://discuss.elastic.co/t/action-message-variable/294908/5 "2022-02-09T08:44:44Z")

</div>

I tried it out and it's working! Thanks!

---

<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:** [March 9, 2022, 8:45am UTC](https://discuss.elastic.co/t/action-message-variable/294908/6 "2022-03-09T08:45:24Z")

</div>

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