-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgo.sh
executable file
·409 lines (338 loc) · 9.11 KB
/
go.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
#!/bin/bash
#
# Wrapper script to set up Splunk Helath Check
#
# To test this script out, set up a webserver:
#
# python -m SimpleHTTPServer 8000
#
# Then run the script:
#
# bash <(curl -s localhost:8000/go.sh)
#
# Errors are fatal
set -e
#
# Set default values for our vars
#
TARGETS="${TARGETS:-google.com,8.8.8.8,1.1.1.1}"
SPLUNK_PASSWORD=${SPLUNK_PASSWORD:-password1}
SPLUNK_DATA=${SPLUNK_DATA:-splunk-data}
SPLUNK_PORT=${SPLUNK_PORT:-8000}
SPLUNK_DEVEL=${SPLUNK_DEVEL:-}
ETC_HOSTS=${ETC_HOSTS:-no}
DOCKER_NAME=${DOCKER_NAME:-splunk-network-health-check}
DOCKER_RM=${DOCKER_RM:-1}
SSL_CERT=${SSL_CERT:-}
SSL_KEY=${SSL_KEY:-}
if test "$SPLUNK_START_ARGS" != "--accept-license"
then
echo "! "
echo "! You need to accept the Splunk License in order to continue."
echo "! Please restart this container with SPLUNK_START_ARGS set to \"--accept-license\" "
echo "! as follows: "
echo "! "
echo "! SPLUNK_START_ARGS=--accept-license"
echo "! "
exit 1
fi
#
# Yes, I am aware that the password checking logic is a duplicate of what's in the
# container's entry point script. But if someone is running Splunk Health Check through this
# script, I want bad passwords to cause failure as soon as possible, because it's
# easier to troubleshoot here than through Docker logs.
#
if test "$SPLUNK_PASSWORD" == "password"
then
echo "! "
echo "! "
echo "! Cowardly refusing to set the password to 'password'. Please set a different password."
echo "! "
echo "! If you need help picking a secure password, there's an app for that:"
echo "! "
echo "! https://diceware.dmuth.org/"
echo "! "
echo "! "
exit 1
fi
PASSWORD_LEN=${#SPLUNK_PASSWORD}
if test $PASSWORD_LEN -lt 8
then
echo "! "
echo "! "
echo "! Admin password needs to be at least 8 characters!"
echo "! "
echo "! Password specified: ${SPLUNK_PASSWORD}"
echo "! "
echo "! "
exit 1
fi
if ! test $(which docker)
then
echo "! "
echo "! Docker not found in the system path!"
echo "! "
echo "! Please double-check that Docker is installed on your system, otherwise you "
echo "! can go to https://www.docker.com/ to download Docker. "
echo "! "
exit 1
fi
#
# Catch targets with spaces in it (old style)
#
case "$TARGETS" in
*\ *)
echo "! "
echo "! You cannot have strings in the target string: ${TARGETS}"
echo "! "
echo "! Instead, try commas between targets. "
echo "! e.g. TARGETS=google.com,8.8.8.8"
echo "! "
echo "! "
exit 1
;;
esac
#
# Sanity check
#
if test "$ETC_HOSTS" != "no"
then
if test ! -f ${ETC_HOSTS}
then
echo "! Unable to read file '${ETC_HOSTS}' specfied in \$ETC_HOSTS!"
exit 1
fi
fi
#
# Start forming our command
#
CMD="docker run \
--privileged \
-p ${SPLUNK_PORT}:8000 \
-e TARGETS=${TARGETS} \
-e SPLUNK_PASSWORD=${SPLUNK_PASSWORD} \
"
#
# If SPLUNK_DATA is no, we're not exporting it.
# Useful for re-importing everything every time.
#
if test "${SPLUNK_DATA}" != "no"
then
CMD="$CMD -v $(pwd)/${SPLUNK_DATA}:/data "
fi
if test "${DOCKER_NAME}"
then
CMD="${CMD} --name ${DOCKER_NAME}"
fi
#
# Sanity check to make sure that both SSL_CERT *and* SSL_KEY are specified.
#
if test "${SSL_CERT}"
then
if test ! "${SSL_KEY}"
then
echo "! "
echo "! \$SSL_CERT is specified but not \$SSL_KEY!"
echo "! "
exit 1
fi
elif test "${SSL_KEY}"
then
if test ! "${SSL_CERT}"
then
echo "! "
echo "! \$SSL_KEY is specified but not \$SSL_CERT!"
echo "! "
exit 1
fi
fi
#
# Sanity check to make sure that SSL cert and key are both readable
#
if test "${SSL_CERT}"
then
if test ! -r "${SSL_CERT}"
then
echo "! "
echo "! SSL Cert File ${SSL_CERT} does not exist or is not readable!"
echo "! "
exit 1
fi
if test ! -r "${SSL_KEY}"
then
echo "! "
echo "! SSL Cert File ${SSL_KEY} does not exist or is not readable!"
echo "! "
exit 1
fi
fi
#
# If SSL files don't start with a leading slash, prefix with the full path
#
if test "${SSL_CERT}"
then
if test ${SSL_CERT:0:1} != "/"
then
SSL_CERT="$(pwd)/${SSL_CERT}"
fi
if test ${SSL_KEY:0:1} != "/"
then
SSL_KEY="$(pwd)/${SSL_KEY}"
fi
CMD="${CMD} -v ${SSL_CERT}:/ssl.cert -v ${SSL_KEY}:/ssl.key"
fi
#
# Only disable --rm if DOCKER_RM is set to "no".
# We want --rm action by default, since we also have a default name
# and don't want name conflicts.
#
if test "$DOCKER_RM" == "no"
then
DOCKER_RM=""
fi
if test "${DOCKER_RM}"
then
CMD="${CMD} --rm"
else
CMD="${CMD} --restart unless-stopped "
fi
if test "${ETC_HOSTS}" != "no"
then
CMD="$CMD -v $(pwd)/${ETC_HOSTS}:/etc/hosts.extra "
fi
if test ! "$SPLUNK_DEVEL"
then
CMD="${CMD} -d "
fi
if test "$SPLUNK_START_ARGS" -a "$SPLUNK_START_ARGS" != 0
then
CMD="${CMD} -e SPLUNK_START_ARGS=${SPLUNK_START_ARGS}"
fi
if test "$SPLUNK_DEVEL"
then
CMD="${CMD} -it"
CMD="${CMD} -v $(pwd):/mnt "
#
# In devel mode, we'll mount the splunk-lab/ directory to the app directory
# here, and the entrypoint.sh script will create the local/ symlink
# (with build.sh removing said symlink before building any images)
#
CMD="${CMD} -v $(pwd)/splunk-app:/opt/splunk/etc/apps/Network-Monitor "
CMD="${CMD} -e SPLUNK_DEVEL=${SPLUNK_DEVEL} "
fi
DOCKER_V="-v $(pwd)/user-prefs.conf:/opt/splunk/etc/users/admin/user-prefs/local/user-prefs.conf"
CMD="${CMD} ${DOCKER_V}"
#
# Create our user-prefs.conf which will be pulled into Splunk at runtime
# to set the default app.
#
cat > user-prefs.conf << EOF
#
# Created by Splunk Network Health Check
#
[general]
default_namespace = Network-Monitor
EOF
IMAGE="dmuth1/splunk-network-health-check"
#IMAGE="splunk-network-health-check" # Debugging/testing
CMD="${CMD} ${IMAGE}"
if test "$SPLUNK_DEVEL"
then
CMD="${CMD} bash"
fi
echo
echo " ____ _ _ _ _ _ _ "
echo " / ___| _ __ | |_ _ _ __ | | __ | \ | | ___| |___ _____ _ __| | __ "
echo " \___ \| '_ \| | | | | '_ \| |/ / | \| |/ _ \ __\ \ /\ / / _ \| '__| |/ / "
echo " ___) | |_) | | |_| | | | | < | |\ | __/ |_ \ V V / (_) | | | < "
echo " |____/| .__/|_|\__,_|_| |_|_|\_\ |_| \_|\___|\__| \_/\_/ \___/|_| |_|\_\ "
echo " |_| "
echo " _ _ _ _ _ ____ _ _ "
echo " | | | | ___ __ _| | |_| |__ / ___| |__ ___ ___| | __ "
echo " | |_| |/ _ \/ _\` | | __| '_ \ | | | '_ \ / _ \/ __| |/ / "
echo " | _ | __/ (_| | | |_| | | | | |___| | | | __/ (__| < "
echo " |_| |_|\___|\__,_|_|\__|_| |_| \____|_| |_|\___|\___|_|\_\ "
echo
echo "# "
if test ! "${SPLUNK_DEVEL}"
then
echo "# About to run Splunk Health Check!"
else
echo "# About to run Splunk Health Check IN DEVELOPMENT MODE!"
fi
echo "# "
echo "# Before we do, please take a few seconds to ensure that your options are correct:"
echo "# "
echo "# URL: https://localhost:${SPLUNK_PORT} (Change with \$SPLUNK_PORT)"
echo "# Login/password: admin/${SPLUNK_PASSWORD} (Change with \$SPLUNK_PASSWORD)"
echo "# "
echo "# Targets to ping: ${TARGETS} (Override with \$TARGETS)"
echo "# "
if test "${SPLUNK_DATA}" != "no"
then
echo "# Indexed data will be stored in: ${SPLUNK_DATA} (Change with \$SPLUNK_DATA, disable with SPLUNK_DATA=no)"
else
echo "# Indexed data WILL NOT persist. (Change by setting \$SPLUNK_DATA)"
fi
if test "$DOCKER_NAME"
then
echo "# Docker container name: ${DOCKER_NAME}"
else
echo "# Docker container name: (Set with \$DOCKER_NAME, if you like)"
fi
if test "$DOCKER_RM"
then
echo "# Removing container at exit? YES (Disable with \$DOCKER_RM=no)"
else
echo "# Removing container at exit? NO (Set with \$DOCKER_RM=1)"
fi
if test "$ETC_HOSTS" != "no"
then
echo "# /etc/hosts addition: ${ETC_HOSTS} (Disable with \$ETC_HOSTS=no)"
else
echo "# /etc/hosts addition: NO (Set with \$ETC_HOSTS=filename)"
fi
if test "${SSL_CERT}"
then
echo "# SSL Cert and Key? YES (${SSL_CERT}, ${SSL_KEY})"
else
echo "# SSL Cert and Key? NO (Specify with \$SSL_CERT and \$SSL_KEY)"
fi
echo "# "
if test "$SPLUNK_PASSWORD" == "password1"
then
echo "# "
echo "# PLEASE NOTE THAT YOU USED THE DEFAULT PASSWORD"
echo "# "
echo "# If you are testing this on localhost, you are probably fine."
echo "# If you are not, then PLEASE use a different password for safety."
echo "# If you have trouble coming up with a password, I have a utility "
echo "# at https://diceware.dmuth.org/ which will help you pick a password "
echo "# that can be remembered."
echo "# "
fi
echo "> "
echo "> Press ENTER to run Splunk Health Check with the above settings, or ctrl-C to abort..."
echo "> "
read
echo "# "
echo "# Launching container..."
echo "# "
if test "$SPLUNK_DEVEL"
then
$CMD
elif test ! "$DOCKER_NAME"
then
ID=$($CMD)
SHORT_ID=$(echo $ID | cut -c-4)
else
ID=$($CMD)
SHORT_ID=$DOCKER_NAME
echo "#"
echo "# Running Docker container with ID: ${ID}"
echo "#"
echo "# Inspect container logs with: docker logs ${SHORT_ID}"
echo "#"
echo "# Kill container with: docker kill ${SHORT_ID}"
echo "#"
fi