Condition in html action section not working

alerting

(Leela Kumili) #1

Hi all,

I want to send email from x-pack watcher and content in email varies depending on values. I tried writing if else condition, its not evaluating the condition treating as a text.

Any idea how to do it?

"actions": {
"send_email": {
"email": {
"profile": "standard",
"to": [
"xxxx@gmail.com"
],
"subject": " Alert",
"body": {
"html": "

Hi Team,

Here is comparison report of 'Add To Bag' trends form each source for past 2 hours:


{{#ctx.payload._value}} {{#Page}} {{#source}}if({{percentage < 0.0}}) {{/source}} {{/Page
}} {{/ctx.payload._value}}
Application Page Sourcr Earlier Count Latest Count Trending Up/Down
{{App}} {{page}} {{src}} {{earlier}} {{latest}} {{percentage}}
For details refer to chart : <a href=index.html">AddToBagTrends
"
}
}
}
}

I want to change color of percentage cell to red is less than 0 , to green if greater than zero.

But instead of evaluating the condition if printing as text replace {{percentage}} variable as text like this : -46.75156796093264 < 0.0

Any idea how to tell watcher to evaluate the condition and not to treat as text.


(system) #2

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


(Alexander Reelsen) #3

hey,

mustache follows the principle of being a so-called logic less template language, trying not to have these kind of constructs. There are similar constructs though, see this page https://www.elastic.co/guide/en/elasticsearch/reference/6.3/search-template.html

However, you might be better off using a transform in your action, that adds a new field called color and doing the calculation in the script to decide if color should be red or green.

Fore more information about transforms, see https://www.elastic.co/guide/en/elastic-stack-overview/6.3/transform-script.html

Hope this helps.