Skip to content

Commit 390b525

Browse files
Multiple updates
- Synchronized date format across shell scripts - Added logic to remove multiple deployment client configurations in apps that are not put into a desired app or are not configured with the correct deployment server URI - Introducing the capability to define the desired deployment server URI and deployed app to the inputs.conf file to do proper comparisons
1 parent dd77cdc commit 390b525

File tree

7 files changed

+64
-34
lines changed

7 files changed

+64
-34
lines changed

bin/appContext.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,11 @@
22
## Grab the current app context
33
SCRIPT_PATH=$(realpath $0)
44
APP_PATH=$(dirname ${SCRIPT_PATH})
5+
SCRIPT_NAME=$(echo ${SCRIPT_PATH} | sed "s|${APP_PATH}/||")
6+
APP_NAME=$(echo ${SCRIPT_PATH} | sed "s|${SPLUNK_HOME}/etc/apps" | sed "s|/${SCRIPT_NAME}||")
7+
8+
## Capture the deploymentServerUri from the inputs stanza
9+
if [ "${SCRIPT_NAME}" = "dsRemove.sh" ]; then
10+
CORRECT_DS=$(${SPLUNK_HOME}/bin/splunk btool --app=$APP_NAME inputs list script://./bin/$SCRIPT_NAME | grep deploymentServerUri | sed "s/deploymentServerUri = //")
11+
CORRECT_APP=$(${SPLUNK_HOME}/bin/splunk btool --app=$APP_NAME inputs list script://./bin/$SCRIPT_NAME | grep deploymentClientApp | sed "s/deploymentClientApp = //")
12+
fi

bin/dateTimeCorrect.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ RESTART_DATETIME_CHECK="$SPLUNK_HOME/etc/restartdatetime.txt"
77

88
### Determine if a correction is necessary
99
if [ $DATETIME_DIFFERENCE = 0 ]; then
10-
echo "$(date +"%Y-%m-%d %H:%M:%S.%3N") ${HOSTNAME}: The datetime.xml is the updated version. No correction necessary..."
10+
echo "$(date -R) ${HOSTNAME}: The datetime.xml is the updated version. No correction necessary..."
1111
else
12-
echo "$(date +"%Y-%m-%d %H:%M:%S.%3N") ${HOSTNAME}: The datetime.xml file needs to be updated. Updating..."
12+
echo "$(date -R) ${HOSTNAME}: The datetime.xml file needs to be updated. Updating..."
1313
mv $EXISTING_DATETIME $EXISTING_DATETIME.$(date +"%m%d%Y")
1414
cp $REFERENCE_DATETIME $EXISTING_DATETIME
1515
touch $RESTART_DATETIME_CHECK

bin/dsRemove.sh

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,44 @@
11
#!/bin/bash
2+
3+
## Run appContext to capture details from inputs stanza
4+
. $(dirname $0)/appContext.sh
5+
26
### Look for a deploymentclient.conf file in the apps directory and define the path to the restartds.txt file
7+
CORRECT_APP_DEPLOYED=$(find $SPLUNK_HOME/etc/apps -type d -name ${CORRECT_APP} | wc -l)
38
DEPLOYED_APP=$(find $SPLUNK_HOME/etc/apps -type f -name deploymentclient.conf | wc -l)
49
LOCAL=$(find $SPLUNK_HOME/etc/system/local -type f -name deploymentclient.conf | wc -l)
510
RESTART_CHECK=$SPLUNK_HOME/etc/restartds.txt
611

7-
### Check variables and take action accordingly
12+
## Capture the current deployment server URI from btool
13+
BTOOL=$(${SPLUNK_HOME}/bin/splunk btool deploymentclient list --debug | grep targetUri)
14+
CURRENT_DS=$(echo ${BTOOL} | awk '{print $4}')
15+
CURRENT_APP_PATH=$(echo ${BTOOL} | awk '{print $1}' | sed "s/\/(default|local)\/deploymentclient.conf//"
16+
CURRENT_APP_NAME=$(echo ${CURRENT_APP_PATH} | sed "s|${SPLUNK_HOME}\/etc\/apps\/||")
17+
818
## If there is no deployed app with a deployment client, bail out
919
if [ $DEPLOYED_APP = "0" ]; then
10-
echo $(date -R) $HOSTNAME: No deploymentclient.conf detected in $SPLUNK_HOME/etc/apps. Bailing out so the fowarder doesn\'t get orphaned.
11-
exit 1
12-
## If more than one deploymentclient.conf file is deployed, bail out
13-
elif [ $DEPLOYED_APP > "1" ]; then
14-
echo $(date -R) $HOSTNAME: Multiple deploymentclient.conf detected in $SPLUNK_HOME/etc/apps. Check all deployed apps to ensure you\'re only using one.
15-
exit 1
16-
## If there's 1 local config and 1 deployed config, remove the local one and set the checkpoint file
17-
elif [ $LOCAL = "1" ] & [ $DEPLOYED_APP = "1" ]; then
18-
# Remove the deploymentclient.conf from $SPLUNK_HOME/etc/system/local
19-
rm -f $SPLUNK_HOME/etc/system/local/deploymentclient.conf > /dev/null 2>&1
20-
echo $(date -R) $HOSTNAME: Removed deploymentclient.conf from local system.
21-
touch $RESTART_CHECK
22-
else
23-
echo $(date -R) $HOSTNAME: No deploymentclient.conf correction necessary.
20+
echo "$(date -R) $HOSTNAME: No deploymentclient.conf detected in $SPLUNK_HOME/etc/apps. Bailing out so the fowarder doesn\'t get orphaned."
21+
echo "$(date -R) $HOSTNAME: Deploy \"${CURRENT_APP_NAME}\" to this server to correct this issue."
22+
exit 1
23+
fi
24+
25+
## If more than one deploymentclient.conf file is deployed, nuke the wrong app and set the checkpoint file
26+
if [ $DEPLOYED_APP > "1" ]; then
27+
echo "$(date -R) $HOSTNAME: Multiple apps with deploymentclient.conf detected in $SPLUNK_HOME/etc/apps."
28+
echo "$(date -R) $HOSTNAME: Removing ${CURRENT_APP_NAME} to ensure there is no contention with ${CORRECT_APP}"
29+
rm -rf "${CURRENT_APP_PATH}"
30+
touch $RESTART_CHECK
31+
fi
32+
33+
## If there's 1 local config, remove the local one and set the checkpoint file
34+
if [ $LOCAL = "1" ]; then
35+
# Remove the deploymentclient.conf from $SPLUNK_HOME/etc/system/local
36+
rm -f $SPLUNK_HOME/etc/system/local/deploymentclient.conf > /dev/null 2>&1
37+
echo $(date -R) $HOSTNAME: Removed deploymentclient.conf from local system.
38+
touch $RESTART_CHECK
39+
fi
40+
41+
## If the current deployment server is configured and the correct app is installed, bail out
42+
if [ "${CURRENT_DS}" = "${CORRECT_DS}" ] && [ "${CURRENT_APP}" = "${CORRECT_APP}" ]; then
43+
echo $(date -R) $HOSTNAME: No deploymentclient.conf correction necessary.
2444
fi

bin/hostCorrect.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ RESTART_SERVER_CHECK="$SPLUNK_HOME/etc/restartserver.txt"
99
if [ -f "$INPUTS_FILE" ]; then
1010
CURRENT_HOST=$(cat "$INPUTS_FILE" | grep "host =" | awk '{printf $3}')
1111
else
12-
echo "$(date +"%Y-%m-%d %H:%M:%S.%3N") ${HOSTNAME}: Inputs file is missing from local config. Creating it now..."
12+
echo "$(date -R) ${HOSTNAME}: Inputs file is missing from local config. Creating it now..."
1313
touch "$INPUTS_FILE"
1414
echo "[default]
1515
host = IntentionallyWrong" > "$INPUTS_FILE"
@@ -19,7 +19,7 @@ fi
1919
### Check for the existence of a serverName value and insert one if one isn't configured
2020
CURRENT_SERVER=$(cat "$SERVER_FILE" | grep "serverName =" | awk '{printf $3}')
2121
if [ -z "$CURRENT_SERVER" ]; then
22-
echo "$(date +"%Y-%m-%d %H:%M:%S.%3N") ${HOSTNAME}: There is no serverName value configured. Inserting one..."
22+
echo "$(date -R) ${HOSTNAME}: There is no serverName value configured. Inserting one..."
2323
echo "
2424
[general]
2525
serverName = IntentionallyWrong" >> "$SERVER_FILE"
@@ -28,17 +28,17 @@ fi
2828

2929
### Check the current values of the configured files and correct if necessary
3030
if [ "$CURRENT_HOST" = "$HOSTNAME" ]; then
31-
echo "$(date +"%Y-%m-%d %H:%M:%S.%3N") ${HOSTNAME}: Currently configured host name: $CURRENT_HOST. No correction necessary..."
31+
echo "$(date -R) ${HOSTNAME}: Currently configured host name: $CURRENT_HOST. No correction necessary..."
3232
else
33-
echo "$(date +"%Y-%m-%d %H:%M:%S.%3N") ${HOSTNAME}: Currently configured host name: $CURRENT_HOST. Reconfiguring inputs.conf..."
33+
echo "$(date -R) ${HOSTNAME}: Currently configured host name: $CURRENT_HOST. Reconfiguring inputs.conf..."
3434
cp "$INPUTS_FILE" "$INPUTS_FILE".$(date +"%m%d%Y")
3535
sed -i "s/$CURRENT_HOST/$HOSTNAME/" "$INPUTS_FILE"
3636
touch "$RESTART_INPUT_CHECK"
3737
fi
3838
if [ "$CURRENT_SERVER" = "$HOSTNAME" ]; then
39-
echo "$(date +"%Y-%m-%d %H:%M:%S.%3N") ${HOSTNAME}: Currently configured server name: $CURRENT_SERVER. No correction necessary..."
39+
echo "$(date -R) ${HOSTNAME}: Currently configured server name: $CURRENT_SERVER. No correction necessary..."
4040
else
41-
echo "$(date +"%Y-%m-%d %H:%M:%S.%3N") ${HOSTNAME}: Currently configured server name: $CURRENT_SERVER. Reconfiguring server.conf..."
41+
echo "$(date -R) ${HOSTNAME}: Currently configured server name: $CURRENT_SERVER. Reconfiguring server.conf..."
4242
cp "$SERVER_FILE" "$SERVER_FILE".$(date +"%m%d%Y")
4343
sed -i "s/$CURRENT_SERVER/$HOSTNAME/" "$SERVER_FILE"
4444
touch "$RESTART_SERVER_CHECK"

bin/regenGUID.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ RESTART_CHECK="$SPLUNK_HOME/etc/restartguid.txt"
55

66
### Check if there is already a backup of the instance.cfg and take the appropriate action.
77
if [ -f "${INSTANCE}.*" ]; then
8-
echo "$(date +"%Y-%m-%d %H:%M:%S.%3N") ${HOSTNAME}: Instance GUID has already been changed."
8+
echo "$(date -R) ${HOSTNAME}: Instance GUID has already been changed."
99
CHECK="0"
1010
else
11-
echo "$(date +"%Y-%m-%d %H:%M:%S.%3N") ${HOSTNAME}: Backing up instance.cfg"
11+
echo "$(date -R) ${HOSTNAME}: Backing up instance.cfg"
1212
mv "$INSTANCE" "${INSTANCE}.$(date +"%m%d%Y")"
1313
touch $RESTART_CHECK
14-
fi
14+
fi

bin/restart.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
2-
### Source the appPath script to pull proper app context
3-
source appContext.sh
2+
### Source the appContext script to pull proper app context
3+
. $(dirname $0)/appContext.sh
44

55
### Configure the path to the restart_check.txt file on the system
66
RESTARTINPUT="$SPLUNK_HOME/etc/restartinput.txt"
@@ -11,8 +11,8 @@ RESTARTDATETIME="$SPLUNK_HOME/etc/restartdatetime.txt"
1111

1212
### If any files exist, restart forwarder
1313
if [ -f "$RESTARTINPUT" ] || [ -f "$RESTARTSERVER" ] || [ -f "$RESTARTDS" ] || [ -f "$RESTARTGUID" ] || [ -f "$RESTARTDATETIME" ]; then
14-
echo "$(date +"%Y-%m-%d %H:%M:%S.%3N") ${HOSTNAME}: One or more settings has been changed."
15-
echo "$(date +"%Y-%m-%d %H:%M:%S.%3N") ${HOSTNAME}: Restarting forwarder."
14+
echo "$(date -R) ${HOSTNAME}: One or more settings has been changed."
15+
echo "$(date -R) ${HOSTNAME}: Restarting forwarder."
1616
if [ -f "$RESTARTINPUT" ]; then
1717
rm -f "$RESTARTINPUT"
1818
fi
@@ -28,8 +28,8 @@ if [ -f "$RESTARTINPUT" ] || [ -f "$RESTARTSERVER" ] || [ -f "$RESTARTDS" ] || [
2828
if [ -f "$RESTARTDATETIME" ]; then
2929
rm -f "$RESTARTDATETIME"
3030
fi
31-
rm -f "${APP_PATH}/DeleteMeToRestart"
31+
rm -f "${APP_PATH}/bin/DeleteMeToRestart"
3232
else
33-
echo "$(date +"%Y-%m-%d %H:%M:%S.%3N") ${HOSTNAME}: No settings have been changed."
34-
echo "$(date +"%Y-%m-%d %H:%M:%S.%3N") ${HOSTNAME}: No restart required."
33+
echo "$(date -R) ${HOSTNAME}: No settings have been changed."
34+
echo "$(date -R) ${HOSTNAME}: No restart required."
3535
fi

default/inputs.conf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ index = _internal
5151
sourcetype = ds_remove:output
5252
interval = -1
5353
source = ds_remove_output
54+
deploymentServerUri =
55+
deploymentClientApp =
5456

5557
[powershell://dsRemove]
5658
disabled = 1
@@ -88,4 +90,4 @@ disabled = 1
8890
index = _internal
8991
sourcetype = pw_change:output
9092
interval = -1
91-
source = pw_change_output
93+
source = pw_change_output

0 commit comments

Comments
 (0)