Playbooks to a new Lilik
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
2.3 KiB

  1. #!/bin/bash
  2. PROGNAME=$(basename $0)
  3. PROGPATH=$(echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,')
  4. . $PROGPATH/utils.sh
  5. print_usage() {
  6. echo "Usage: $PROGNAME -R repo [-d log_dir] [-w warning_age] [-c critical_age]"
  7. echo "Usage: $PROGNAME --help"
  8. }
  9. print_help() {
  10. echo ""
  11. exit $STATE_OK
  12. }
  13. logdir=/var/log/backup-status
  14. wage=93600 # 26h
  15. cage=187200 # 52h
  16. repo=""
  17. while test -n "$1"; do
  18. case "$1" in
  19. --help|-h)
  20. print_help
  21. exit $STATE_OK
  22. ;;
  23. --repo|-R)
  24. repo=$2
  25. shift
  26. ;;
  27. --dir|-d)
  28. logdir=$2
  29. shift
  30. ;;
  31. --wage|-w)
  32. wage=$2
  33. shift
  34. ;;
  35. --cage|-c)
  36. cage=$2
  37. shift
  38. ;;
  39. *)
  40. echo "Unknown argument: $1"
  41. print_usage
  42. exit $STATE_UNKNOWN
  43. ;;
  44. esac
  45. shift
  46. done
  47. if [ "$repo" == "" ] || [ ! -d "$logdir/$repo" ]; then
  48. echo "Unknown repo $repo."
  49. exit $STATE_UNKNOWN
  50. fi
  51. perf=""
  52. message=""
  53. warning=0
  54. critical=0
  55. unknown=0
  56. for i in $logdir/$repo/*; do
  57. IFS='|' read -ra STATE < $i
  58. ENTRY=$(basename $i)
  59. END=${STATE[0]}
  60. START=${STATE[1]}
  61. BACKUP_RC=${STATE[2]}
  62. PRUNE_RC=${STATE[3]}
  63. AGE=$(( $(date +%s) - ${START} ))
  64. DURATION=$(( ${END} - ${START} ))
  65. case "$BACKUP_RC" in
  66. 0)
  67. ;;
  68. 1)
  69. warning=1
  70. message="${message} - [ Backup of ${ENTRY} returned 1. ]"
  71. ;;
  72. *)
  73. critical=1
  74. message="${message} - [ Backup of ${ENTRY} returned ${BACKUP_RC}. ]"
  75. ;;
  76. esac
  77. case "$PRUNE_RC" in
  78. 0)
  79. ;;
  80. 1)
  81. warning=1
  82. message="${message} - [ Prune of ${ENTRY} returned 1. ]"
  83. ;;
  84. *)
  85. critical=1
  86. message="${message} - [ Prune of ${ENTRY} returned ${PRUNE_RC}. ]"
  87. ;;
  88. esac
  89. if [ "${AGE}" -gt "${cage}" ]; then
  90. critical=1
  91. message="${message} - [ Age of ${ENTRY} is CRITICAL ]"
  92. elif [ "${AGE}" -gt "${wage}" ]; then
  93. warning=1
  94. message="${message} - [ Age of ${ENTRY} is WARNING ]"
  95. fi
  96. perf="${perf}${ENTRY}/age=${AGE}s;${wage};${cage};0;${cage} "
  97. perf="${perf}${ENTRY}/duration=${DURATION}s "
  98. done
  99. if [ "$critical" == "1" ]; then
  100. echo "BACKUP CRITICAL${message}|${perf}"
  101. exit $STATE_CRITICAL
  102. elif [ "$warning" == "1" ]; then
  103. echo "BACKUP WARNING${message}|${perf}"
  104. exit $STATE_WARNING
  105. else
  106. echo "BACKUP OK|${perf}"
  107. exit $STATE_OK
  108. fi
  109. exit $STATE_UNKNOWN