-
Notifications
You must be signed in to change notification settings - Fork 44
/
openshift-checks.sh
executable file
·139 lines (127 loc) · 3.97 KB
/
openshift-checks.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
#!/usr/bin/env bash
# Inherit the shell variables in the subprocesses
# Useful for the -v flag
export SHELLOPTS
# https://betterdev.blog/minimal-safe-bash-script-template/
#set -Eeuo pipefail
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
IFS=$'\n\t'
# shellcheck disable=2164
cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1
# shellcheck disable=SC1091
source $(pwd)/utils
#trap cleanup SIGINT SIGTERM ERR EXIT
export ERRORFILE=$(mktemp)
trap "rm ${ERRORFILE}" EXIT
errors=0
# Flags
INFO=1
CHECKS=1
PRE=0
SSH=1
LIST=0
SINGLE=0
RESULTS_ONLY=0
SCRIPT_PROVIDED=''
RESTART_THRESHOLD=${RESTART_THRESHOLD:=10} #arbitray
THRASHING_THRESHOLD=${THRASHING_THRESHOLD:=10}
OCDEBUGIMAGE=${OCDEBUGIMAGE:=registry.redhat.io/rhel8/support-tools:latest}
OSETOOLSIMAGE=${OSETOOLSIMAGE:=registry.redhat.io/openshift4/ose-tools-rhel8:latest}
parse_params "$@"
setup_colors
main() {
# Check if only list is needed
if [ "${LIST}" -ne 0 ]; then
msg "${GREEN}Available scripts:${NOCOLOR}"
find checks/ info/ pre/ ssh/ -type f | sort -n
exit 0
else
# Check binaries availability
for i in oc yq jq curl column; do
check_command ${i}
done
# If only prechecks are needed:
if [ "${PRE}" -gt 0 ]; then
INSTALL_CONFIG_PATH=${INSTALL_CONFIG_PATH:=./install-config.yaml}
if [ ! -f ${INSTALL_CONFIG_PATH} ]; then
die "${RED}install-config.yaml not found${NOCOLOR}"
fi
msg "Running prechecks:"
for pre in ./pre/*; do
# shellcheck disable=SC1090,SC1091
"${pre}"
done
else
# Check kubeconfig and current user
kubeconfig
OCUSER=$(oc_whoami)
# If only a single script is needed:
if [ "${SINGLE}" -ne 0 ]; then
# Disable all the other checks
INFO=0
CHECKS=0
PRE=0
SSH=0
# shellcheck disable=SC1090,SC1091
"${SCRIPT_PROVIDED}"
fi
# If only info data is needed:
if [ "${INFO}" -gt 0 ]; then
msg "Gathering cluster information as ${GREEN}${OCUSER}${NOCOLOR}:"
for info in ./info/*; do
# shellcheck disable=SC1090,SC1091
"${info}"
done
fi
# If only checks are needed:
if [ "${CHECKS}" -gt 0 ]; then
msg "Running basic health checks as ${GREEN}${OCUSER}${NOCOLOR}"
for check in ./checks/*; do
# Refresh error count before execution
export errors=$(expr $(cat ${ERRORFILE}) + 0)
# shellcheck disable=SC1090,SC1091
if [ "${RESULTS_ONLY}" -gt 0 ]; then
"${check}" &>/dev/null
case $? in
0 | 1) msg "${check:2} ${GREEN}PASS${NOCOLOR}" ;;
2) msg "${check:2} ${RED}FAIL${NOCOLOR}" ;;
3) msg "${check:2} ${ORANGE}SKIPPED${NOCOLOR}" ;;
4) msg "${check:2} ${YELLOW}UNKNOWN${NOCOLOR}" ;;
*) msg "${check:2} ${RED}UNKNOWN RETURN CODE${NOCOLOR}" ;;
esac
else
"${check}"
fi
done
fi
# If only ssh checks are needed:
if [ "${SSH}" -gt 0 ]; then
msg "Running ssh-based health checks as ${GREEN}${OCUSER}${NOCOLOR}"
for ssh in ./ssh/*; do
# Refresh error count before execution
export errors=$(expr $(cat ${ERRORFILE}) + 0)
# shellcheck disable=SC1090,SC1091
if [ "${RESULTS_ONLY}" -gt 0 ]; then
"${ssh}" &>/dev/null
case $? in
0 | 1) msg "${ssh:2} ${GREEN}PASS${NOCOLOR}" ;;
2) msg "${ssh:2} ${RED}FAIL${NOCOLOR}" ;;
3) msg "${ssh:2} ${ORANGE}SKIPPED${NOCOLOR}" ;;
4) msg "${ssh:2} ${YELLOW}UNKNOWN${NOCOLOR}" ;;
*) msg "${ssh:2} ${RED}UNKNOWN RETURN CODE${NOCOLOR}" ;;
esac
else
"${ssh}"
fi
done
fi
fi
fi
export errors=$(expr $(cat ${ERRORFILE}) + 0)
if [ ${errors} -gt 0 ]; then
die "${RED}Total issues found: ${errors}${NOCOLOR}"
else
msg "${GREEN}No issues found${NOCOLOR}"
fi
}
main "$@"