# E-mail plugin conditional expression

**URL:** <https://discuss.elastic.co/t/e-mail-plugin-conditional-expression/47120>\
**Category:** Logstash\
**Created:** [April 12, 2016, 1:37pm UTC](https://discuss.elastic.co/t/e-mail-plugin-conditional-expression/47120 "2016-04-12T13:37:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rafaellamuniz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rafaellamuniz/32/8885_2.png) [@rafaellamuniz](https://discuss.elastic.co/u/rafaellamuniz)\
**Post date:** [April 12, 2016, 1:37pm UTC](https://discuss.elastic.co/t/e-mail-plugin-conditional-expression/47120/1 "2016-04-12T13:37:44Z")

</div>

Hello,

I'm trying to configure the e-mail plugin for Topbeat.  
I would like to receive an e-mail when the variable fs.used\_p is greather than 70%.  
However the sintax is not working for the conditional:

**if [fs][used\_p] \>= "0.7" {**

This is my output file:

output {  
elasticsearch {  
hosts =\> ["..."]  
index =\> "%{[@metadata][beat]}-%{+YYYY.MM.dd}"  
document\_type =\> "%{[@metadata][type]}"  
}

if [fs][used\_p] \>= "0.7" {  
email {  
address =\> "..."  
port =\> 25  
authentication =\> "plain"  
from =\> "..."  
subject =\> "%{[fs][used\_p]} - %{[beat][hostname]} %{[fs][mount\_point]}"  
to =\> "..."  
via =\> "smtp"  
htmlbody =\> "  
...  
"  
}  
}  
}

I'm missing or doing something wrong?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [April 12, 2016, 1:52pm UTC](https://discuss.elastic.co/t/e-mail-plugin-conditional-expression/47120/2 "2016-04-12T13:52:39Z")

</div>

Your conditional needs to look like this:

```
if [fs][used_p] >= 0.7 {

```

This assumes that the `[fs][used_p]` field is numeric rather than a string.

---

<div class="post-metadata">

**Author:** ![rafaellamuniz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rafaellamuniz/32/8885_2.png) [@rafaellamuniz](https://discuss.elastic.co/u/rafaellamuniz)\
**Post date:** [April 12, 2016, 2:10pm UTC](https://discuss.elastic.co/t/e-mail-plugin-conditional-expression/47120/3 "2016-04-12T14:10:18Z")

</div>

When put this: if [fs][used\_p] \>= 0.7 {

I receive lots of TIME\_WAIT:

:/opt/logstash/conf.d.topbeat# netstat -na | grep 5045  
tcp 0 0 53.8.125.71:5045 53.8.125.71:41939 TIME\_WAIT  
tcp 0 0 53.8.125.71:5045 53.8.125.118:38029 TIME\_WAIT  
tcp 0 0 53.8.125.71:5045 53.8.124.153:50989 TIME\_WAIT  
tcp 0 0 53.8.125.71:5045 53.8.144.119:49096 TIME\_WAIT  
tcp 0 0 53.8.125.71:5045 53.8.144.122:39336 TIME\_WAIT  
tcp 0 0 53.8.125.71:5045 53.8.124.154:35232 TIME\_WAIT

After a while the Logstash finishes.

If I put for example: if [type] == "filesystem" {

It works and I receive the e-mails.

That's why I guess I'm missing something.

---

<div class="post-metadata">

**Author:** ![rafaellamuniz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rafaellamuniz/32/8885_2.png) [@rafaellamuniz](https://discuss.elastic.co/u/rafaellamuniz)\
**Post date:** [April 12, 2016, 7:16pm UTC](https://discuss.elastic.co/t/e-mail-plugin-conditional-expression/47120/4 "2016-04-12T19:16:25Z")

</div>

I've noticed that if I put:

if [fs][used\_p] == 0.0 {

It works.

Does anybody know if the equality conditional "\>=" really works for this case?

---

<div class="post-metadata">

**Author:** ![rafaellamuniz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rafaellamuniz/32/8885_2.png) [@rafaellamuniz](https://discuss.elastic.co/u/rafaellamuniz)\
**Post date:** [April 14, 2016, 5:04pm UTC](https://discuss.elastic.co/t/e-mail-plugin-conditional-expression/47120/5 "2016-04-14T17:04:23Z")

</div>

Any idea?

---

<div class="post-metadata">

**Author:** ![rafaellamuniz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rafaellamuniz/32/8885_2.png) [@rafaellamuniz](https://discuss.elastic.co/u/rafaellamuniz)\
**Post date:** [April 18, 2016, 6:25pm UTC](https://discuss.elastic.co/t/e-mail-plugin-conditional-expression/47120/6 "2016-04-18T18:25:27Z")

</div>

Unfortunately I still with no answer. I don't know what to do.

---

<div class="post-metadata">

**Author:** ![rafaellamuniz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rafaellamuniz/32/8885_2.png) [@rafaellamuniz](https://discuss.elastic.co/u/rafaellamuniz)\
**Post date:** [June 28, 2016, 12:11pm UTC](https://discuss.elastic.co/t/e-mail-plugin-conditional-expression/47120/7 "2016-06-28T12:11:15Z")

</div>

I was trying to use the follow conditional:

if [fs][used\_p] \>= 0.7 {

However, it didn't work. After many searchs we have discovered that some values on the fs.used\_p variable are null.  
So, when it try to campare an error is given.

To fix this it is necessary to use the follow expression:

if [fs][used\_p] and [fs][used\_p] \>= 0.7 {

First the variable is validated (if is null or not) than the conditional is made.

Now It's working and we are receiving the e-mails as expected.

---

<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 6, 2017, 4:50am UTC](https://discuss.elastic.co/t/e-mail-plugin-conditional-expression/47120/8 "2017-07-06T04:50:39Z")

</div>


