I'm having this problem primarily with this monitor (and similar monitors that aggregate a large number of events).
This doesn't happen with other monitors, even though the configuration via sample_documents is the same.
I'm not currently using sample_documents in it for testing, but I need to get information about the user and IP address.
Before this I used a similar action mustache:
{
"monitor_id": "{{
ctx.trigger.id}}",
"monitor_name": "{{
ctx.trigger.name}}",
"trigger_severity": {{ctx.trigger.severity}},
"bucket_keys": "{{#ctx.newAlerts}}{{bucket_keys}}{{/ctx.newAlerts}}",
"wazuh_url":"{{#ctx.newAlerts}}
https://wazuh.ovp.ru/app/data-explorer/discover#?_a=(discover:(columns:!(_source),isDirty:!f,sort:!()),metadata:(indexPattern:'wazuh-alerts-*',view:discover))&_q=(filters:!(('$state':(store:appState),meta:(alias:!n,disabled:!f,index:'wazuh-alerts-*',key:
rule.id,negate:!f,params:(query:'100052'),type:phrase),query:(match_phrase:(rule.id:'100052'))),('$state':(store:appState),meta:(alias:!n,disabled:!f,index:'wazuh-alerts-*',key:data.win.eventdata.targetUserName,negate:!f,params:(query:{{bucket_keys}}),type:phrase),query:(match_phrase:(data.win.eventdata.targetUserName:{{bucket_keys}})))),query:(language:kuery,query:''))&_g=(filters:!(),refreshInterval:(pause:!t,value:0),time:(from:now-{{ctx.periodStart}},to:now)){{/ctx.newAlerts}}",
"raw": {
"src.ip":"{{#ctx.newAlerts}}{{#sample_documents}}{{_source.data.win.eventdata.ipAddress}} {{/sample_documents}}{{/ctx.newAlerts}}",
"agent.ip":"{{#ctx.newAlerts}}{{#sample_documents}}{{_source.agent.ip}} {{/sample_documents}}{{/ctx.newAlerts}}",
"
agent.name":"{{#ctx.newAlerts}}{{#sample_documents}}{{_
source.agent.name}} {{/sample_documents}}{{/ctx.newAlerts}}",
"src.username":"{{#ctx.newAlerts}}{{#sample_documents}}{{_source.data.win.eventdata.subjectUserName}} {{/sample_documents}}{{/ctx.newAlerts}}",
"dst.username":"{{#ctx.newAlerts}}{{#sample_documents}}{{_source.data.win.eventdata.targetUserName}} {{/sample_documents}}{{/ctx.newAlerts}}",
"rule":"{{#ctx.newAlerts}}{{#sample_documents}}{{_source.rule.description}} {{/sample_documents}}{{/ctx.newAlerts}}",
"periodStart": "{{ctx.periodStart}}",
"periodEnd": "{{ctx.periodEnd}}"
}
}
I use this template in all monitors, but in this one I get errors when it's triggered or when I try to send a test message. I attribute this to the fact that it's aggregating across a large number of events (>4000 hits).
I can attach you the JSON of my problematic monitor and you can tell me how to fix it.
For some reason, the monitor can't retrieve sample_documents. Maybe I don't fully understand how it works? Or how can I fix this?
I really need your help.
{
"name": "MS Windows: Успешное подключение одной УЗ с разных IP адресов",
"type": "monitor",
"monitor_type": "bucket_level_monitor",
"enabled": true,
"schedule": {
"period": {
"unit": "MINUTES",
"interval": 2
}
},
"inputs": [
{
"search": {
"indices": [
"wazuh-alerts-current"
],
"query": {
"size": 0,
"query": {
"bool": {
"filter": [
{
"range": {
"@timestamp": {
"from": "{{period_end}}||-400s",
"to": "{{period_end}}",
"include_lower": true,
"include_upper": true,
"format": "epoch_millis",
"boost": 1
}
}
},
{
"term": {
"rule.id": {
"value": "100014",
"boost": 1
}
}
}
],
"must_not": [
{
"terms": {
"data.win.eventdata.targetUserName": [
"ANONYMOUS LOGON",
"АНОНИМНЫЙ ВХОД"
],
"boost": 1
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
},
"aggregations": {
"users": {
"terms": {
"field": "data.win.eventdata.targetUserName",
"size": 1000,
"min_doc_count": 5,
"shard_min_doc_count": 0,
"show_term_doc_count_error": false,
"order": [
{
"_count": "desc"
},
{
"_key": "asc"
}
]
},
"aggregations": {
"unique_ips": {
"cardinality": {
"field": "data.win.eventdata.ipAddress"
}
}
}
}
}
}
}
}
],
"triggers": [
{
"bucket_level_trigger": {
"id": "xGdjA5sBoeamHjFYf3Hq",
"name": "MS Windows: Успешное подключение одной УЗ с разных рабочих станций",
"severity": "2",
"condition": {
"buckets_path": {
"uniq": "unique_ips.value"
},
"parent_bucket_path": "users",
"script": {
"source": "params.uniq > 3",
"lang": "painless"
},
"gap_policy": "skip"
},
"actions": [
{
"id": "notification810195",
"name": "Send to Yandex",
"destination_id": "X4L_5pkBS6jN-8SDuQFi",
"message_template": {
"source": "{\n \"chat_id\": \"1/0/191a25c4-b3f1-4e10-a6b1-a412c17b48e5\",\n \"text\": \"WAZUH\\n\\n- 🚨 Событие: {{ctx.monitor.name}}\\n- 🚨 Приоритет: {{ctx.trigger.severity}}\\n- ⏳ Время начала: {{ctx.periodStart}} UTC\\n- ⌛ Время окончания: {{ctx.periodEnd}} UTC {{#ctx.newAlerts}}\\n---\\n- 🙎♂️ Инициатор: {{bucket_keys}} {{/ctx.newAlerts}}\"\n}\n",
"lang": "mustache"
},
"throttle_enabled": false,
"subject_template": {
"source": "Alerting Notification action",
"lang": "mustache"
},
"action_execution_policy": {
"action_execution_scope": {
"per_alert": {
"actionable_alerts": [
"NEW"
]
}
}
}
},
{
"id": "notification644540",
"name": "Send_BD",
"destination_id": "yA92t5sBd-k2aqqxbrrG",
"message_template": {
"source": "{\n \"monitor_id\": \"{{ctx.trigger.id}}\",\n \"monitor_name\": \"{{ctx.trigger.name}}\",\n \"trigger_severity\": {{ctx.trigger.severity}},\n \"bucket_keys\": \"{{#ctx.newAlerts}}{{bucket_keys}}{{/ctx.newAlerts}}\",\n \"wazuh_url\":\"{{#ctx.newAlerts}}https://wazuh.ovp.ru/app/data-explorer/discover#?_a=(discover:(columns:!(agent.name,data.win.eventdata.targetUserName,data.win.eventdata.ipAddress,rule.id,rule.description),isDirty:!t,sort:!()),metadata:(indexPattern:'wazuh-alerts-*',view:discover))&_q=(filters:!(('$state':(store:appState),meta:(alias:!n,disabled:!f,index:'wazuh-alerts-*',key:rule.id,negate:!f,params:(query:'100014'),type:phrase),query:(match_phrase:(rule.id:'100014'))),('$state':(store:appState),meta:(alias:!n,disabled:!f,index:'wazuh-alerts-*',key:data.win.eventdata.targetUserName,negate:!f,params:(query:{{bucket_keys}}),type:phrase),query:(match_phrase:(data.win.eventdata.targetUserName:{{bucket_keys}})))),query:(language:kuery,query:''))&_g=(filters:!(),refreshInterval:(pause:!t,value:0),time:(from:now-1y,to:now)){{/ctx.newAlerts}}\",\n \"raw\": {\n \"src.ip\":\"{{#ctx.newAlerts}}{{bucket_keys}}{{/ctx.newAlerts}}\",\n \"periodStart\": \"{{ctx.periodStart}}\",\n \"periodEnd\": \"{{ctx.periodEnd}}\"\n }\n}",
"lang": "mustache"
},
"throttle_enabled": false,
"subject_template": {
"source": "Alerting Notification action",
"lang": "mustache"
},
"action_execution_policy": {
"action_execution_scope": {
"per_alert": {
"actionable_alerts": [
"NEW"
]
}
}
}
}
]
}
}
],
"ui_metadata": {
"schedule": {
"timezone": null,
"frequency": "interval",
"period": {
"unit": "MINUTES",
"interval": 2
},
"daily": 0,
"weekly": {
"tue": false,
"wed": false,
"thur": false,
"sat": false,
"fri": false,
"mon": false,
"sun": false
},
"monthly": {
"type": "day",
"day": 1
},
"cronExpression": "0 */1 * * *"
},
"monitor_type": "bucket_level_monitor",
"search": {
"searchType": "query",
"timeField": "@timestamp",
"aggregations": [],
"groupBy": [
"data.win.eventdata.targetUserName"
],
"bucketValue": 1,
"bucketUnitOfTime": "m",
"filters": [
{
"fieldName": [
{
"label": "rule.id",
"type": "keyword"
}
],
"fieldValue": "100014",
"operator": "is"
},
{
"fieldName": [
{
"label": "data.win.eventdata.workstationName",
"type": "keyword"
}
],
"fieldValue": "",
"operator": "is_not_null"
}
]
}
}
}