4

I am using elastic search open distro.This is my trigger condition :

for (int i = 0; i < ctx.results[0].hits.hits.length; i++) {

    if(2 < ctx.results[0].hits.hits[i]._source.responseTime) {
      score = true;
    } else {
      score = false;
    }

}
return score;

I am trying to send the message with the specific details of my source with the API url and response time, something like below just for all raised alerts(how do we ensure that):

Monitor {{ctx.monitor.name}} just entered alert status. Please investigate the issue.
- **API Url : {{ctx.results.0.hits.hits.0._source.msg}} and response time {{ctx.results.0.hits.hits.0._source.responseTime}}** -- **need details only for raised alerts**
- Trigger: {{ctx.trigger.name}}
- Severity: {{ctx.trigger.severity}}
SimplyProgrammer
  • 1,799
  • 2
  • 17
  • 28

1 Answers1

1
//painless trigger script
def errorCodes = new ArrayList();
for (def item : ctx.results[0].aggregations.mystats.bysats.buckets) {
   if(item.val1 > 5) {
       resMessate.add(item.key);
    }
} 
// at the end..

ctx.results[0].hits["customerror"] = errorCodes;  `




//Now the custom error can be accessed from trigger Action template message format

//i.e

{
    {{#ctx.results.0.hits.customerror}}
        "erroIn": {{.}}     
    {{/ctx.results.0.hits.customerror}}
}
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 27 '22 at 00:48