mirror of
https://github.com/Security-Onion-Solutions/securityonion.git
synced 2025-12-06 17:22:49 +01:00
Update Elastic clear utility script
This commit is contained in:
@@ -21,15 +21,33 @@ Security Onion Elastic Clear
|
|||||||
-y Skip interactive mode
|
-y Skip interactive mode
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
while getopts "h:y" OPTION
|
while getopts "h:cdely" OPTION
|
||||||
do
|
do
|
||||||
case $OPTION in
|
case $OPTION in
|
||||||
h)
|
h)
|
||||||
usage
|
usage
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
|
c)
|
||||||
|
DELETE_CASES_DATA=1
|
||||||
|
SKIP=1
|
||||||
|
;;
|
||||||
|
d)
|
||||||
|
DONT_STOP_SERVICES=1
|
||||||
|
SKIP=1
|
||||||
|
;;
|
||||||
|
e)
|
||||||
|
DELETE_ELASTALERT_DATA=1
|
||||||
|
SKIP=1
|
||||||
|
;;
|
||||||
|
l)
|
||||||
|
DELETE_LOG_DATA=1
|
||||||
|
SKIP=1
|
||||||
|
;;
|
||||||
y)
|
y)
|
||||||
|
DELETE_CASES_DATA=1
|
||||||
|
DELETE_ELASTALERT_DATA=1
|
||||||
|
DELETE_LOG_DATA=1
|
||||||
SKIP=1
|
SKIP=1
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
@@ -54,41 +72,83 @@ if [ $SKIP -ne 1 ]; then
|
|||||||
if [ "$INPUT" != "AGREE" ] ; then exit 0; fi
|
if [ "$INPUT" != "AGREE" ] ; then exit 0; fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check to see if Logstash are running
|
|
||||||
|
if [ -z "$DONT_STOP_SERVICES" ]; then
|
||||||
|
# Stop Elastic Agent
|
||||||
|
for i in $(pgrep elastic-agent | grep -v grep); do
|
||||||
|
kill -9 $i;
|
||||||
|
done
|
||||||
|
|
||||||
|
# Check to see if Elastic Fleet, Logstash, Elastalert are running
|
||||||
|
EF_ENABLED=$(so-status | grep elastic-fleet)
|
||||||
LS_ENABLED=$(so-status | grep logstash)
|
LS_ENABLED=$(so-status | grep logstash)
|
||||||
EA_ENABLED=$(so-status | grep elastalert)
|
EA_ENABLED=$(so-status | grep elastalert)
|
||||||
|
|
||||||
|
if [ ! -z "$EF_ENABLED" ]; then
|
||||||
|
/usr/sbin/so-elastic-fleet-stop
|
||||||
|
fi
|
||||||
|
|
||||||
if [ ! -z "$LS_ENABLED" ]; then
|
if [ ! -z "$LS_ENABLED" ]; then
|
||||||
|
|
||||||
/usr/sbin/so-logstash-stop
|
/usr/sbin/so-logstash-stop
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -z "$EA_ENABLED" ]; then
|
if [ ! -z "$EA_ENABLED" ]; then
|
||||||
|
|
||||||
/usr/sbin/so-elastalert-stop
|
/usr/sbin/so-elastalert-stop
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Delete data
|
if [ ! -z "$DELETE_CASES_DATA" ]; then
|
||||||
echo "Deleting data..."
|
# Delete Cases data
|
||||||
|
echo "Deleting Cases data..."
|
||||||
INDXS=$(curl -K /opt/so/conf/elasticsearch/curl.config -s -XGET -k -L https://{{ NODEIP }}:9200/_cat/indices?v | egrep 'logstash|elastalert|so-' | awk '{ print $3 }')
|
INDXS=$(/usr/sbin/so-elasticsearch-query _cat/indices?h=index | grep "so-case")
|
||||||
for INDX in ${INDXS}
|
for INDX in ${INDXS}
|
||||||
do
|
do
|
||||||
curl -K /opt/so/conf/elasticsearch/curl.config-XDELETE -k -L https://"{{ NODEIP }}:9200/${INDX}" > /dev/null 2>&1
|
echo "Deleting $INDX"
|
||||||
|
/usr/sbin/so-elasticsearch-query ${INDX} -XDELETE > /dev/null 2>&1
|
||||||
done
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Delete Elastalert data
|
||||||
|
if [ ! -z "$DELETE_ELASTALERT_DATA" ]; then
|
||||||
|
# Delete Elastalert data
|
||||||
|
echo "Deleting Elastalert data..."
|
||||||
|
INDXS=$(/usr/sbin/so-elasticsearch-query _cat/indices?h=index | grep "elastalert")
|
||||||
|
for INDX in ${INDXS}
|
||||||
|
do
|
||||||
|
echo "Deleting $INDX"
|
||||||
|
/usr/sbin/so-elasticsearch-query ${INDX} -XDELETE > /dev/null 2>&1
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Delete log data
|
||||||
|
if [ ! -z "$DELETE_LOG_DATA" ]; then
|
||||||
|
echo "Deleting log data ..."
|
||||||
|
DATASTREAMS=$(/usr/sbin/so-elasticsearch-query _data_stream | jq -r '.[] |.[].name')
|
||||||
|
for DATASTREAM in ${DATASTREAMS}
|
||||||
|
do
|
||||||
|
# Delete the data stream
|
||||||
|
echo "Deleting $DATASTREAM..."
|
||||||
|
/usr/sbin/so-elasticsearch-query _data_stream/${DATASTREAM} -XDELETE > /dev/null 2>&1
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$DONT_STOP_SERVICES" ]; then
|
||||||
#Start Logstash
|
#Start Logstash
|
||||||
if [ ! -z "$LS_ENABLED" ]; then
|
if [ ! -z "$LS_ENABLED" ]; then
|
||||||
|
|
||||||
/usr/sbin/so-logstash-start
|
/usr/sbin/so-logstash-start
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -z "$EA_ENABLED" ]; then
|
#Start Elastic Fleet
|
||||||
|
if [ ! -z "$EF_ENABLED" ]; then
|
||||||
/usr/sbin/so-elastalert-start
|
/usr/sbin/so-elastic-fleet-start
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
#Start Elastalert
|
||||||
|
if [ ! -z "$EA_ENABLED" ]; then
|
||||||
|
/usr/sbin/so-elastalert-start
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Start Elastic Agent
|
||||||
|
/usr/bin/elastic-agent restart
|
||||||
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user