Skip to content

Instantly share code, notes, and snippets.

@ppf2
Created August 6, 2018 23:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ppf2/445a208a74eefbb44d4e71e2c7a1c8fe to your computer and use it in GitHub Desktop.
Save ppf2/445a208a74eefbb44d4e71e2c7a1c8fe to your computer and use it in GitHub Desktop.
Case 00240888
PUT _xpack/watcher/watch/alex_watch
{
"trigger": {
"schedule": {
"interval": "5s"
}
},
"input": {
"search": {
"request": {
"indices": [
"*wineventlog*"
],
"body": {
"_source": [
"@timestamp",
"host",
"event_data.IpAddress",
"event_data.TargetUserName"
],
"aggs": {
"byUser": {
"terms": {
"field": "event_data.TargetUserName.keyword",
"min_doc_count": 3
},
"aggs": {
"ip": {
"terms": {
"field": "event_data.IpAddress.keyword"
}
}
}
}
}
}
}
}
},
"condition": {
"array_compare": {
"ctx.payload.aggregations.byUser.buckets": {
"path": "doc_count",
"gte": {
"value": 3
}
}
}
},
"actions": {
"index_payload": {
"transform": {
"script": "String test='\n'; for (HashMap o : ctx.payload.aggregations.byUser.buckets) { test += o.get('key') + ':\n'; for (HashMap i: o.ip.buckets) { test += i.get('key') + '\n'; }} return test;"
},
"logging": {
"text": "{{ctx.payload._value}}"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment