I have a problem with this watcher, I need to get the number of samples of an index, that is, the count of the documents sent by heartbeat to kibana and send an email every day with the number of documents that arrived that day, for example this:
This is code in watcher:
{
"trigger": {
"schedule": {
"daily": {
"at": [
"14:00"
]
}
}
},
"input": {
"search": {
"request": {
"search_type": "query_then_fetch",
"indices": [
"heartbeat*"
],
"rest_total_hits_as_int": true,
"body": {
"size": 1,
"query": {
"bool":{
"filter": [
{
"range": {
"@timestamp": {
"gte": "now-1d/d",
"lt": "now/d"
}
}
}
],
"aggs": {
"terms": {
"field": "_index"
}
}
}
}
}
}
}
},
"condition": {
"compare": {
"ctx.payload.hits.total": {
"gte": 1
}
}
},
"actions": {
"email_1": {
"email": {
"profile": "standard",
"attach_data": {
"format": "yaml"
},
"to": [
"victor.vera@megadvantage.com",
"juan.jaramillo@megadvantage.com"
],
"bcc": [
"juancho.jaramillo16@gmail.com"
],
"subject": "{{ctx.metadata.name}}",
"body": {
"text": """Buen dia,
⚠La herramienta de monitoreo a funcionado correctamente en las ultimas 24 horas {{ctx.payload.hits.total}}
{{ctx. payload.result}}
Estado: UP🟢
🕧Hora: {{ctx.payload.time_triggered}} {{ctx.result.execution_time}}
Área: Networking
🔔Mensaje Alerta: Por favor no responder a este mensaje
"""
}
}
}
},
"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"
}
}
}
Error:
{
"watch_id": "_inlined_",
"node": "ELuSGxpSRICZb2ZHJp4paA",
"state": "failed",
"user": "elastic",
"status": {
"state": {
"active": true,
"timestamp": "2021-04-19T16:45:41.246Z"
},
"actions": {
"email_1": {
"ack": {
"timestamp": "2021-04-19T16:45:41.246Z",
"state": "awaits_successful_execution"
}
}
},
"execution_state": "failed",
"version": -1
},
"trigger_event": {
"type": "manual",
"triggered_time": "2021-04-19T16:45:41.246Z",
"manual": {
"schedule": {
"scheduled_time": "2021-04-19T16:45:41.246Z"
}
}
},
"input": {
"search": {
"request": {
"search_type": "query_then_fetch",
"indices": [
"heartbeat*"
],
"rest_total_hits_as_int": true,
"body": {
"size": 1,
"query": {
"bool": {
"filter": [
{
"range": {
"@timestamp": {
"gte": "now-1d/d",
"lt": "now/d"
}
}
}
],
"aggs": {
"terms": {
"field": "_index"
}
}
}
}
}
}
}
},
"condition": {
"compare": {
"ctx.payload.hits.total": {
"gte": 1
}
}
},
"metadata": {
"name": "Estado herramienta monitoreo",
"xpack": {
"type": "json"
}
},
"result": {
"execution_time": "2021-04-19T16:45:41.246Z",
"execution_duration": 0,
"input": {
"type": "search",
"status": "failure",
"error": {
"root_cause": [
{
"type": "x_content_parse_exception",
"reason": "[1:96] [bool] unknown field [aggs]"
}
],
"type": "x_content_parse_exception",
"reason": "[1:96] [bool] unknown field [aggs]"
},
"search": {
"request": {
"search_type": "query_then_fetch",
"indices": [
"heartbeat*"
],
"rest_total_hits_as_int": true,
"body": {
"size": 1,
"query": {
"bool": {
"filter": [
{
"range": {
"@timestamp": {
"gte": "now-1d/d",
"lt": "now/d"
}
}
}
],
"aggs": {
"terms": {
"field": "_index"
}
}
}
}
}
}
}
},
"actions": []
},
"messages": [
"failed to execute watch input"
]
}