Hi Thanks
Please find the code which I have done,
its Kibana 7 and I am using Watcher,
now bellow code, I can see its Executing but the problem is, its not using log trailing, what i meant is example if its runs at 10.00 PM, its showing
"logged_text": "There are 60 documents in your index. Threshold is 1."
Now when its runs again after 1 hour example 11.00 PM, its showing the same result
I want to get alert for NEW occurence , but its keep showing the same Occurence, so if No new occurence from last Exeucte, should not it show 0 ?
basically, i want to get Alert for every new Occurence , if the number is same (60) (this is are past occurence) , then no need to sent alert. if this become 61 then sent alert
How can i do this ?
The code : -
{
"trigger": {
"schedule": {
"interval": "60m"
}
},
"input": {
"search": {
"request": {
"search_type": "query_then_fetch",
"indices": [
"*"
],
"rest_total_hits_as_int": true,
"body": {
"size": 0,
"query": {
"match": {
"message": "ALARM:ALARM_POWER_OFF"
}
}
}
}
}
},
"condition": {
"compare": {
"ctx.payload.hits.total": {
"gte": 1
}
}
},
"actions": {
"my-logging-action": {
"logging": {
"level": "info",
"text": "There are {{ctx.payload.hits.total}} documents in your index. Threshold is 1."
}
}
}
}
Execution Result (Simulation Result)
{
"watch_id": "_inlined_",
"node": "fWMM4t9NS2mHJoQRnN1bGQ",
"state": "executed",
"user": "elastic",
"status": {
"state": {
"active": true,
"timestamp": "2019-05-01T06:40:15.721Z"
},
"last_checked": "2019-05-01T06:40:15.721Z",
"last_met_condition": "2019-05-01T06:40:15.721Z",
"actions": {
"my-logging-action": {
"ack": {
"timestamp": "2019-05-01T06:40:15.721Z",
"state": "ackable"
},
"last_execution": {
"timestamp": "2019-05-01T06:40:15.721Z",
"successful": true
},
"last_successful_execution": {
"timestamp": "2019-05-01T06:40:15.721Z",
"successful": true
}
}
},
"execution_state": "executed",
"version": -1
},
"trigger_event": {
"type": "manual",
"triggered_time": "2019-05-01T06:40:15.721Z",
"manual": {
"schedule": {
"scheduled_time": "2019-05-01T06:40:15.721Z"
}
}
},
"input": {
"search": {
"request": {
"search_type": "query_then_fetch",
"indices": [
"*"
],
"rest_total_hits_as_int": true,
"body": {
"size": 0,
"query": {
"match": {
"message": "ALARM:ALARM_POWER_OFF"
}
}
}
}
}
},
"condition": {
"compare": {
"ctx.payload.hits.total": {
"gte": 1
}
}
},
"metadata": {
"name": "POWER_CUT",
"xpack": {
"type": "json"
}
},
"result": {
"execution_time": "2019-05-01T06:40:15.721Z",
"execution_duration": 10,
"input": {
"type": "search",
"status": "success",
"payload": {
"_shards": {
"total": 28,
"failed": 0,
"successful": 28,
"skipped": 0
},
"hits": {
"hits": [],
"total": 60,
"max_score": null
},
"took": 9,
"timed_out": false
},
"search": {
"request": {
"search_type": "query_then_fetch",
"indices": [
"*"
],
"rest_total_hits_as_int": true,
"body": {
"size": 0,
"query": {
"match": {
"message": "ALARM:ALARM_POWER_OFF"
}
}
}
}
}
},
"condition": {
"type": "compare",
"status": "success",
"met": true,
"compare": {
"resolved_values": {
"ctx.payload.hits.total": 60
}
}
},
"actions": [
{
"id": "my-logging-action",
"type": "logging",
"status": "simulated",
"logging": {
"logged_text": "There are 60 documents in your index. Threshold is 1."
}
}
]
},
"messages": []
}