Thx for your response Alexander, I've only just seen this (email notification broken?).
I need now() in the input query, is that accessible ? I was imagining access to execution & scheduler time was only available in the response context, not the request context.
Either way, here is our watch pre-detokenisation (@env@) & with a few things replaced (by BLABLA) to make it possible to share. The condition & transform is still a WIP. The important bit is the script in the input search. Thats where I need to know now().
Thank you for any help you may have time to offer, hugely appreciated
{
"trigger": {
"schedule": {
"cron": "BLABLA"
}
},
"input": {
"search": {
"request": {
"indices": [
"logstash-@env@-*"
],
"body": {
"query": {
"bool": {
"must": [
{
"wildcard": {
"key": "BLABLA.latest.logs.crawl.log"
}
},
{
"match": {
"http_status": "200"
}
},
{
"match": {
"mimeType": "text/html"
}
},
{
"range": {
"@timestamp": {
"from": "now/d-7d",
"to" : "now"
}
}
},
{
"script": {
"script": {
"inline" : "doc['@timestamp'].date.getSecondOfDay() < DateTime.now().getSecondOfDay()",
"lang" : "painless"
}
}
}
]
}
},
"size": 0,
"aggregations": {
"jobs": {
"terms": {
"script": {
"inline" : "doc['key'].value.subSequence(26,doc['key'].value.length() - 22)",
"lang" : "painless"
}
},
"aggregations": {
"history": {
"date_range": {
"field": "@timestamp",
"format": "yyyy-MM-dd",
"ranges": [
{
"key" : "Yesterday",
"from": "now/d-1d",
"to": "now-1d"
},
{
"key" : "2 days ago",
"from": "now/d-2d",
"to": "now-2d"
},
{
"key" : "5 days ago",
"from": "now/d-5d",
"to": "now-5d"
},
{
"key" : "3 days ago",
"from": "now/d-3d",
"to": "now-3d"
},
{
"key" : "4 days ago",
"from": "now/d-4d",
"to": "now-4d"
},
{
"key" : "6 days ago",
"from": "now/d-6d",
"to": "now-6d"
},
{
"key" : "7 days ago",
"from": "now/d-7d",
"to": "now-7d"
}
]
},
"aggregations": {
"count": {
"value_count": {
"field": "key"
}
}
}
},
"current": {
"date_range": {
"field": "@timestamp",
"format": "yyyy-MM-dd",
"ranges": [
{
"key": "Today",
"from": "now/d",
"to": "now"
}
]
}
},
"avg_historic_daily_count": {
"avg_bucket": {
"buckets_path": "history>count"
}
}
}
}
}
}
}
}
},
"condition": {
"script": {
"inline": "historicCompare = ctx.payload.aggregations.jobs.buckets[0].current.buckets[0].doc_count / ctx.payload.aggregations.jobs.buckets[0].avg_historic_daily_count.value; return ( historicCompare < lowerThreshold ) || ( historicCompare > upperThreshold )",
"lang" : "groovy",
"params" : {
"upperThreshold" : @watcher.BLABLA.upperThreshold@,
"lowerThreshold" : @watcher.BLABLA.lowerThreshold@
}
}
},
"transform": {
"script" : {
"inline" : "avg_historic_daily_count = ctx.payload.aggregations.jobs.buckets[0].avg_historic_daily_count.value; return [ jobs : ctx.payload.aggregations.jobs.buckets.collect { [ avg_historic_daily_count : avg_historic_daily_count.round(), history : it.history.buckets.collect { [ day : it.key, doc_count : it.doc_count, color : ( ( it.doc_count / avg_historic_daily_count ) > upperThreshold || ( it.doc_count / avg_historic_daily_count ) < lowerThreshold ) ? '@watcher.to.slack.alert.colour@' : 'good' ] }, current : it.current.buckets.collect { [ day : it.key, doc_count : it.doc_count, color : ( ( it.doc_count / avg_historic_daily_count ) > upperThreshold || ( it.doc_count / avg_historic_daily_count ) < lowerThreshold ) ? '@watcher.to.slack.alert.colour@' : '#000000' ] } ] } ]",
"lang" : "groovy",
"params" : {
"upperThreshold" : @watcher.BLABLA.upperThreshold@,
"lowerThreshold" : @watcher.BLABLA.lowerThreshold@
}
}
},
"actions" : {
"notify-slack" : {
... cut short to fit inside 7000 post limit