mirror of
https://github.com/Security-Onion-Solutions/securityonion.git
synced 2025-12-06 17:22:49 +01:00
Better error handling and state file management
This commit is contained in:
@@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
. /usr/sbin/so-common
|
. /usr/sbin/so-common
|
||||||
|
|
||||||
|
|
||||||
RETURN_CODE=0
|
RETURN_CODE=0
|
||||||
ELASTICSEARCH_HOST=$1
|
ELASTICSEARCH_HOST=$1
|
||||||
ELASTICSEARCH_PORT=9200
|
ELASTICSEARCH_PORT=9200
|
||||||
@@ -15,41 +14,51 @@ ELASTICSEARCH_PORT=9200
|
|||||||
ELASTICSEARCH_INGEST_PIPELINES="/opt/so/conf/elasticsearch/ingest/"
|
ELASTICSEARCH_INGEST_PIPELINES="/opt/so/conf/elasticsearch/ingest/"
|
||||||
|
|
||||||
# Wait for ElasticSearch to initialize
|
# Wait for ElasticSearch to initialize
|
||||||
|
|
||||||
if [ ! -f /opt/so/state/espipelines.txt ]; then
|
if [ ! -f /opt/so/state/espipelines.txt ]; then
|
||||||
|
echo "State file /opt/so/state/espipelines.txt not found. Running so-elasticsearch-pipelines."
|
||||||
|
|
||||||
echo -n "Waiting for ElasticSearch..."
|
echo -n "Waiting for ElasticSearch..."
|
||||||
COUNT=0
|
COUNT=0
|
||||||
ELASTICSEARCH_CONNECTED="no"
|
ELASTICSEARCH_CONNECTED="no"
|
||||||
while [[ "$COUNT" -le 240 ]]; do
|
while [[ "$COUNT" -le 240 ]]; do
|
||||||
curl -K /opt/so/conf/elasticsearch/curl.config -k --output /dev/null --silent --head --fail -L https://"$ELASTICSEARCH_HOST":"$ELASTICSEARCH_PORT"
|
curl -K /opt/so/conf/elasticsearch/curl.config -k --output /dev/null --silent --head --fail -L https://"$ELASTICSEARCH_HOST":"$ELASTICSEARCH_PORT"
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
ELASTICSEARCH_CONNECTED="yes"
|
ELASTICSEARCH_CONNECTED="yes"
|
||||||
echo "connected!"
|
echo "connected!"
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
((COUNT+=1))
|
((COUNT+=1))
|
||||||
sleep 1
|
sleep 1
|
||||||
echo -n "."
|
echo -n "."
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
if [ "$ELASTICSEARCH_CONNECTED" == "no" ]; then
|
if [ "$ELASTICSEARCH_CONNECTED" == "no" ]; then
|
||||||
echo
|
echo
|
||||||
echo -e "Connection attempt timed out. Unable to connect to ElasticSearch. \nPlease try: \n -checking log(s) in /var/log/elasticsearch/\n -running 'sudo docker ps' \n -running 'sudo so-elastic-restart'"
|
echo -e "Connection attempt timed out. Unable to connect to ElasticSearch. \nPlease try: \n -checking log(s) in /var/log/elasticsearch/\n -running 'sudo docker ps' \n -running 'sudo so-elastic-restart'"
|
||||||
echo
|
echo
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd ${ELASTICSEARCH_INGEST_PIPELINES}
|
cd ${ELASTICSEARCH_INGEST_PIPELINES}
|
||||||
|
|
||||||
echo "Loading pipelines..."
|
echo "Loading pipelines..."
|
||||||
for i in .[a-z]* *; do echo $i; RESPONSE=$(curl -K /opt/so/conf/elasticsearch/curl.config -k -XPUT -L https://${ELASTICSEARCH_HOST}:${ELASTICSEARCH_PORT}/_ingest/pipeline/$i -H 'Content-Type: application/json' -d@$i 2>/dev/null); echo $RESPONSE; if [[ "$RESPONSE" == *"error"* ]]; then RETURN_CODE=1; fi; done
|
for i in .[a-z]* *;
|
||||||
|
do echo $i;
|
||||||
|
RESPONSE=$(curl -K /opt/so/conf/elasticsearch/curl.config -k -XPUT -L https://${ELASTICSEARCH_HOST}:${ELASTICSEARCH_PORT}/_ingest/pipeline/$i -H 'Content-Type: application/json' -d@$i 2>/dev/null);
|
||||||
|
ERRORS=$(echo $RESPONSE | grep -E "Connection attempt timed out|error");
|
||||||
|
if ! [ -z "$ERRORS" ]; then
|
||||||
|
echo $ERRORS;
|
||||||
|
RETURN_CODE=1;
|
||||||
|
fi;
|
||||||
|
done
|
||||||
echo
|
echo
|
||||||
|
|
||||||
cd - >/dev/null
|
cd - >/dev/null
|
||||||
|
|
||||||
if [[ "$RETURN_CODE" != "1" ]]; then
|
if [[ "$RETURN_CODE" != "1" ]]; then
|
||||||
touch /opt/so/state/espipelines.txt
|
touch /opt/so/state/espipelines.txt
|
||||||
fi
|
else
|
||||||
else
|
echo "Errors were detected. This script will run again during the next application of the state."
|
||||||
|
fi
|
||||||
|
else
|
||||||
exit $RETURN_CODE
|
exit $RETURN_CODE
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user