# Format metricbeat field value in watcher alert

**URL:** <https://discuss.elastic.co/t/format-metricbeat-field-value-in-watcher-alert/263306>\
**Category:** Kibana\
**Created:** [February 4, 2021, 10:14pm UTC](https://discuss.elastic.co/t/format-metricbeat-field-value-in-watcher-alert/263306 "2021-02-04T22:14:25Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![twilight](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/twilight/32/83450_2.png) [@twilight](https://discuss.elastic.co/u/twilight)\
**Post date:** [February 4, 2021, 10:14pm UTC](https://discuss.elastic.co/t/format-metricbeat-field-value-in-watcher-alert/263306/1 "2021-02-04T22:14:25Z")

</div>

Hello,

I am using a number of watcher with various conditions and alert to be sent via email and slack.

I am receiving some values in the alert which are not easily readable e.g. disk free space which is sent by metricbeat in bytes.  
But in Kibana, we see that Kibana applies some formatting to those values before displaying in 'Discover', in Discover, I see those fields like 5.6GB, 2.1GB etc.  
The field type is 'Number' and format is set as 'Bytes'.

I am looking for same to be applied to the watcher result object {{ctx}} so that the alert email or slack message gets more comprehensible.

Thanks

---

<div class="post-metadata">

**Author:** ![AClerk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aclerk/32/55297_2.png) [@AClerk](https://discuss.elastic.co/u/AClerk)\
**Post date:** [February 4, 2021, 11:01pm UTC](https://discuss.elastic.co/t/format-metricbeat-field-value-in-watcher-alert/263306/2 "2021-02-04T23:01:48Z")

</div>

Did you try dividing the value?  
From Bytes to GB --\>  
`value/1024/1024/1024`

---

<div class="post-metadata">

**Author:** ![twilight](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/twilight/32/83450_2.png) [@twilight](https://discuss.elastic.co/u/twilight)\
**Post date:** [February 4, 2021, 11:22pm UTC](https://discuss.elastic.co/t/format-metricbeat-field-value-in-watcher-alert/263306/3 "2021-02-04T23:22:17Z")

</div>

I did. The math operators are not recognised in the email text.

The alert text can contain the variables as is like {{ctx.metadata.payload.result.value}} but no calculations.

---

<div class="post-metadata">

**Author:** ![AClerk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aclerk/32/55297_2.png) [@AClerk](https://discuss.elastic.co/u/AClerk)\
**Post date:** [February 5, 2021, 1:24am UTC](https://discuss.elastic.co/t/format-metricbeat-field-value-in-watcher-alert/263306/4 "2021-02-05T01:24:39Z")

</div>

I Did not try it before.  
But have you tried [scripts](https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting-using.html)?

---

<div class="post-metadata">

**Author:** ![twilight](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/twilight/32/83450_2.png) [@twilight](https://discuss.elastic.co/u/twilight)\
**Post date:** [February 5, 2021, 11:37am UTC](https://discuss.elastic.co/t/format-metricbeat-field-value-in-watcher-alert/263306/5 "2021-02-05T11:37:36Z")

</div>

Not sure how to embed {script} in the alert body.  
The watcher I am talking about is created through the UI.

---

<div class="post-metadata">

**Author:** ![twilight](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/twilight/32/83450_2.png) [@twilight](https://discuss.elastic.co/u/twilight)\
**Post date:** [February 6, 2021, 10:07am UTC](https://discuss.elastic.co/t/format-metricbeat-field-value-in-watcher-alert/263306/6 "2021-02-06T10:07:23Z")

</div>

I created a scripted field in the same metricbeat-\* index, that contains calculated value in GB from bytes.

But that field is not accessible in watcher UI to set threshold on it. how would a new field appear in there?

---

<div class="post-metadata">

**Author:** ![AClerk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aclerk/32/55297_2.png) [@AClerk](https://discuss.elastic.co/u/AClerk)\
**Post date:** [February 8, 2021, 3:05am UTC](https://discuss.elastic.co/t/format-metricbeat-field-value-in-watcher-alert/263306/7 "2021-02-08T03:05:23Z")

</div>

AFAIK, scripted fields are not supported in watcher.  
You'll have to use scripting as mentioned before.

---

<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 8, 2021, 3:05am UTC](https://discuss.elastic.co/t/format-metricbeat-field-value-in-watcher-alert/263306/8 "2021-03-08T03:05:32Z")

</div>

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