Skip to content

Commit

Permalink
Ignoring statuses in workload check
Browse files Browse the repository at this point in the history
  • Loading branch information
Napsty committed Sep 9, 2022
1 parent 2efa3b0 commit 5dd9040
Showing 1 changed file with 36 additions and 13 deletions.
49 changes: 36 additions & 13 deletions check_rancher2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
# 20211201 1.7.1 Fix cluster state detection (#26) #
# 20220610 1.8.0 More performance data, long parameters, other improvements (#31) #
# 20220729 1.9.0 Output improvements (#32), show workload namespace (#33) #
# 20220909 1.9.1 Fix ComponentStatus (#35), show K8s version in single cluster check #
# 20220909 1.10.0 Fix ComponentStatus (#35), show K8s version in single cluster check #
# 20220909 1.10.0 Allow ignoring statuses on workload checks (#29) #
##########################################################################################
# (Pre-)Define some fixed variables
STATE_OK=0 # define the exit code if status is OK
Expand All @@ -58,7 +59,7 @@ STATE_CRITICAL=2 # define the exit code if status is Critical
STATE_UNKNOWN=3 # define the exit code if status is Unknown
export PATH=/usr/local/bin:/usr/bin:/bin:$PATH # Set path
proto=http # Protocol to use, default is http, can be overwritten with -S parameter
version=1.9.1
version=1.10.0
##########################################################################################
# functions

Expand Down Expand Up @@ -994,9 +995,17 @@ if [[ -z $workloadname ]]; then
for workload in ${workload_names[*]}; do
for status in ${healthstatus[$i]}; do
if [[ ${status} = updating ]]; then
workloadwarnings[$i]="Workload ${workload} is ${status} -"
if [[ -n $(echo ${ignore} | grep -i ${status}) ]]; then
workloadignored[$i]="Workload ${workload} is ${status} but ignored -"
else
workloadwarnings[$i]="Workload ${workload} is ${status} -"
fi
elif [[ ${status} != active ]]; then
workloaderrors[$i]="Workload ${workload} is ${status} -"
if [[ -n $(echo ${ignore} | grep -i ${status}) ]]; then
workloadignored[$i]="Workload ${workload} is ${status} but ignored -"
else
workloaderrors[$i]="Workload ${workload} is ${status} -"
fi
fi
done
for paused in ${pausedstatus[$i]}; do
Expand All @@ -1007,17 +1016,21 @@ if [[ -z $workloadname ]]; then
let i++
done

