From 45d3438d1873cab236a14f25bb3bf5762d9c278b Mon Sep 17 00:00:00 2001 From: reyesj2 <94730068+reyesj2@users.noreply.github.com> Date: Thu, 16 Jan 2025 17:33:14 -0600 Subject: [PATCH 1/5] update ingest pipeline for imported logs Signed-off-by: reyesj2 <94730068+reyesj2@users.noreply.github.com> --- salt/elasticsearch/files/ingest/suricata.alert | 2 +- salt/manager/tools/sbin/soup | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/salt/elasticsearch/files/ingest/suricata.alert b/salt/elasticsearch/files/ingest/suricata.alert index 68e0a5cb3..c92a406b4 100644 --- a/salt/elasticsearch/files/ingest/suricata.alert +++ b/salt/elasticsearch/files/ingest/suricata.alert @@ -1,7 +1,7 @@ { "description" : "suricata.alert", "processors" : [ - { "set": { "field": "_index", "value": "logs-suricata.alerts-so" } }, + { "set": { "if": "ctx.data_stream?.dataset != null && ctx.data_stream?.dataset == 'suricata'", "field": "_index", "value": "logs-suricata.alerts-so" } }, { "set": { "field": "tags","value": "alert" }}, { "rename":{ "field": "message2.alert", "target_field": "rule", "ignore_failure": true } }, { "rename":{ "field": "rule.signature", "target_field": "rule.name", "ignore_failure": true } }, diff --git a/salt/manager/tools/sbin/soup b/salt/manager/tools/sbin/soup index fc0c7aca4..23c59eb6b 100755 --- a/salt/manager/tools/sbin/soup +++ b/salt/manager/tools/sbin/soup @@ -527,6 +527,10 @@ post_to_2.4.111() { post_to_2.4.120() { update_elasticsearch_index_settings + + # Manually rollover suricata alerts index to ensure data_stream.dataset expected mapping is set to 'suricata' + rollover_index "logs-suricata.alerts-so" + POSTVERSION=2.4.120 } @@ -805,6 +809,19 @@ ASSIST_EOF fi } +rollover_index() { + idx=$1 + exists=$(curl -K /opt/so/conf/elasticsearch/curl.config -s -o /dev/null -w "%{http_code}" -k -L -H "Content-Type: application/json" "https://localhost:9200/$idx") + + rollover=$(curl -K /opt/so/conf/elasticsearch/curl.config -s -o /dev/null -w "%{http_code}" -k -L -H "Content-Type: application/json" "https://localhost:9200/$idx/_rollover" -XPOST) + + if [[ $rollover -eq 200 ]]; then + echo "Successfully triggered rollover for $idx..." + else + echo "Could not trigger rollover for $idx..." + fi +} + suricata_idstools_migration() { #Backup the pillars for idstools mkdir -p /nsm/backup/detections-migration/idstools From d573c0922d5c14f92beeda18e911b36f82745695 Mon Sep 17 00:00:00 2001 From: reyesj2 <94730068+reyesj2@users.noreply.github.com> Date: Thu, 16 Jan 2025 18:25:06 -0600 Subject: [PATCH 2/5] add 2.4.111 -> postupgrade check Signed-off-by: reyesj2 <94730068+reyesj2@users.noreply.github.com> --- salt/manager/tools/sbin/soup | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/salt/manager/tools/sbin/soup b/salt/manager/tools/sbin/soup index 23c59eb6b..6264558fa 100755 --- a/salt/manager/tools/sbin/soup +++ b/salt/manager/tools/sbin/soup @@ -427,7 +427,8 @@ postupgrade_changes() { [[ "$POSTVERSION" == 2.4.80 ]] && post_to_2.4.90 [[ "$POSTVERSION" == 2.4.90 ]] && post_to_2.4.100 [[ "$POSTVERSION" == 2.4.100 ]] && post_to_2.4.110 - [[ "$POSTVERSION" == 2.4.110 ]] && post_to_2.4.120 + [[ "$POSTVERSION" == 2.4.110 ]] && post_to_2.4.111 + [[ "$POSTVERSION" == 2.4.111 ]] && post_to_2.4.120 true } From 9032d7d7bc90543d23278a7be3b5d8457885c92e Mon Sep 17 00:00:00 2001 From: reyesj2 <94730068+reyesj2@users.noreply.github.com> Date: Thu, 16 Jan 2025 18:48:31 -0600 Subject: [PATCH 3/5] any suricata.alert with event.imported: true remains in logs-import-so Signed-off-by: reyesj2 <94730068+reyesj2@users.noreply.github.com> --- salt/elasticsearch/files/ingest/suricata.alert | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/elasticsearch/files/ingest/suricata.alert b/salt/elasticsearch/files/ingest/suricata.alert index c92a406b4..9ee0acfd6 100644 --- a/salt/elasticsearch/files/ingest/suricata.alert +++ b/salt/elasticsearch/files/ingest/suricata.alert @@ -1,7 +1,7 @@ { "description" : "suricata.alert", "processors" : [ - { "set": { "if": "ctx.data_stream?.dataset != null && ctx.data_stream?.dataset == 'suricata'", "field": "_index", "value": "logs-suricata.alerts-so" } }, + { "set": { "if": "ctx.event?.imported != null && ctx.event?.imported != true", "field": "_index", "value": "logs-suricata.alerts-so" } }, { "set": { "field": "tags","value": "alert" }}, { "rename":{ "field": "message2.alert", "target_field": "rule", "ignore_failure": true } }, { "rename":{ "field": "rule.signature", "target_field": "rule.name", "ignore_failure": true } }, From 01a2e4cd4f4f950f0145d410a17686bdf383024d Mon Sep 17 00:00:00 2001 From: reyesj2 <94730068+reyesj2@users.noreply.github.com> Date: Fri, 17 Jan 2025 09:27:28 -0600 Subject: [PATCH 4/5] check for index existence before attemping rollover Signed-off-by: reyesj2 <94730068+reyesj2@users.noreply.github.com> --- salt/manager/tools/sbin/soup | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/salt/manager/tools/sbin/soup b/salt/manager/tools/sbin/soup index 6264558fa..5e52388ac 100755 --- a/salt/manager/tools/sbin/soup +++ b/salt/manager/tools/sbin/soup @@ -814,12 +814,16 @@ rollover_index() { idx=$1 exists=$(curl -K /opt/so/conf/elasticsearch/curl.config -s -o /dev/null -w "%{http_code}" -k -L -H "Content-Type: application/json" "https://localhost:9200/$idx") - rollover=$(curl -K /opt/so/conf/elasticsearch/curl.config -s -o /dev/null -w "%{http_code}" -k -L -H "Content-Type: application/json" "https://localhost:9200/$idx/_rollover" -XPOST) + if [[ $exists -eq 200 ]]; then + rollover=$(curl -K /opt/so/conf/elasticsearch/curl.config -s -o /dev/null -w "%{http_code}" -k -L -H "Content-Type: application/json" "https://localhost:9200/$idx/_rollover" -XPOST) - if [[ $rollover -eq 200 ]]; then - echo "Successfully triggered rollover for $idx..." + if [[ $rollover -eq 200 ]]; then + echo "Successfully triggered rollover for $idx..." + else + echo "Could not trigger rollover for $idx..." + fi else - echo "Could not trigger rollover for $idx..." + echo "Could not find index $idx..." fi } From 1396083b7da0804c061176e0f32236115cadd1c0 Mon Sep 17 00:00:00 2001 From: reyesj2 <94730068+reyesj2@users.noreply.github.com> Date: Fri, 17 Jan 2025 13:29:46 -0600 Subject: [PATCH 5/5] use so-elasticsearch-query where possible; simplify suricata.alerts index reroute Signed-off-by: reyesj2 <94730068+reyesj2@users.noreply.github.com> --- salt/elasticsearch/files/ingest/suricata.alert | 2 +- salt/manager/tools/sbin/soup | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/salt/elasticsearch/files/ingest/suricata.alert b/salt/elasticsearch/files/ingest/suricata.alert index 9ee0acfd6..9dd97e190 100644 --- a/salt/elasticsearch/files/ingest/suricata.alert +++ b/salt/elasticsearch/files/ingest/suricata.alert @@ -1,7 +1,7 @@ { "description" : "suricata.alert", "processors" : [ - { "set": { "if": "ctx.event?.imported != null && ctx.event?.imported != true", "field": "_index", "value": "logs-suricata.alerts-so" } }, + { "set": { "if": "ctx.event?.imported != true", "field": "_index", "value": "logs-suricata.alerts-so" } }, { "set": { "field": "tags","value": "alert" }}, { "rename":{ "field": "message2.alert", "target_field": "rule", "ignore_failure": true } }, { "rename":{ "field": "rule.signature", "target_field": "rule.name", "ignore_failure": true } }, diff --git a/salt/manager/tools/sbin/soup b/salt/manager/tools/sbin/soup index 5e52388ac..88dd5c9d8 100755 --- a/salt/manager/tools/sbin/soup +++ b/salt/manager/tools/sbin/soup @@ -812,10 +812,9 @@ ASSIST_EOF rollover_index() { idx=$1 - exists=$(curl -K /opt/so/conf/elasticsearch/curl.config -s -o /dev/null -w "%{http_code}" -k -L -H "Content-Type: application/json" "https://localhost:9200/$idx") - + exists=$(so-elasticsearch-query $idx -o /dev/null -w "%{http_code}") if [[ $exists -eq 200 ]]; then - rollover=$(curl -K /opt/so/conf/elasticsearch/curl.config -s -o /dev/null -w "%{http_code}" -k -L -H "Content-Type: application/json" "https://localhost:9200/$idx/_rollover" -XPOST) + rollover=$(so-elasticsearch-query $idx/_rollover -o /dev/null -w "%{http_code}" -XPOST) if [[ $rollover -eq 200 ]]; then echo "Successfully triggered rollover for $idx..."