-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path3scale-dump.sh
1439 lines (915 loc) · 36.7 KB
/
3scale-dump.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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
THREESCALE_PROJECT="${1}"
COMPRESS_UTIL="${2,,}"
CURRENT_DIR=$(dirname "$0")
# Avoid fetching information about any pod that is not a 3scale one
THREEESCALE_PODS=("3scale-amp-system-oracle" "3scale-operator" "apicast-production" "apicast-staging" "apicast-wildcard-router" "backend-cron" "backend-listener" "backend-redis" "backend-worker" "system-app" "system-memcache" "system-mysql" "system-redis" "system-resque" "system-sidekiq" "system-sphinx" "zync" "zync-que" "zync-database")
NOW=$(date -u +"%Y-%m-%d_%H-%M")
DUMP_DIR="${CURRENT_DIR}/3scale_dump-${NOW}"
DUMP_FILE="${DUMP_DIR}.tar"
#############
# Functions #
#############
print_error() {
if [[ -z ${MSG} ]]; then
echo -e "\n# Unknown Error #\n"
else
echo -e "\n# [Error] ${MSG} #\n"
fi
exit 1
}
create_dir() {
if [[ -z ${NEWDIR} ]]; then
MSG="Variable Not Found: NEWDIR"
print_error
elif [[ -z ${SINGLE_FILE} ]]; then
MSG="Variable Not Found: SINGLE_FILE"
print_error
else
if [[ ! -d ${DUMP_DIR}/${NEWDIR} ]]; then
MKDIR=$(mkdir -pv ${DUMP_DIR}/${NEWDIR} 2>&1)
echo -e "\t${MKDIR}"
if [[ ! -d ${DUMP_DIR}/${NEWDIR} ]]; then
MSG="Unable to create: ${DUMP_DIR}/${NEWDIR}"
print_error
fi
elif [[ -f ${DUMP_DIR}/${SINGLE_FILE} ]]; then
REMOVE=$(/bin/rm -fv ${DUMP_DIR}/${SINGLE_FILE} 2>&1)
echo -e "\t${REMOVE}"
if [[ -f ${SINGLE_FILE} ]]; then
MSG="Unable to delete: ${DUMP_DIR}/${SINGLE_FILE}"
print_error
fi
fi
fi
}
execute_command() {
if [[ -z ${COMMAND} ]]; then
MSG="Variable Not Found: COMMAND"
print_error
elif [[ ${RESTRICT} == 1 ]]; then
${COMMAND} | grep -i "${THREESCALE_PROJECT}" 2> ${DUMP_DIR}/temp-cmd.txt | awk '{print $1}' > ${DUMP_DIR}/temp.txt
detect_error
else
${COMMAND} 2> ${DUMP_DIR}/temp-cmd.txt | awk '{print $1}' | tail -n +2 > ${DUMP_DIR}/temp.txt
detect_error
fi
}
detect_error() {
if [[ -f ${DUMP_DIR}/temp-cmd.txt ]]; then
TEMP_CMD=$(< ${DUMP_DIR}/temp-cmd.txt)
if [[ -n ${TEMP_CMD} ]]; then
echo -e "Error on the Step ${STEP} (${STEP_DESC}):\n" >> ${DUMP_DIR}/errors.txt
cat ${DUMP_DIR}/temp-cmd.txt >> ${DUMP_DIR}/errors.txt
echo -e "\n" >> ${DUMP_DIR}/errors.txt
fi
/bin/rm -f ${DUMP_DIR}/temp-cmd.txt
unset TEMP_CMD
fi
}
read_obj() {
if [[ -z ${NOYAML} ]]; then
YAML="-o yaml"
else
unset YAML
fi
while read OBJ; do
if [[ ! ${VALIDATE_PODS} == 1 ]]; then
FOUND=1
else
FOUND=0
for POD in "${THREEESCALE_PODS[@]}"; do
if ( [[ ${SUBSTRING} == 1 ]] && [[ "${OBJ}" == *"${POD}"* ]] ) || ( [[ "${OBJ}" == "${POD}" ]] ); then
FOUND=1
fi
done
fi
if [[ ! ${FOUND} == 1 ]]; then
echo -e "\tSkipping: ${OBJ}"
else
if [[ ${VERBOSE} == 1 ]]; then
echo -e "\n\tProcess: ${OBJ}"
fi
if [[ ${COMPRESS} == 1 ]]; then
CONTAINERS=$(${COMMAND} ${OBJ} --template='{{range .spec.containers}}{{.name}}
{{end}}')
for CONTAINER in ${CONTAINERS}; do
if [[ ${PREVIOUS} == 1 ]]; then
oc logs -p ${OBJ} --container=${CONTAINER} --timestamps > ${DUMP_DIR}/${NEWDIR}/previous-temp.txt 2>&1
VALIDATE=$(< ${DUMP_DIR}/${NEWDIR}/previous-temp.txt head -n 1)
if [[ ! "${VALIDATE,,}" == *"previous terminated container"* ]] && [[ ! "${VALIDATE,,}" == *"not found"* ]]; then
cat ${DUMP_DIR}/${NEWDIR}/previous-temp.txt | ${COMPRESS_UTIL} -f - > ${DUMP_DIR}/${NEWDIR}/${OBJ}-${CONTAINER}.${COMPRESS_FORMAT}
else
echo -e "\n${VALIDATE}" >> ${DUMP_DIR}/${NEWDIR}/ignored-temp.txt
fi
else
oc logs ${OBJ} --container=${CONTAINER} --timestamps 2>&1 | ${COMPRESS_UTIL} -f - > ${DUMP_DIR}/${NEWDIR}/${OBJ}-${CONTAINER}.${COMPRESS_FORMAT}
fi
done
sleep 1.0
else
${COMMAND} ${OBJ} ${YAML} >> ${DUMP_DIR}/${SINGLE_FILE} 2>&1
${COMMAND} ${OBJ} ${YAML} > ${DUMP_DIR}/${NEWDIR}/${OBJ}.yaml 2>&1
sleep 0.5
fi
fi
done < ${DUMP_DIR}/temp.txt
if [[ ${PREVIOUS} == 1 ]]; then
/bin/rm -f ${DUMP_DIR}/${NEWDIR}/previous-temp.txt
if [[ -f ${DUMP_DIR}/${NEWDIR}/ignored-temp.txt ]]; then
echo -e "The following containers have been ignored as there were no previous logs:\n" > ${DUMP_DIR}/${NEWDIR}/ignored-containers.txt
cat ${DUMP_DIR}/${NEWDIR}/ignored-temp.txt >> ${DUMP_DIR}/${NEWDIR}/ignored-containers.txt
/bin/rm -f ${DUMP_DIR}/${NEWDIR}/ignored-temp.txt
fi
fi
/bin/rm -f ${DUMP_DIR}/temp.txt
}
mgmt_api() {
if [[ -z ${OUTPUT} ]]; then
MSG="Variable Not Found: OUTPUT"
print_error
elif [[ -z ${APICAST_POD} ]]; then
MSG="Variable Not Found: APICAST_POD"
print_error
elif [[ ${MGMT_API,,} == "debug" ]] || [[ ${MGMT_API,,} == "status" ]]; then
OUTPUT="${OUTPUT}-status"
timeout 15 oc rsh ${APICAST_POD} /bin/bash -c "curl -X GET http://localhost:8090/status/live" > ${OUTPUT}-live.txt 2>&1 < /dev/null
timeout 15 oc rsh ${APICAST_POD} /bin/bash -c "curl -X GET http://localhost:8090/status/ready" > ${OUTPUT}-ready.txt 2>&1 < /dev/null
timeout 15 oc rsh ${APICAST_POD} /bin/bash -c "curl -X GET http://localhost:8090/status/info" > ${OUTPUT}-info.txt 2>&1 < /dev/null
if [[ ${MGMT_API,,} == "debug" ]]; then
OUTPUT="${OUTPUT}-debug"
timeout 15 oc rsh ${APICAST_POD} /bin/bash -c "curl -X GET -H 'Accept: application/json' http://localhost:8090/config" > ${OUTPUT}.json 2> ${OUTPUT}-stderr.txt < /dev/null
fi
unset OUTPUT APICAST_POD MGMT_API
fi
}
cleanup() {
unset COMMAND COMPRESS NEWDIR NOYAML PREVIOUS RESTRICT SINGLE_FILE SUBSTRING VALIDATE_PODS VERBOSE
}
cleanup_dir() {
if [[ -z ${TARGET_DIR} ]]; then
MSG="Variable Not Found: TARGET_DIR"
print_error
else
if [[ ${TARGET_DIR,,} == "dump_dir" ]]; then
TARGET_DIR="${DUMP_DIR}"
else
TARGET_DIR="${DUMP_DIR}/${TARGET_DIR}"
fi
if [[ ${COMPRESS} == 1 ]]; then
CMD_OUTPUT=$(/bin/rm -fv ${TARGET_DIR}/*.${COMPRESS_FORMAT} 2>&1)
TAB=2
display_verbose
else
CMD_OUTPUT=$(/bin/rm -fv ${TARGET_DIR}/{*.txt,*.json,*.yml,*.yaml} 2>&1)
TAB=2
display_verbose
fi
RMDIR=$(rmdir -v ${TARGET_DIR} 2>&1)
echo -e "\n\t${RMDIR}\n"
sleep 0.25
fi
unset TARGET_DIR COMPRESS
}
display_verbose() {
while read ITEM; do
if [[ ${TAB} == 2 ]]; then
echo -e "\t\t${ITEM}"
elif [[ ${TAB} == 1 ]]; then
echo -e "\t${ITEM}"
else
echo -e "${ITEM}"
fi
done <<< "${CMD_OUTPUT}"
unset TAB
}
print_step() {
echo -e "\n${STEP}. ${STEP_DESC}\n"
}
fetch_nodes() {
if [[ ${FIRST_CHECK} == 1 ]]; then
FETCH_NODES_DIR="status/nodes-before"
else
FETCH_NODES_DIR="status/nodes-after"
fi
# YAML format
NEWDIR="${FETCH_NODES_DIR}"
SINGLE_FILE="${FETCH_NODES_DIR}.yaml"
COMMAND="oc get nodes -o wide"
create_dir
execute_command
read_obj
cleanup
# TXT (describe) format
oc get nodes -o wide --show-kind --show-labels > ${DUMP_DIR}/${FETCH_NODES_DIR}.txt 2>&1
COMMAND="oc get nodes -o wide"
execute_command
while read NODE; do
DESCRIBE=$(oc describe node ${NODE} 2> ${DUMP_DIR}/temp-cmd.txt)
detect_error
echo -e "${DESCRIBE}" > ${DUMP_DIR}/${FETCH_NODES_DIR}/${NODE}.txt
echo -e "${DESCRIBE}\n" >> ${DUMP_DIR}/${FETCH_NODES_DIR}-describe.txt
sleep 0.5
done < ${DUMP_DIR}/temp.txt
}
########
# MAIN #
########
# Validate Argument: 3scale project #
if [[ -z ${THREESCALE_PROJECT} ]]; then
MSG="Usage: 3scale_dump.sh [3SCALE PROJECT] [COMPRESS UTIL (Optional)]"
print_error
else
# Validate the existance of the project
OC_PROJECT_DEBUG=$(oc get project 2>&1)
OC_PROJECT=$(echo -e "${OC_PROJECT_DEBUG}" | awk '{print $1}' | grep -iw "${THREESCALE_PROJECT}" | sort | head -n 1)
if [[ ! "${OC_PROJECT}" == "${THREESCALE_PROJECT}" ]]; then
MSG="Project not found: ${THREESCALE_PROJECT}:\n\n~~~\n${OC_PROJECT_DEBUG}\n~~~\n\nEnsure that you are logged in and specified the correct project"
print_error
else
# Change to the 3scale project
echo
oc project ${THREESCALE_PROJECT}
fi
fi
# Validate Argument: Compress Util #
# Attempt to auto-detect the COMPRESS_UTIL if not specified
if [[ -z ${COMPRESS_UTIL} ]] || [[ "${COMPRESS_UTIL}" == "auto" ]] || [[ ${COMPRESS_UTIL} == "xz" ]]; then
XZ_COMMAND=$(command -v xz 2>&1)
XZ_VERSION=$(xz --version 2>&1)
if [[ -n ${XZ_COMMAND} ]] && [[ "${XZ_VERSION,,}" == *"xz utils"* ]]; then
echo -e "\nXZ util found:\n\n~~~\n${XZ_VERSION}\n~~~\n"
COMPRESS_UTIL="xz"
COMPRESS_FORMAT="${COMPRESS_UTIL}"
else
echo -e "\nXZ util not found: using gzip\n"
COMPRESS_UTIL="gzip"
COMPRESS_FORMAT="gz"
fi
elif [[ ${COMPRESS_UTIL} == "gz" ]] || [[ ${COMPRESS_UTIL} == "gzip" ]]; then
COMPRESS_UTIL="gzip"
COMPRESS_FORMAT="gz"
else
MSG="Invalid Compress Util: ${COMPRESS_UTIL} (Values: gzip, xz)"
print_error
fi
# Validate: Permissions
FORBIDDEN=$(oc describe node 2>&1 | grep -i "forbidden")
if [[ -n ${FORBIDDEN} ]]; then
echo -e "\nWARNING: It looks like the Red Hat 3scale dump is being executed with an OpenShift user that doesn't have the 'cluster-admin' role. While the information fetched could be already sufficient to troubleshoot the issue regardless of this limitation, it's recommended using elevated privileges if possible (otherwise, please go ahead and proceed anyway). Refer to the section 'Administrator (Recommended)' from the Knowledge Base Article for more information. \n\nPress [ENTER] to continue or <Ctrl + C> to abort...\n"
read TEMP < /dev/tty
fi
# Case Number
echo -ne "Please enter the number of the Red Hat Case which this dump belongs to (Optional): "
read CASE < /dev/tty
if [[ -n ${CASE} ]]; then
echo -e "\nCase: ${CASE}.\n"
DUMP_DIR="${CURRENT_DIR}/${CASE}-3scale_dump-${NOW}"
DUMP_FILE="${DUMP_DIR}.tar"
else
echo -e "\nNOTE: No Case has been specified. Proceeding anyway.\n"
fi
echo -e "NOTE: A temporary directory will be created in order to store the information about the 3scale dump: ${DUMP_DIR}\n\nPress [ENTER] to continue or <Ctrl + C> to abort...\n"
read TEMP < /dev/tty
# Create the Dump Directory if it does not exist #
if [[ ! -d ${DUMP_DIR}/status/apicast-staging ]] || [[ ! -d ${DUMP_DIR}/status/apicast-production ]]; then
CMD_OUTPUT=$(mkdir -pv ${DUMP_DIR}/status/{apicast-staging,apicast-production} 2>&1)
TAB=1
display_verbose
if [[ ! -d ${DUMP_DIR}/status/apicast-staging ]] || [[ ! -d ${DUMP_DIR}/status/apicast-production ]]; then
MSG="Unable to create: ${DUMP_DIR}/status"
print_error
fi
fi
STEP=1
# Status: Nodes (First Check) #
STEP_DESC="Status: Nodes (First Check)"
print_step
FIRST_CHECK=1
fetch_nodes
((STEP++))
# Fetch the status from all the pods and events #
STEP_DESC="Fetch: All pods and Events"
print_step
oc get pod -o wide > ${DUMP_DIR}/status/pods-all.txt 2>&1
oc get pod -o wide --all-namespaces > ${DUMP_DIR}/status/pods-all-namespaces.txt 2>&1
oc get pod -o wide | grep -iv "deploy" | grep -iv "Evicted" | grep -iv "MatchNodeSelector" > ${DUMP_DIR}/status/pods.txt 2>&1
oc get pod -o wide | grep -i "deploy" > ${DUMP_DIR}/status/pods-deploy.txt 2>&1
oc get pod -o wide | grep -i "Evicted\|MatchNodeSelector" > ${DUMP_DIR}/status/pods-misc.txt 2>&1
oc get event > ${DUMP_DIR}/status/events.txt 2>&1
oc get event -o yaml > ${DUMP_DIR}/status/events.yaml 2>&1
oc get event --all-namespaces > ${DUMP_DIR}/status/events-all-namespaces.txt 2>&1
oc get event --all-namespaces -o yaml > ${DUMP_DIR}/status/events-all-namespaces.yaml 2>&1
oc version > ${DUMP_DIR}/status/ocp-version.txt 2>&1
((STEP++))
# DeploymentConfig objects #
STEP_DESC="Fetch: DeploymentConfig"
print_step
NEWDIR="dc"
SINGLE_FILE="dc.yaml"
COMMAND="oc get dc"
VALIDATE_PODS=1
create_dir
execute_command
read_obj
cleanup
((STEP++))
# DeploymentConfig Environment Variables #
STEP_DESC="Fetch: DeploymentConfig (Environment Variables)"
print_step
NEWDIR="dc/env"
SINGLE_FILE="env.txt"
COMMAND="oc get dc"
create_dir
execute_command
while read DC; do
ENV=$(oc set env dc/${DC} --list 2> ${DUMP_DIR}/temp-cmd.txt)
detect_error
echo -e "${ENV}" > ${DUMP_DIR}/dc/env/${DC}.txt
echo -e "${ENV}\n" >> ${DUMP_DIR}/dc/env.txt
sleep 0.25
done < ${DUMP_DIR}/temp.txt
((STEP++))
# Fetch and compress the logs #
STEP_DESC="Fetch: Logs"
print_step
NEWDIR="logs"
SINGLE_FILE="logs.txt"
COMMAND="oc get pod"
VALIDATE_PODS=1
SUBSTRING=1
COMPRESS=1
VERBOSE=1
NOYAML=1
cat ${DUMP_DIR}/status/pods.txt | awk '{print $1}' | tail -n +2 > ${DUMP_DIR}/temp.txt
create_dir
read_obj
cleanup
echo -e "\n\n\t# Logs from previous pods (if any) #\n"
# Previous logs #
NEWDIR="logs/previous"
SINGLE_FILE="logs-previous.txt"
COMMAND="oc get pod"
VALIDATE_PODS=1
SUBSTRING=1
COMPRESS=1
VERBOSE=1
NOYAML=1
PREVIOUS=1
cat ${DUMP_DIR}/status/pods.txt | awk '{print $1}' | tail -n +2 > ${DUMP_DIR}/temp.txt
create_dir
read_obj
cleanup
# Misc Logs #
LINES=$(cat ${DUMP_DIR}/status/pods-misc.txt | wc -l)
if [[ ! "${LINES}" == "0" ]]; then
echo -e "\n\n\t# Other pod logs #\n"
NEWDIR="logs/misc"
SINGLE_FILE="logs-misc.txt"
COMMAND="oc get pod"
VALIDATE_PODS=1
SUBSTRING=1
COMPRESS=1
VERBOSE=1
NOYAML=1
cat ${DUMP_DIR}/status/pods-misc.txt | awk '{print $1}' > ${DUMP_DIR}/temp.txt
create_dir
read_obj
cleanup
if [[ ${COMPRESS_UTIL} == "xz" ]]; then
echo -e '#!/bin/bash\n\nfor FILE in *.xz; do\n\txz -d ${FILE}\n mv $(echo "${FILE}" | cut -f 1 -d '.') $(echo "${FILE}" | cut -f 1 -d '.').log \ndone' > ${DUMP_DIR}/logs/misc/uncompress-logs.sh
else
echo -e '#!/bin/bash\n\nfor FILE in *.gz; do\n\tgunzip ${FILE}\n mv $(echo "${FILE}" | cut -f 1 -d '.') $(echo "${FILE}" | cut -f 1 -d '.').log \ndone' > ${DUMP_DIR}/logs/misc/uncompress-logs.sh
fi
chmod +x ${DUMP_DIR}/logs/misc/uncompress-logs.sh
fi
# Build the shell script to uncompress all logs according to the util (gzip, xz) being used
if [[ ${COMPRESS_UTIL} == "xz" ]]; then
echo -e '#!/bin/bash\n\nfor FILE in *.xz; do\n\txz -d ${FILE}\n mv $(echo "${FILE}" | cut -f 1 -d '.') $(echo "${FILE}" | cut -f 1 -d '.').log \ndone' > ${DUMP_DIR}/logs/uncompress-logs.sh
echo -e '#!/bin/bash\n\nfor FILE in *.xz; do\n\txz -d ${FILE}\n mv $(echo "${FILE}" | cut -f 1 -d '.') $(echo "${FILE}" | cut -f 1 -d '.').log \ndone' > ${DUMP_DIR}/logs/previous/uncompress-logs.sh
else
echo -e '#!/bin/bash\n\nfor FILE in *.gz; do\n\tgunzip ${FILE}\n mv $(echo "${FILE}" | cut -f 1 -d '.') $(echo "${FILE}" | cut -f 1 -d '.').log \ndone' > ${DUMP_DIR}/logs/uncompress-logs.sh
echo -e '#!/bin/bash\n\nfor FILE in *.gz; do\n\tgunzip ${FILE}\n mv $(echo "${FILE}" | cut -f 1 -d '.') $(echo "${FILE}" | cut -f 1 -d '.').log \ndone' > ${DUMP_DIR}/logs/previous/uncompress-logs.sh
fi
chmod +x ${DUMP_DIR}/logs/uncompress-logs.sh
chmod +x ${DUMP_DIR}/logs/previous/uncompress-logs.sh
# Fetch the logs from the pods in the 'deploy' state (if any):
DEPLOY_PODS=$(oc get pod -o wide | grep -i "deploy" 2> /dev/null)
if [[ -n ${DEPLOY_PODS} ]]; then
echo -e "\n\n\t# Logs from pods in a 'deploy' state #\n"
NEWDIR="logs/deploy"
SINGLE_FILE="logs-deploy.txt"
COMMAND="oc get pod"
VALIDATE_PODS=1
SUBSTRING=1
COMPRESS=1
VERBOSE=1
NOYAML=1
cat ${DUMP_DIR}/status/pods-deploy.txt | awk '{print $1}' > ${DUMP_DIR}/temp.txt
create_dir
read_obj
cleanup
if [[ ${COMPRESS_UTIL} == "xz" ]]; then
echo -e '#!/bin/bash\n\nfor FILE in *.xz; do\n\txz -d ${FILE}\n mv $(echo "${FILE}" | cut -f 1 -d '.') $(echo "${FILE}" | cut -f 1 -d '.').log \ndone' > ${DUMP_DIR}/logs/deploy/uncompress-logs.sh
else
echo -e '#!/bin/bash\n\nfor FILE in *.gz; do\n\tgunzip ${FILE}\n mv $(echo "${FILE}" | cut -f 1 -d '.') $(echo "${FILE}" | cut -f 1 -d '.').log \ndone' > ${DUMP_DIR}/logs/deploy/uncompress-logs.sh
fi
chmod +x ${DUMP_DIR}/logs/deploy/uncompress-logs.sh
fi
((STEP++))
# Secrets #
STEP_DESC="Fetch: Secrets"
print_step
NEWDIR="secrets"
SINGLE_FILE="secrets.yaml"
COMMAND="oc get secret"
create_dir
execute_command
read_obj
cleanup
((STEP++))
# Routes #
STEP_DESC="Fetch: Routes"
print_step
oc get route > ${DUMP_DIR}/routes.txt
NEWDIR="routes"
SINGLE_FILE="routes.yaml"
COMMAND="oc get route"
create_dir
execute_command
read_obj
cleanup
((STEP++))
# Services #
STEP_DESC="Fetch: Services"
print_step
NEWDIR="services"
SINGLE_FILE="services.yaml"
COMMAND="oc get service"
create_dir
execute_command
read_obj
cleanup
((STEP++))
# Image Streams #
STEP_DESC="Fetch: Image Streams"
print_step
NEWDIR="images"
SINGLE_FILE="images.yaml"
COMMAND="oc get imagestream"
create_dir
execute_command
read_obj
cleanup
((STEP++))
# ConfigMaps #
STEP_DESC="Fetch: ConfigMaps"
print_step
NEWDIR="configmaps"
SINGLE_FILE="configmaps.yaml"
COMMAND="oc get configmap"
create_dir
execute_command
read_obj
cleanup
((STEP++))
# Pods #
STEP_DESC="Fetch: Pods"
print_step
NEWDIR="pods"
SINGLE_FILE="pods.txt"
create_dir
COMMAND="oc get pod"
execute_command
while read POD; do
DESCRIBE=$(oc describe pod ${POD} 2> ${DUMP_DIR}/temp-cmd.txt)
detect_error
echo -e "${DESCRIBE}" > ${DUMP_DIR}/pods/${POD}.txt
echo -e "${DESCRIBE}\n" >> ${DUMP_DIR}/pods.txt
GET_POD=$(oc get pod ${POD} -o yaml 2> ${DUMP_DIR}/temp-cmd.txt)
detect_error
echo -e "${GET_POD}" > ${DUMP_DIR}/pods/${POD}.yaml
echo -e "${GET_POD}\n" >> ${DUMP_DIR}/pods.yaml
sleep 0.5
done < ${DUMP_DIR}/temp.txt
((STEP++))
# PV #
STEP_DESC="Fetch: PV"
print_step
NEWDIR="pv"
SINGLE_FILE="pv.yaml"
COMMAND="oc get pv"
RESTRICT=1
${COMMAND} | grep -i "${THREESCALE_PROJECT}" > ${DUMP_DIR}/status/pv.txt 2> ${DUMP_DIR}/temp-cmd.txt
detect_error
create_dir
execute_command
read_obj
cleanup
NEWDIR="pv/describe"
SINGLE_FILE="pv/describe.txt"
COMMAND="oc get pv"
RESTRICT=1
create_dir
execute_command
cleanup
while read PV; do
DESCRIBE=$(oc describe pv ${PV} 2> ${DUMP_DIR}/temp-cmd.txt)
detect_error
echo -e "${DESCRIBE}" > ${DUMP_DIR}/pv/describe/${PV}.txt
echo -e "${DESCRIBE}\n" >> ${DUMP_DIR}/pv/describe.txt
sleep 0.5
done < ${DUMP_DIR}/temp.txt
((STEP++))
# PVC #
STEP_DESC="Fetch: PVC"
print_step
NEWDIR="pvc"
SINGLE_FILE="pvc.yaml"
COMMAND="oc get pvc"
${COMMAND} > ${DUMP_DIR}/status/pvc.txt 2> ${DUMP_DIR}/temp-cmd.txt
detect_error
create_dir
execute_command
read_obj
cleanup
NEWDIR="pvc/describe"
SINGLE_FILE="pvc/describe.txt"
COMMAND="oc get pvc"
create_dir
execute_command
cleanup
while read PVC; do
DESCRIBE=$(oc describe pvc ${PVC} 2> ${DUMP_DIR}/temp-cmd.txt)
detect_error
echo -e "${DESCRIBE}" > ${DUMP_DIR}/pvc/describe/${PVC}.txt
echo -e "${DESCRIBE}\n" >> ${DUMP_DIR}/pvc/describe.txt
sleep 0.5
done < ${DUMP_DIR}/temp.txt
((STEP++))
# ServiceAccounts #
STEP_DESC="Fetch: ServiceAccounts"
print_step
NEWDIR="serviceaccounts"
SINGLE_FILE="serviceaccounts.yaml"
COMMAND="oc get serviceaccount"
create_dir
execute_command
read_obj
cleanup
((STEP++))
# Status: Replication Controllers #
STEP_DESC="Status: Replication Controllers"
print_step
# YAML format
NEWDIR="status/replicationcontrollers"
SINGLE_FILE="status/replicationcontrollers.yaml"
COMMAND="oc get replicationcontrollers -o wide"
create_dir
execute_command
read_obj
cleanup
# TXT (describe) format
COMMAND="oc get replicationcontrollers -o wide"
execute_command
${COMMAND} > ${DUMP_DIR}/status/replicationcontrollers.txt 2> ${DUMP_DIR}/temp-cmd.txt
detect_error
while read RC; do
DESCRIBE=$(oc describe replicationcontroller ${RC} 2> ${DUMP_DIR}/temp-cmd.txt)
detect_error
echo -e "${DESCRIBE}" > ${DUMP_DIR}/status/replicationcontrollers/${RC}.txt
sleep 0.1
done < ${DUMP_DIR}/temp.txt
((STEP++))
# Status: Project Quotas #
STEP_DESC="Status: Quotas"
print_step
oc get quota -o yaml > ${DUMP_DIR}/status/quotas.yaml 2> ${DUMP_DIR}/temp-cmd.txt
detect_error
oc describe quota > ${DUMP_DIR}/status/quotas.txt 2> ${DUMP_DIR}/temp-cmd.txt
detect_error
((STEP++))
# Status: Limits #
STEP_DESC="Status: Limits"
print_step
cat ${DUMP_DIR}/status/pods-all.txt | awk '{print $1}' | tail -n +2 > ${DUMP_DIR}/temp.txt
LIMITS_DESCRIBE_FILE="${DUMP_DIR}/temp-describe.txt"
LIMITS_FILE="${DUMP_DIR}/limits-temp.txt"
while read POD; do
echo -e "\n\tProcess: ${POD}"
oc describe pod "${POD}" > ${LIMITS_DESCRIBE_FILE}
while read LINE; do
if [[ "${LINE,,}" == *"container id:"* ]] && [[ ! "${PREVIOUS_LINE,,}" == *"-svc:"* ]]; then
PREVIOUS_LINE=$(echo "${PREVIOUS_LINE}" | sed "s@:@@g")
echo -e "\n\n# Pod: ${POD} | Container: ${PREVIOUS_LINE} #\n" >> ${LIMITS_FILE}
elif [[ "${LINE,,}" == *"limits"* ]]; then
echo -e "${LINE}" >> ${LIMITS_FILE}
elif [[ "${LINE,,}" == *"requests:"* ]]; then
echo -e "\n${LINE}" >> ${LIMITS_FILE}
elif [[ "${LINE,,}" == *"cpu:"* ]] || [[ "${LINE,,}" == *"memory:"* ]]; then
echo -e " ${LINE}" >> ${LIMITS_FILE}
fi
PREVIOUS_LINE="${LINE}"
done < ${LIMITS_DESCRIBE_FILE}
sleep 1.0
done < ${DUMP_DIR}/temp.txt
cat ${LIMITS_FILE} | tail -n +3 > ${DUMP_DIR}/status/limits.txt
/bin/rm -f ${LIMITS_DESCRIBE_FILE} ${LIMITS_FILE}
((STEP++))
# Status: OpenShift Project Debug #
STEP_DESC="Status: OpenShift Project Debug"
print_step
echo -e "# Overall Status #\n" > ${DUMP_DIR}/status/openshift-status.txt
oc status >> ${DUMP_DIR}/status/openshift-status.txt 2> ${DUMP_DIR}/temp-cmd.txt
detect_error
echo -e "\n\n# Suggestions #\n" >> ${DUMP_DIR}/status/openshift-status.txt
oc status --suggest >> ${DUMP_DIR}/status/openshift-status.txt 2> ${DUMP_DIR}/temp-cmd.txt
detect_error
echo -e "\n\n# Dot Output #\n" >> ${DUMP_DIR}/status/openshift-status.txt
oc status -o dot >> ${DUMP_DIR}/status/openshift-status.txt 2> ${DUMP_DIR}/temp-cmd.txt
detect_error
((STEP++))
# Status: OpenShift Nodes #
STEP_DESC="OpenShift Top Nodes"
print_step
oc adm top node > ${DUMP_DIR}/status/openshift-nodes 2>&1
oc adm top pods > ${DUMP_DIR}/status/openshift-pods 2>&1
# Status: Host Subnet #
STEP_DESC="Status: Host Subnet"
print_step
oc get hostsubnet -o yaml > ${DUMP_DIR}/status/hostsubnet.yaml 2> ${DUMP_DIR}/temp-cmd.txt
detect_error
oc get hostsubnet > ${DUMP_DIR}/status/hostsubnet.txt 2> ${DUMP_DIR}/temp-cmd.txt
detect_error
echo -e "\n" >> ${DUMP_DIR}/status/hostsubnet.txt
oc describe hostsubnet >> ${DUMP_DIR}/status/hostsubnet.txt 2> ${DUMP_DIR}/temp-cmd.txt
detect_error
((STEP++))
# Status: SCC #
STEP_DESC="Status: SCC"
print_step
oc get scc -o yaml > ${DUMP_DIR}/status/scc.yaml 2> ${DUMP_DIR}/temp-cmd.txt
detect_error