How to make a condition that is met if the state of execution of a watch is executed, to send me an email, but only if the condition is met.
{
"trigger": {
"schedule": {
"interval": "24h"
}
},
"input": {
"chain":{
"inputs":[
{
"first":{
"watch_id": "iGCYyGCcTPKAXtFYnqXWJA_elasticsearch_cluster_status",
"state" : "executed"
},
"second":{
"transform" : {
"script" : "return [ 'watch_id' : ctx.payload.first.watch_id ]"
}
}
}
]
},
"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": "if (ctx.payload.aggregations.metricAgg.value = params.threshold) && if (ctx.payload.first.watch_id = 'iGCYyGCcTPKAXtFYnqXWJA_elasticsearch_cluster_status' ) && if (ctx.payload.first.state = 'executed') { return true; } return false;",
"lang": "painless",
"params": {
"threshold": 0
}
}
},
"actions": {
"email_1": {
"email": {
"profile": "standard",
"attach_data": {
"format": "yaml"
},
"to": [
"victor.vera@megadvantage.com",
"juan.jaramillo@megadvantage.com",
"juancho.jaramillo16@gmail.com"
],
"subject": "{{ctx.metadata.name}} ",
"body": {
"text": """Buen dia, Adjunto registro del reporte.
⚠️ALERTA NODO!!! El siguiente enlace ha restablecido la conexión.
Estado: UP🟢
Nombre del Enlace: 01-1-CAV30328203-DATOS-PPAL-2.7G-99.98
🕧Hora: {{ctx.payload.time_triggered}} {{ctx.result.execution_time}}
Área: Networking
🔔Mensaje Alerta: El enlace ha vuelto a 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": "return [ 'time_triggered': Instant.ofEpochMilli(ctx.trigger.triggered_time.getMillis()).atZone(ZoneId.of('America/Bogota')).format(DateTimeFormatter.ofPattern('YYYY-MM-dd HH:mm:ss')) ];",
"lang": "painless"
}
}
}