I am trying to build a watcher which alerts me when the following occurs:
- Event A (based on three tags and field result="InvalidPassword" for username=y) occurs three times.
- Event A is followed by event B (based on three tags and field result="BlockedUser" for username=y) occurs once.
I have the following but this does not seem to work
{
"trigger": {
"schedule": {
"interval": "10s"
}
},
"input": {
"chain":{
"inputs": [
{
"InvalidPassword": {
"search": {
"request": {
"body": {
"size": 0,
"query": {
"bool": {
"must": [
{
"range": {
"@timestamp": {
"gte": "now-2m"
}
}
},
{
"match_phrase": {
"tags": "login"
}
},
{
"match_phrase": {
"result": "InvalidPassword"
}
}
]
}
},
"aggs": {
"byUser": {
"terms": {
"field": "username"
}
}
}
},
"indices": [
"filebeat-*"
]
}
}
}
},
{
"BlockedUser": {
"search": {
"request": {
"body": {
"size": 0,
"query": {
"bool": {
"must": [
{
"range": {
"@timestamp": {
"gte": "now-2m"
}
}
},
{
"match_phrase": {
"tags": "login"
}
},
{
"match_phrase": {
"result": "BlockedUser"
}
}
]
}
},
"aggs": {
"byUser": {
"terms": {
"field": "username"
}
}
}
},
"indices": [
"filebeat-*"
]
}
}
}
}
]
}
},
"condition": {
"script": {
"source": "return ctx.payload.InvalidPassword.username == ctx.payload.BlockedUser.username"
}
},
"actions": {
//my action
}
}