Skip to content

Commit 4887168

Browse files
authored
Fix cluster state detection (#30)
* Fix cluster state detection * Bump release date
1 parent c9118fa commit 4887168

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

check_rancher2.sh

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
# 20210504 1.6.0 Add usage performance data on single cluster check, fix project check #
4747
# 20210824 1.6.1 Fix cluster and project not found error (#24) #
4848
# 20211021 1.7.0 Check for additional node (pressure) conditions (#27) #
49+
# 20211201 1.7.1 Fix cluster state detection (#26) #
4950
##########################################################################################
5051
# (Pre-)Define some fixed variables
5152
STATE_OK=0 # define the exit code if status is OK
@@ -54,7 +55,7 @@ STATE_CRITICAL=2 # define the exit code if status is Critical
5455
STATE_UNKNOWN=3 # define the exit code if status is Unknown
5556
export PATH=/usr/local/bin:/usr/bin:/bin:$PATH # Set path
5657
proto=http # Protocol to use, default is http, can be overwritten with -S parameter
57-
version=1.7.0
58+
version=1.7.1
5859

5960
# Check for necessary commands
6061
for cmd in jq curl [
@@ -193,8 +194,15 @@ if [[ -z $clustername ]]; then
193194
do
194195
#echo $cluster # For Debug
195196
clusteralias=$(echo "$api_out_clusters" | jq -r '.data[] | select(.id == "'${cluster}'")|.name')
197+
declare -a clusterstate=( $(echo "$api_out_clusters" | jq -r '.data[] | select(.id == "'${cluster}'") | .state') )
196198
declare -a component=( $(echo "$api_out_clusters" | jq -r '.data[] | select(.id == "'${cluster}'") | .componentStatuses[].name') )
197199
declare -a healthstatus=( $(echo "$api_out_clusters" | jq -r '.data[] | select(.id == "'${cluster}'") | .componentStatuses[].conditions[].status') )
200+
201+
if [[ "${clusterstate}" != "active" ]]; then
202+
componenterrors[$e]="cluster ${clusteralias} is in ${clusterstate} state -"
203+
clustererrors[$e]="${cluster}"
204+
fi
205+
198206
c=0
199207
for status in ${healthstatus[*]}
200208
do
@@ -230,6 +238,7 @@ else
230238
fi
231239

232240
clusteralias=$(echo "$api_out_single_cluster" | jq -r '.name')
241+
clusterstate=$(echo "$api_out_single_cluster" | jq -r '.state')
233242
declare -a component=( $(echo "$api_out_single_cluster" | jq -r '.componentStatuses[].name') )
234243
declare -a healthstatus=( $(echo "$api_out_single_cluster" | jq -r '.componentStatuses[].conditions[].status') )
235244

@@ -269,14 +278,15 @@ else
269278
# remove unit from requested_cpu
270279
requested_cpu=( $(echo "${requested_cpu}" | sed 's/[a-zA-Z]*$//g') )
271280

281+
if [[ "${clusterstate}" != "active" ]]; then
282+
componenterrors+="cluster ${clusteralias} is in ${clusterstate} state -"
283+
fi
272284

273-
i=0
274285
for status in ${healthstatus[*]}
275286
do
276287
if [[ ${status} != True ]]; then
277-
componenterrors[$i]="${component[$i]} is not healthy -"
288+
componenterrors+="${component[$i]} is not healthy -"
278289
fi
279-
let i++
280290
done
281291

282292
if [[ ${#componenterrors[*]} -gt 0 ]]

0 commit comments

Comments
 (0)