Skip to content

Kubernetes — alert when a CronJob is suspended

Someone set `spec.suspend: true` on a CronJob (debug or rushed release) and forgot to revert. The daily task does not run, reports are not generated — you only learn when finance asks.

Recipe

bash
#!/usr/bin/env bash
# /etc/cron.d/cj-suspended
# 0 9 * * * root /opt/cj-suspended.sh

CONTEXT=${KUBE_CONTEXT:-prod}

SUSP=$(kubectl --context "$CONTEXT" get cronjobs -A -o json \
  | jq -r '[.items[] | select(.spec.suspend == true) | "\(.metadata.namespace)/\(.metadata.name)"]')

COUNT=$(echo "$SUSP" | jq 'length')

if [ "${COUNT:-0}" -gt 0 ]; then
  NAMES=$(echo "$SUSP" | jq -r '.[]' | head -10 | tr '\n' ',')
  curl -fsS "$HEARTBEAT_URL" --data-urlencode "cj_suspended=$COUNT,names=$NAMES"
  exit 2
fi
echo "OK (no suspended CronJobs)"

Same thing in Enterno.io

Wire to an Enterno heartbeat — a daily report of "what is currently disabled" so nothing falls through the cracks.

Set up HTTP monitor → ← All recipes

Related recipes