ruạṛ
#!/bin/bash usage() { echo "check_smartermail_queue - Icinga SmarterMail queue check" echo "" echo "Usage: check_smartermail_queue -w <warning queue size> -c <critical queue size> [ -h ]" echo "" echo " -w Queue size at which a warning is triggered" echo " -c Queue size at which a critical is triggered" echo " -h Show this page" echo "" } cmdopts() { if [ $# -gt 0 ]; then while getopts w:c:h myarg; do case $myarg in h|\?) usage exit 0;; w) WARNING=$OPTARG;; c) CRITICAL=$OPTARG;; *) # Default usage exit 1;; esac done else usage exit 1 fi } cmdopts "$@" if [ -z "$WARNING" ] || [ -z "$CRITICAL" ]; then echo "Error: Both -w (warning) and -c (critical) thresholds must be provided." usage exit 1 fi SPOOL_DIR="/var/lib/smartermail/Spool" EMAIL_COUNT=$(find "$SPOOL_DIR" -type f -name "*.eml" 2>/dev/null | wc -l) if [ "$EMAIL_COUNT" -ge "$CRITICAL" ]; then echo "CRITICAL: $EMAIL_COUNT mail(s) in queue (Threshold: $CRITICAL)" exit 2 # Critical status elif [ "$EMAIL_COUNT" -ge "$WARNING" ]; then echo "WARNING: $EMAIL_COUNT mail(s) in queue (Threshold: $WARNING)" exit 1 # Warning status else echo "OK: $EMAIL_COUNT mail(s) in queue (Threshold is below $WARNING)" exit 0 # OK status fi
cải xoăn