Watcher's condition summary.down 0 and 1

Hi, I need help in a watcher's condition:
I don't know if a for or a while is useful: I need the following: I have a variable "summary.down" with two values 0 and 1, so I need it to be executed infinitely and when it changes, that is, when "summary.down" is equal to 0, I need you to do an action, which is to send me a report to the email I have already configured.

{
  "trigger": {
    "schedule": {
      "interval": "1h"
    }
  },
  "input": {
    "search": {
      "request": {
        "search_type": "query_then_fetch",
        "indices": [
          "agenteallot*"
        ],
        "rest_total_hits_as_int": true,
        "body": {
          "size": 0,
          "query": {
            "bool": {
              "filter": [
                {
                  "range": {
                    "@timestamp": {
                      "gte": "{{ctx.trigger.scheduled_time}}||-5m",
                      "lte": "{{ctx.trigger.scheduled_time}}",
                      "format": "strict_date_optional_time||basic_time_no_millis"
                    }
                  }
                },
                {
                  "term": {
                    "monitor.name.keyword": "01-1-CAV30328203-DATOS-PPAL-2.7G-99.98"
                  }
                }
              ]
            }
          },
          "aggs": {
            "metricAgg": {
              "max": {
                "field": "summary.down"
              }
            }
          }
        }
      }
    }
  },
  "condition": {
    "script": {
      "source": " while (ctx.payload.aggregations.metricAgg.value != params.threshold ) {return=true; } return=false;",
      "lang": "painless",
      "params": {
        "threshold": 0
      }
    }
  },
  "actions": {
    "email_1": {
      "email": {
        "profile": "standard",
        "attach_data": {
          "format": "json"
        },
        "to": [
          "juan.jaramillo@megadvantage.com",
          "juancho.jaramillo16@gmail.com",
          "victor.vera@megadvantage.com"
        ],
        "subject": "{{ctx.metadata.name}} 01-1-CAV30328203-DATOS-PPAL-2.7G-99.98",
        "body": {
          "text": """Buen dia, Adjunto registro del reporte.

 ⚠️ALERTA NODO!!! El siguiente enlace perdió la conexión. 

 Estado: Down🔴 

 Nombre del Enlace: 01-1-CAV30328203-DATOS-PPAL-2.7G-99.98

 🕧Hora: {{ctx.execution_time}}  {{ctx.result.execution_time}}

 Área: Networking 

 🔔Mensaje Alerta: El enlace ha dejado de responder. Responder correo a telecomunicaciones@udistrital.edu.co 

 Ingrese aquí para más información: https://72dfe17217744236af40cc31b704a664.us-central1.gcp.cloud.es.io:9243/s/distrital/app/uptime#"""
        }
      }
    }
  },
  "transform": {
    "script": {
      "source": "HashMap result = new HashMap(); result.result = ctx.payload.aggregations.metricAgg.value; return result;",
      "lang": "painless",
      "params": {
        "threshold": 0
      }
    }
  }
}

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