@@ -144,7 +144,7 @@ mode_apiserver() {
144
144
data=$( getJSON " " " healthz" )
145
145
[ $? -gt 0 ] && die " $data "
146
146
if [ " $data " = ok ]; then
147
- OUTPUT=" OK. Kubernetes apiserver health is OK "
147
+ OUTPUT=" OK. Kubernetes apiserver is healthy "
148
148
EXITCODE=0
149
149
else
150
150
data=$( echo " $data " | grep " \[\-\]" )
@@ -164,15 +164,15 @@ mode_nodes() {
164
164
.status" ) "
165
165
if [ " $ready " != True ]; then
166
166
EXITCODE=2
167
- OUTPUT=" ${OUTPUT} Node $node not ready. "
167
+ OUTPUT=" ERROR. ${OUTPUT} Node $node not ready\n "
168
168
fi
169
169
for condition in OutOfDisk MemoryPressure DiskPressure; do
170
170
state=" $( echo " $data " | jq -r " .items[] | select(.metadata.name==\" $node \" ) | \
171
171
.status.conditions[] | select(.type==\" $condition \" ) | \
172
172
.status" ) "
173
173
if [ " $state " = True ]; then
174
174
[ $EXITCODE -lt 1 ] && EXITCODE=1
175
- OUTPUT=" $ OUTPUT $node $condition . "
175
+ OUTPUT=" WARN. ${ OUTPUT} $node $condition \n "
176
176
fi
177
177
done
178
178
done
@@ -182,7 +182,7 @@ mode_nodes() {
182
182
OUTPUT=" No nodes found"
183
183
EXITCODE=" $MISSING_EXITCODE "
184
184
else
185
- OUTPUT=" OK. ${# nodes[@]} nodes are Ready "
185
+ OUTPUT=" OK. ${# nodes[@]} nodes are ready "
186
186
fi
187
187
fi
188
188
}
@@ -420,22 +420,30 @@ mode_pods() {
420
420
else
421
421
(( count_failed++ ))
422
422
fi
423
+ if [ " $restart_count " -ge " $WARN " ]; then
424
+ OUTPUT=" ${OUTPUT} Container $bad_container : $restart_count restarts.\n"
425
+ EXITCODE=1
426
+ if [ " $restart_count " -ge " $CRIT " ]; then
427
+ EXITCODE=2
428
+ fi
429
+ fi
423
430
done
424
431
done
425
432
433
+ if [ $EXITCODE = 0 ]; then
426
434
if [ -z " $ns " ]; then
427
435
OUTPUT=" No pods found"
428
436
EXITCODE=" $MISSING_EXITCODE "
429
437
else
430
- if [ " $max_restart_count " -ge " $WARN " ]; then
431
- OUTPUT=" Container $bad_container : $max_restart_count restarts. "
432
- EXITCODE=1
433
- if [ " $max_restart_count " -ge " $CRIT " ]; then
434
- EXITCODE=2
438
+ OUTPUT=" OK. $count_ready pods ready, $count_succeeded pods succeeded, $count_failed pods not ready\n${OUTPUT} "
439
+ fi
440
+ else
441
+ if [ $EXITCODE = 1 ]; then
442
+ OUTPUT=" WARNING. $count_ready pods ready, $count_succeeded pods succeeded, $count_failed pods not ready\n${OUTPUT} "
443
+ else
444
+ OUTPUT=" ERROR. $count_ready pods ready, $count_succeeded pods succeeded, $count_failed pods not ready\n${OUTPUT} "
435
445
fi
436
446
fi
437
- OUTPUT=" $OUTPUT$count_ready pods ready, $count_succeeded pods succeeded, $count_failed pods not ready"
438
- fi
439
447
}
440
448
441
449
mode_deployments () {
@@ -647,7 +655,7 @@ mode_statefulsets() {
647
655
done < <( echo " $data " | \
648
656
jq -r " .items[] | select(.metadata.namespace==\" $ns \" and .metadata.name==\" $rs \" ) | \
649
657
.status | to_entries | map(\" \(.key)=\(.value)\" ) | .[]" )
650
- OUTPUT=" Statefulset $ns /$rs ${statusArr[readyReplicas]} /${statusArr[currentReplicas]} ready"
658
+ OUTPUT=" ${OUTPUT} Statefulset $ns /$rs ${statusArr[readyReplicas]} /${statusArr[currentReplicas]} ready\n "
651
659
if [ " ${statusArr[readyReplicas]} " != " ${statusArr[currentReplicas]} " ]; then
652
660
(( count_failed++ ))
653
661
EXITCODE=2
@@ -711,7 +719,7 @@ mode_jobs() {
711
719
job_fail_count=$( echo " $data " | jq -r " .items[] | select(.status.failed and .metadata.name==\" $job \" ) | .status.failed" )
712
720
total_failed_count=" $(( total_failed_count+ job_fail_count)) "
713
721
if [ " $job_fail_count " -ge " ${WARN} " ]; then
714
- OUTPUT=" ${OUTPUT} Job $job has $job_fail_count failures. "
722
+ OUTPUT=" ${OUTPUT} Job $job has $job_fail_count failures\n "
715
723
EXITCODE=1
716
724
elif [ " $job_fail_count " -ge " ${CRIT} " ]; then
717
725
EXITCODE=2
@@ -728,7 +736,7 @@ mode_jobs() {
728
736
if [ -z " $ns " ]; then
729
737
OUTPUT=" No jobs found"
730
738
else
731
- OUTPUT=" OK. $total_jobs checked. ${total_failed_count} failed jobs is below threshold"
739
+ OUTPUT=" OK. $total_jobs checked. ${total_failed_count} failed jobs is below threshold\n "
732
740
fi
733
741
else
734
742
if [ " $EXITCODE " -eq 1 ] ; then
@@ -737,7 +745,7 @@ mode_jobs() {
737
745
OUTPUT=" CRITICAL. ${OUTPUT} "
738
746
fi
739
747
if [ -z " $NAME " ] && [ " $EXITCODE " -ge 1 ] ; then
740
- OUTPUT=" ${OUTPUT}${total_failed_count} jobs in total have failed"
748
+ OUTPUT=" ${OUTPUT}${total_failed_count} jobs have failed"
741
749
fi
742
750
fi
743
751
}
0 commit comments