check_enq.sh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/usr/bin/env bash
  2. # Author: Jon Schipp
  3. ########
  4. # Examples:
  5. # 1.) Return critical if any queue is in the DOWN state
  6. # $ ./check_enq.sh -d
  7. #
  8. # 2.) Return critical if any queue is in the DOWN state except those listed
  9. # $ ./check_enq.sh -d -e "color,black,invoice"
  10. #
  11. # 3.) Return critical if color is in DOWN state
  12. # $ ./check_enq.sh -d -q color
  13. # Nagios Exit Codes
  14. OK=0
  15. WARNING=1
  16. CRITICAL=2
  17. UNKNOWN=3
  18. # set default values for the thresholds
  19. usage()
  20. {
  21. cat <<EOF
  22. Check printer queue status (enq) on AIX. If the queue
  23. matches the given status then return OK.
  24. Options:
  25. -q Comma separated list of print queue names (def: all)
  26. -d Given a queue, alert on those in a DOWN state
  27. -e Comma separated list of queues to exclude from the default all list
  28. -s Status to look for (READY/RUNNING/DOWN/QUEUED)
  29. Usage: $0 -q "invoice,black" -s READY
  30. EOF
  31. }
  32. argcheck() {
  33. # if less than n argument
  34. if [ $ARGC -lt $1 ]; then
  35. echo "Missing arguments! Use \`\`-h'' for help."
  36. exit 1
  37. fi
  38. }
  39. ARGC=$#
  40. DOWN_CHECK=0
  41. STATUS_CHECK=0
  42. QUEUE=".*"
  43. WONTMATCH=asdlfjasdlfjasdflasdjfaldsjfaldfj
  44. argcheck 1
  45. while getopts "hde:q:s:" ARG;
  46. do
  47. case $ARG in
  48. d) DOWN_CHECK=1
  49. ;;
  50. e) EXCLUDE=$(echo $OPTARG| sed 's/,/|/g')
  51. ;;
  52. q) QUEUE=$(echo $OPTARG| sed 's/,/|/g')
  53. ;;
  54. s) STATUS=$OPTARG
  55. STATUS_CHECK=1
  56. ;;
  57. h) usage
  58. exit
  59. ;;
  60. esac
  61. done
  62. if [ $DOWN_CHECK -eq 1 ]; then
  63. enq -A all | grep -v -E "${EXCLUDE:-$WONTMATCH}" | grep -E "$QUEUE" | grep DOWN && exit $CRITICAL ||
  64. (echo "No queues in down state" && exit $OK)
  65. fi
  66. #if [ $STATUS_CHECK -eq 1 ]; then
  67. # enq -A all |
  68. #fi