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.

70 lines
1.4 KiB

  1. #!/bin/bash -fu
  2. #
  3. # Hook to write file report instead of sending email
  4. #
  5. CONFIG_HOST="$1"
  6. CONFIG_PATH="$2"
  7. CONFIG_TASK="$3"
  8. CONFIG_DATE="$4"
  9. CONFIG_FILE="$5"
  10. HOOK_NAME="$6"
  11. HOOK_TYPE="$7"
  12. HOOK_TASK="$8"
  13. HOOK_CTID="$9"
  14. # ---
  15. source "$CONFIG_FILE"
  16. if [[ "$CONFIG_TASK" == "openvz-diff-backup" ]]; then
  17. LOG_FILE="$CONFIG_PATH/var/log/ovzdb.log"
  18. else
  19. LOG_FILE="$CONFIG_PATH/var/log/ovzdb_${CONFIG_TASK}.log"
  20. fi
  21. # ---
  22. if [[ -n "${!LOG_FILE[@]}" ]] && [[ -f "$LOG_FILE" ]]; then
  23. # --- Set report file
  24. REPORT_FILE="$SERVER_TMP_DIR/${CALLER_TASK}_${HOOK_TASK}_${HOOK_CTID}_error-report.flag"
  25. # --- Splash
  26. echo "
  27. ######################################
  28. # Error report - openvz-diff-backups #
  29. ######################################
  30. Oops, something went wrong. *Read this report or a kitten will die*.
  31. (please, do not panic and fill a bug report if necessary)" >> "$REPORT_FILE"
  32. # --- Create report
  33. echo -e "\n# --- $LOG_FILE\n" >> "$REPORT_FILE"
  34. if [[ -s "$LOG_FILE" ]]; then
  35. tac "$LOG_FILE" | grep -B 8192 -P -m 1 "\s*Info\s*\-\s*openvz\-diff\-backups\s*\d\.\d\.\d" | tac >> "$REPORT_FILE"
  36. fi
  37. echo -e "\n# --- /var/log/vzctl.log\n" >> "$REPORT_FILE"
  38. if [[ -s "/var/log/vzctl.log" ]]; then
  39. tail -n 50 "/var/log/vzctl.log" >> "$REPORT_FILE"
  40. fi
  41. echo -e "\n# --- /var/log/kern.log\n" >> "$REPORT_FILE"
  42. if [[ -s "/var/log/kern.log" ]]; then
  43. tail -n 50 "/var/log/kern.log" >> "$REPORT_FILE"
  44. fi
  45. # --- Exit
  46. exit 0
  47. fi