@@ -655,9 +655,10 @@ mode_jobs() {
655
655
WARN=${WARN:- 1}
656
656
CRIT=${CRIT:- 2}
657
657
658
+ total_jobs=0
658
659
declare -i total_failed_count=0
659
660
declare -i job_fail_count
660
- data=$( getJSON " get jobs $kubectl_ns " " apis/apps /v1$api_ns /jobs/" )
661
+ data=$( getJSON " get jobs $kubectl_ns " " apis/batch /v1$api_ns /jobs/" )
661
662
[ $? -gt 0 ] && die " $data "
662
663
663
664
if [ " $NAME " ]; then
@@ -680,6 +681,7 @@ mode_jobs() {
680
681
.metadata.name" ) )
681
682
fi
682
683
for job in " ${jobs[@]} " ; do
684
+ (( total_jobs++ ))
683
685
job_fail_count=$( echo $data | jq -r " .items[] | select(.status.failed and .metadata.name==\" $job \" ) | .status.failed" )
684
686
let " total_failed_count= $total_failed_count + $job_fail_count "
685
687
if [ " $job_fail_count " -ge " ${WARN} " ]; then
@@ -689,12 +691,20 @@ mode_jobs() {
689
691
EXITCODE=2
690
692
fi
691
693
done
692
- if [ " $total_failed_count " -ge " ${WARN} " ]; then
693
- EXITCODE=1
694
- if [ " $total_failed_count " -ge " ${CRIT} " ]; then
695
- EXITCODE=2
696
- fi
694
+ if [ " $total_failed_count " -ge " ${WARN} " ]; then
695
+ EXITCODE=1
696
+ elif [ " $total_failed_count " -ge " ${CRIT} " ]; then
697
+ EXITCODE=2
697
698
fi
699
+ done
700
+
701
+ if [ $EXITCODE = 0 ]; then
702
+ if [ -z " $ns " ]; then
703
+ OUTPUT=" No jobs found"
704
+ else
705
+ OUTPUT=" OK. $total_jobs checked. ${total_failed_count} failed jobs is below threshold"
706
+ fi
707
+ else
698
708
if [ " $EXITCODE " -eq 1 ] ; then
699
709
OUTPUT=" WARNING. ${OUTPUT} "
700
710
elif [ " $EXITCODE " -ge 2 ] ; then
@@ -703,10 +713,7 @@ mode_jobs() {
703
713
if [ -z " $NAME " ] && [ " $EXITCODE " -ge 1 ] ; then
704
714
OUTPUT=" ${OUTPUT}${total_failed_count} jobs in total have failed"
705
715
fi
706
- if [ $EXITCODE -eq 0 ] ; then
707
- OUTPUT=" OK: ${total_failed_count} failed jobs is below threshold"
708
- fi
709
- done
716
+ fi
710
717
}
711
718
712
719
case " $MODE " in
0 commit comments