if [[ ${#workloadignored[*]} -gt 0 ]]; then
ignoreoutput="- ${workloadignored[*]}"
fi

if [[ ${#workloaderrors[*]} -gt 0 ]]; then
echo "CHECK_RANCHER2 CRITICAL - ${#workloaderrors[*]} workload(s) in error state: ${workloaderrors[*]}|'workloads_total'=${#workload_names[*]};;;; 'workloads_errors'=${#workloaderrors[*]};;;; 'workloads_warnings'=${#workloadwarnings[*]};;;; 'workloads_paused'=${#workloadpaused[*]};;;;"
echo "CHECK_RANCHER2 CRITICAL - ${#workloaderrors[*]} workload(s) in error state: ${workloaderrors[*]} ${ignoreoutput}|'workloads_total'=${#workload_names[*]};;;; 'workloads_errors'=${#workloaderrors[*]};;;; 'workloads_warnings'=${#workloadwarnings[*]};;;; 'workloads_paused'=${#workloadpaused[*]};;;; 'workloads_ignored'=${#workloadignored[*]};;;;"
exit ${STATE_CRITICAL}
elif [[ ${#workloadwarnings[*]} -gt 0 ]]; then
echo "CHECK_RANCHER2 WARNING - ${#workloadwarnings[*]} workload(s) in warning state: ${workloadwarnings[*]}|'workloads_total'=${#workload_names[*]};;;; 'workloads_errors'=${#workloaderrors[*]};;;; 'workloads_warnings'=${#workloadwarnings[*]};;;; 'workloads_paused'=${#workloadpaused[*]};;;;"
echo "CHECK_RANCHER2 WARNING - ${#workloadwarnings[*]} workload(s) in warning state: ${workloadwarnings[*]} ${ignoreoutput}|'workloads_total'=${#workload_names[*]};;;; 'workloads_errors'=${#workloaderrors[*]};;;; 'workloads_warnings'=${#workloadwarnings[*]};;;; 'workloads_paused'=${#workloadpaused[*]};;;; 'workloads_ignored'=${#workloadignored[*]};;;;"
exit ${STATE_WARNING}
else
if [[ ${#workloadpaused[*]} -gt 0 ]]; then
echo "CHECK_RANCHER2 OK - All workloads (${#workload_names[*]}) in project ${projectname} are healthy/active ( Note: ${#workloadpaused[*]} workloads currently paused: ${workloadpaused[*]})|'workloads_total'=${#workload_names[*]};;;; 'workloads_errors'=${#workloaderrors[*]};;;; 'workloads_warnings'=${#workloadwarnings[*]};;;; 'workloads_paused'=${#workloadpaused[*]};;;;"
echo "CHECK_RANCHER2 OK - All workloads (${#workload_names[*]}) in project ${projectname} are healthy/active ( Note: ${#workloadpaused[*]} workloads currently paused: ${workloadpaused[*]}) ${ignoreoutput}|'workloads_total'=${#workload_names[*]};;;; 'workloads_errors'=${#workloaderrors[*]};;;; 'workloads_warnings'=${#workloadwarnings[*]};;;; 'workloads_paused'=${#workloadpaused[*]};;;; 'workloads_ignored'=${#workloadignored[*]};;;;"
else
echo "CHECK_RANCHER2 OK - All workloads (${#workload_names[*]}) in project ${projectname} are healthy/active|'workloads_total'=${#workload_names[*]};;;; 'workloads_errors'=${#workloaderrors[*]};;;; 'workloads_warnings'=${#workloadwarnings[*]};;;; 'workloads_paused'=${#workloadpaused[*]};;;;"
echo "CHECK_RANCHER2 OK - All workloads (${#workload_names[*]}) in project ${projectname} are healthy/active ${ignoreoutput}|'workloads_total'=${#workload_names[*]};;;; 'workloads_errors'=${#workloaderrors[*]};;;; 'workloads_warnings'=${#workloadwarnings[*]};;;; 'workloads_paused'=${#workloadpaused[*]};;;; 'workloads_ignored'=${#workloadignored[*]};;;;"
fi
exit ${STATE_OK}
fi
Expand Down Expand Up @@ -1052,13 +1065,23 @@ else
healthstatus=$(echo "$api_out_single_workload" | jq -r '.data[].state')

if [[ ${healthstatus} = updating ]]; then
echo "CHECK_RANCHER2 WARNING - Workload $workloadname ${nsoutputappend}is ${healthstatus}|'workload_active'=0;;;; 'workload_error'=0;;;; 'workload_warning'=1;;;;"
exit ${STATE_WARNING}
if [[ -n $(echo ${ignore} | grep -i ${healthstatus}) ]]; then
echo "CHECK_RANCHER2 OK - Workload $workloadname ${nsoutputappend}is ${healthstatus} but ignored|'workload_active'=0;;;; 'workload_error'=0;;;; 'workload_warning'=1;;;; 'workload_ignored'=1;;;;"
exit ${STATE_WARNING}
else
echo "CHECK_RANCHER2 WARNING - Workload $workloadname ${nsoutputappend}is ${healthstatus}|'workload_active'=0;;;; 'workload_error'=0;;;; 'workload_warning'=1;;;; 'workload_ignored'=0;;;;"
exit ${STATE_WARNING}
fi
elif [[ ${healthstatus} != active ]]; then
echo "CHECK_RANCHER2 CRITICAL - Workload $workloadname ${nsoutputappend}is ${healthstatus}|'workload_active'=0;;;; 'workload_error'=1;;;; 'workload_warning'=0;;;;"
exit ${STATE_CRITICAL}
if [[ -n $(echo ${ignore} | grep -i ${healthstatus}) ]]; then
echo "CHECK_RANCHER2 CRITICAL - Workload $workloadname ${nsoutputappend}is ${healthstatus} but ignored|'workload_active'=0;;;; 'workload_error'=1;;;; 'workload_warning'=0;;;; 'workload_ignored'=1;;;;"
exit ${STATE_CRITICAL}
else
echo "CHECK_RANCHER2 CRITICAL - Workload $workloadname ${nsoutputappend}is ${healthstatus}|'workload_active'=0;;;; 'workload_error'=1;;;; 'workload_warning'=0;;;; 'workload_ignored'=0;;;;"
exit ${STATE_CRITICAL}
fi
else
echo "CHECK_RANCHER2 OK - Workload $workloadname ${nsoutputappend}is active|'workload_active'=1;;;; 'workload_error'=0;;;; 'workload_warning'=0;;;;"
echo "CHECK_RANCHER2 OK - Workload $workloadname ${nsoutputappend}is active|'workload_active'=1;;;; 'workload_error'=0;;;; 'workload_warning'=0;;;; 'workload_ignored'=0;;;;"
exit ${STATE_OK}
fi

Expand Down

0 comments on commit 5dd9040

Please sign in to comment.