Skip to content

Commit 5b503df

Browse files
committed
Fix jobs mode
1 parent 93a3f7b commit 5b503df

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

account.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ rules:
4040
verbs:
4141
- get
4242
- list
43+
- apiGroups:
44+
- batch
45+
resources:
46+
- jobs
47+
verbs:
48+
- get
49+
- list
4350

4451
---
4552
apiVersion: rbac.authorization.k8s.io/v1beta1

check_kubernetes.sh

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -655,9 +655,10 @@ mode_jobs() {
655655
WARN=${WARN:-1}
656656
CRIT=${CRIT:-2}
657657

658+
total_jobs=0
658659
declare -i total_failed_count=0
659660
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/")
661662
[ $? -gt 0 ] && die "$data"
662663

663664
if [ "$NAME" ]; then
@@ -680,6 +681,7 @@ mode_jobs() {
680681
.metadata.name"))
681682
fi
682683
for job in "${jobs[@]}"; do
684+
((total_jobs++))
683685
job_fail_count=$(echo $data | jq -r ".items[] | select(.status.failed and .metadata.name==\"$job\") | .status.failed")
684686
let "total_failed_count= $total_failed_count + $job_fail_count"
685687
if [ "$job_fail_count" -ge "${WARN}" ]; then
@@ -689,12 +691,20 @@ mode_jobs() {
689691
EXITCODE=2
690692
fi
691693
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
697698
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
698708
if [ "$EXITCODE" -eq 1 ] ; then
699709
OUTPUT="WARNING. ${OUTPUT}"
700710
elif [ "$EXITCODE" -ge 2 ] ; then
@@ -703,10 +713,7 @@ mode_jobs() {
703713
if [ -z "$NAME" ] && [ "$EXITCODE" -ge 1 ] ; then
704714
OUTPUT="${OUTPUT}${total_failed_count} jobs in total have failed"
705715
fi
706-
if [ $EXITCODE -eq 0 ] ; then
707-
OUTPUT="OK: ${total_failed_count} failed jobs is below threshold"
708-
fi
709-
done
716+
fi
710717
}
711718

712719
case "$MODE" in

0 commit comments

Comments
 (0)