forked from SumoLogic/sumologic-collector-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·107 lines (89 loc) · 3.47 KB
/
run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/bash
SUMO_GENERATE_USER_PROPERTIES=${SUMO_GENERATE_USER_PROPERTIES:=true}
SUMO_ACCESS_ID=${SUMO_ACCESS_ID:=$1}
SUMO_ACCESS_KEY=${SUMO_ACCESS_KEY:=$2}
SUMO_RECEIVER_URL=${SUMO_RECEIVER_URL:=https://collectors.sumologic.com}
SUMO_COLLECTOR_NAME=${SUMO_COLLECTOR_NAME_PREFIX:='collector_container-'}${SUMO_COLLECTOR_NAME:=`cat /etc/hostname`}
SUMO_SOURCES_JSON=${SUMO_SOURCES_JSON:=/etc/sumo-sources.json}
SUMO_SYNC_SOURCES=${SUMO_SYNC_SOURCES:=false}
generate_user_properties_file() {
if [ -z "$SUMO_ACCESS_ID" ] || [ -z "$SUMO_ACCESS_KEY" ]; then
echo "FATAL: Please provide credentials, either via the SUMO_ACCESS_ID and SUMO_ACCESS_KEY environment variables,"
echo " or as the first two command line arguments!"
exit 1
fi
# Support using env as replacement within sources.
# Gather all template files
declare -a TEMPLATE_FILES
if [ -r "${SUMO_SOURCES_JSON}.tmpl" ]; then
TEMPLATE_FILES+=("${SUMO_SOURCES_JSON}.tmpl")
fi
if [ -d "${SUMO_SOURCES_JSON}" ]; then
for f in $(find ${SUMO_SOURCES_JSON} -name '*.tmpl'); do TEMPLATE_FILES+=(${f}); done
fi
for from in "${TEMPLATE_FILES[@]}"
do
# Replace all env variables and remove .tmpl extension
to=${from%.*}
echo > ${to}
if [ $? -ne 0 ]; then
echo "FATAL: unable to write to ${to}"
exit 1
fi
OLD_IFS=$IFS
IFS=$'\n'
while read line; do
echo $(eval echo "\"${line//\"/\\\"}\"") >> ${to}
done <${from}
IFS=${OLD_IFS}
echo "INFO: Replacing environment variables from ${from} into ${to}"
done
if [ ! -e "${SUMO_SOURCES_JSON}" ]; then
echo "FATAL: Unable to find $SUMO_SOURCES_JSON - please make sure you include it in your image!"
exit 1
fi
if [ "${SUMO_SYNC_SOURCES}" == "true" ]; then
SUMO_SYNC_SOURCES=${SUMO_SOURCES_JSON}
unset SUMO_SOURCES_JSON
else
unset SUMO_SYNC_SOURCES
fi
# Supported user.properties configuration parameters
# More information https://help.sumologic.com/Send_Data/Installed_Collectors/stu_user.properties
declare -A SUPPORTED_OPTIONS
SUPPORTED_OPTIONS=(
["SUMO_ACCESS_ID"]="accessid"
["SUMO_ACCESS_KEY"]="accesskey"
["SUMO_RECEIVER_URL"]="url"
["SUMO_COLLECTOR_NAME"]="name"
["SUMO_SOURCES_JSON"]="sources"
["SUMO_SYNC_SOURCES"]="syncSources"
["SUMO_PROXY_HOST"]="proxyHost"
["SUMO_PROXY_PORT"]="proxyPort"
["SUMO_PROXY_USER"]="proxyUser"
["SUMO_PROXY_PASSWORD"]="proxyPassword"
["SUMO_PROXY_NTLM_DOMAIN" ]="proxyNtlmDomain"
["SUMO_CLOBBER"]="clobber"
["SUMO_DISABLE_SCRIPTS"]="disableScriptSource"
["SUMO_JAVA_MEMORY_INIT"]="wrapper.java.initmemory"
["SUMO_JAVA_MEMORY_MAX"]="wrapper.java.maxmemory"
)
USER_PROPERTIES=""
for key in "${!SUPPORTED_OPTIONS[@]}"
do
value=${!key}
if [ -n "${value}" ]; then
USER_PROPERTIES="${USER_PROPERTIES}${SUPPORTED_OPTIONS[$key]}=${value}\n"
fi
done
if [ -n "${USER_PROPERTIES}" ]; then
echo -e ${USER_PROPERTIES} > /opt/SumoCollector/config/user.properties
fi
}
# If the user didn't supply their own user.properties file, generate it
$SUMO_GENERATE_USER_PROPERTIES && {
generate_user_properties_file
}
# The -t flag will force the collector to run as ephemeral
# Don't leave our shell hanging around
exec /opt/SumoCollector/collector console -- -t