Skip to content

Commit

Permalink
work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
mmguero committed Oct 9, 2023
1 parent a328e0e commit d884125
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 88 deletions.
3 changes: 1 addition & 2 deletions api/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/bin/sh

echo "Giving OpenSearch time to start..."
"${APP_HOME}"/opensearch_status.sh 2>&1 && echo "OpenSearch is running!"
"${APP_HOME}"/opensearch_status.sh

exec "$@"
59 changes: 0 additions & 59 deletions arkime/scripts/arkime-needs-upgrade.sh

This file was deleted.

22 changes: 7 additions & 15 deletions arkime/scripts/initarkime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ if ( [[ ! -f "$CERT_FILE" ]] || [[ ! -f "$KEY_FILE" ]] ) && [[ -x /usr/local/bin
popd >/dev/null 2>&1
fi

echo "Giving OpenSearch time to start..."
/opt/opensearch_status.sh 2>&1 && echo "OpenSearch is running!"
echo "Giving $OPENSEARCH_PRIMARY time to start..."
/opt/opensearch_status.sh 2>&1 && echo "$OPENSEARCH_PRIMARY is running!"

# download and/or update geo updates
$ARKIME_DIR/bin/arkime_update_geo.sh
Expand All @@ -55,7 +55,7 @@ fi
# initialize the contents of the OpenSearch database if it has never been initialized (ie., the users_v# table hasn't been created)
if [[ $(curl "${CURL_CONFIG_PARAMS[@]}" -fs -XGET -H'Content-Type: application/json' "${OPENSEARCH_URL}/_cat/indices/arkime_users_v*" | wc -l) < 1 ]]; then

echo "Initializing OpenSearch database..."
echo "Initializing $OPENSEARCH_PRIMARY database..."

$ARKIME_DIR/db/db.pl $DB_SSL_FLAG "${OPENSEARCH_URL_FULL}" initnoprompt

Expand Down Expand Up @@ -86,23 +86,15 @@ if [[ $(curl "${CURL_CONFIG_PARAMS[@]}" -fs -XGET -H'Content-Type: application/j

curl "${CURL_CONFIG_PARAMS[@]}" -sS --output /dev/null -H'Content-Type: application/json' -XPOST "${OPENSEARCH_URL}/arkime_users/_update/$MALCOLM_USERNAME" -d "@$ARKIME_DIR/etc/user_settings.json"

echo -e "\nOpenSearch database initialized!\n"
echo -e "\n$OPENSEARCH_PRIMARY database initialized!\n"

else
echo "OpenSearch database previously initialized!"
echo "$OPENSEARCH_PRIMARY database previously initialized!"
echo

if /opt/arkime-needs-upgrade.sh 2>&1; then
echo "OpenSearch database needs to be upgraded for $ARKIME_VERSION!"
$ARKIME_DIR/db/db.pl $DB_SSL_FLAG "${OPENSEARCH_URL_FULL}" upgradenoprompt
echo "OpenSearch database upgrade complete!"
echo
$ARKIME_DIR/db/db.pl $DB_SSL_FLAG "${OPENSEARCH_URL_FULL}" upgradenoprompt --ifneeded
echo "$OPENSEARCH_PRIMARY database is up-to-date for Arkime version $ARKIME_VERSION!"

else
echo "OpenSearch database is up-to-date for Arkime version $ARKIME_VERSION!"
echo

fi # if /opt/moloch-needs-upgrade.sh
fi # if/else OpenSearch database initialized

# increase OpenSearch max shards per node from default if desired
Expand Down
3 changes: 1 addition & 2 deletions arkime/scripts/wipearkime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
[[ ${OPENSEARCH_SSL_CERTIFICATE_VERIFICATION:-"false"} != "true" ]] && DB_SSL_FLAG="--insecure" || DB_SSL_FLAG=""
OPENSEARCH_URL_FULL="$(grep -Pi '^elasticsearch\s*=' $ARKIME_DIR/etc/config.ini | cut -d'=' -f2-)"

echo "Checking OpenSearch..."
/opt/opensearch_status.sh 2>&1 && echo "OpenSearch is running!"
/opt/opensearch_status.sh

#Wipe is the same initalize except it keeps users intact
echo WIPE | /opt/arkime/db/db.pl $DB_SSL_FLAG "${OPENSEARCH_URL_FULL}" wipe
Expand Down
18 changes: 9 additions & 9 deletions dashboards/scripts/create-arkime-sessions-index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ OPENSEARCH_SECONDARY=${OPENSEARCH_SECONDARY:-""}
# is the argument to automatically create this index enabled?
if [[ "$CREATE_OS_ARKIME_SESSION_INDEX" = "true" ]] ; then

# give OpenSearch time to start before configuring dashboards
/data/opensearch_status.sh >/dev/null 2>&1
# give OpenSearch time to start and Arkime to get its template created before configuring dashboards
/data/opensearch_status.sh -l arkime_sessions3_template >/dev/null 2>&1

for LOOP in primary secondary; do

Expand Down Expand Up @@ -81,7 +81,7 @@ if [[ "$CREATE_OS_ARKIME_SESSION_INDEX" = "true" ]] ; then
# have we not not already created the index pattern?
if [[ "$LOOP" != "primary" ]] || ! curl "${CURL_CONFIG_PARAMS[@]}" -L --silent --output /dev/null --fail -XGET "$DASHB_URL/api/saved_objects/index-pattern/$INDEX_PATTERN_ID" ; then

echo "OpenSearch ($LOOP) is running at \"${OPENSEARCH_URL_TO_USE}\"!"
echo "$DATASTORE_TYPE ($LOOP) is running at \"${OPENSEARCH_URL_TO_USE}\"!"

# register the repo name/path for opensearch snapshots (but don't count this an unrecoverable failure)
if [[ "$LOOP" == "primary" ]] && [[ "$OPENSEARCH_LOCAL" == "true" ]]; then
Expand Down Expand Up @@ -196,7 +196,7 @@ if [[ "$CREATE_OS_ARKIME_SESSION_INDEX" = "true" ]] ; then
-d"{\"attributes\":{\"title\":\"$IDX_NAME\",\"timeFieldName\":\"$IDX_TIME_FIELD\"}}" 2>&1 || true
done

echo "Importing OpenSearch Dashboards saved objects..."
echo "Importing $DATASTORE_TYPE Dashboards saved objects..."

# install default dashboards
for i in /opt/dashboards/*.json; do
Expand All @@ -211,7 +211,7 @@ if [[ "$CREATE_OS_ARKIME_SESSION_INDEX" = "true" ]] ; then
curl "${CURL_CONFIG_PARAMS[@]}" -L --silent --output /dev/null --show-error -XPOST "$DASHB_URL/api/$DASHBOARDS_URI_PATH/dashboards/import?force=true" -H "$XSRF_HEADER:true" -H 'Content-type:application/json' -d "@$i"
done

echo "OpenSearch Dashboards saved objects import complete!"
echo "$DATASTORE_TYPE Dashboards saved objects import complete!"

if [[ "$DATASTORE_TYPE" == "opensearch" ]]; then
# some features and tweaks like anomaly detection, alerting, etc. only exist in opensearch
Expand Down Expand Up @@ -240,7 +240,7 @@ if [[ "$CREATE_OS_ARKIME_SESSION_INDEX" = "true" ]] ; then
/data/opensearch_status.sh -w >/dev/null 2>&1
sleep 60

echo "Creating OpenSearch anomaly detectors..."
echo "Creating $DATASTORE_TYPE anomaly detectors..."

# Create anomaly detectors here
for i in /opt/anomaly_detectors/*.json; do
Expand Down Expand Up @@ -268,9 +268,9 @@ if [[ "$CREATE_OS_ARKIME_SESSION_INDEX" = "true" ]] ; then
curl "${CURL_CONFIG_PARAMS[@]}" -L --silent --output /dev/null --show-error -XDELETE "$OPENSEARCH_URL_TO_USE/_plugins/_anomaly_detection/detectors/$DUMMY_DETECTOR_ID" -H "$XSRF_HEADER:true" -H 'Content-type:application/json'
fi

echo "OpenSearch anomaly detectors creation complete!"
echo "$DATASTORE_TYPE anomaly detectors creation complete!"

echo "Creating OpenSearch alerting objects..."
echo "Creating $DATASTORE_TYPE alerting objects..."

# Create notification/alerting objects here

Expand All @@ -284,7 +284,7 @@ if [[ "$CREATE_OS_ARKIME_SESSION_INDEX" = "true" ]] ; then
curl "${CURL_CONFIG_PARAMS[@]}" -L --silent --output /dev/null --show-error -XPOST "$OPENSEARCH_URL_TO_USE/_plugins/_alerting/monitors" -H "$XSRF_HEADER:true" -H 'Content-type:application/json' -d "@$i"
done

echo "OpenSearch alerting objects creation complete!"
echo "$DATASTORE_TYPE alerting objects creation complete!"

fi # DATASTORE_TYPE == opensearch
fi # stuff to only do for primary
Expand Down
17 changes: 16 additions & 1 deletion shared/bin/opensearch_status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ ENCODING="utf-8"

WAIT_FOR_LOG_DATA=0
WAIT_FOR_TEMPLATE=
while getopts 'vwt:' OPTION; do
WAIT_FOR_TEMPLATE_LEGACY=
while getopts 'vwt:l:' OPTION; do
case "$OPTION" in
v)
set -x
Expand All @@ -29,6 +30,10 @@ while getopts 'vwt:' OPTION; do
WAIT_FOR_TEMPLATE=${OPTARG}
;;

l)
WAIT_FOR_TEMPLATE_LEGACY=${OPTARG}
;;

?)
echo "script usage: $(basename $0) [-v] [-w] [-t <template name>]" >&2
exit 1
Expand Down Expand Up @@ -70,6 +75,16 @@ done

echo "$OPENSEARCH_PRIMARY is up and healthy at "$OPENSEARCH_URL"" >&2

if [[ -n "$WAIT_FOR_TEMPLATE_LEGACY" ]]; then
sleep 1
echo "Waiting until $OPENSEARCH_PRIMARY has legacy template \"$WAIT_FOR_TEMPLATE_LEGACY\"..." >&2
until ( curl "${CURL_CONFIG_PARAMS[@]}" -fs -H'Content-Type: application/json' -XGET "$OPENSEARCH_URL/_template/$WAIT_FOR_TEMPLATE_LEGACY" 2>/dev/null | grep -q mappings ); do
sleep 5
done
echo "$OPENSEARCH_PRIMARY legacy template \"$WAIT_FOR_TEMPLATE_LEGACY\" exists" >&2
sleep 5
fi

if [[ -n "$WAIT_FOR_TEMPLATE" ]]; then
sleep 1
echo "Waiting until $OPENSEARCH_PRIMARY has index template \"$WAIT_FOR_TEMPLATE\"..." >&2
Expand Down

0 comments on commit d884125

Please sign in to comment.