email.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/bash
  2. # LGSM email.sh function
  3. # Author: Daniel Gibbs
  4. # Website: http://gameservermanagers.com
  5. lgsm_version="010216"
  6. # Description: Sends email notification if monitor picks up a failure.
  7. local modulename="Email"
  8. fn_printdots "Sending notification to ${email}"
  9. info_distro.sh
  10. {
  11. echo -e "========================================\n${servicename} details\n========================================"
  12. echo -e "Service: ${servicename}"
  13. echo -e "Server: ${servername}"
  14. echo -e "Game: ${gamename}"
  15. echo -e "Failure reason: ${failurereason}"
  16. echo -e "Action Taken: ${actiontaken}\n"
  17. echo -e "========================================\nServer details\n========================================"
  18. echo -e "Date: $(date)"
  19. echo -e "Distro: ${os}"
  20. echo -e "Arch: ${arch}"
  21. echo -e "Kernel: ${kernel}"
  22. echo -e "Hostname: $HOSTNAME"
  23. echo -e "tmux: ${tmuxv}"
  24. echo -e "GLIBC: ${glibcv}"
  25. echo -e "Uptime: ${days}d, ${hours}h, ${minutes}m"
  26. echo -e "Avg Load${load}\n"
  27. echo -e "========================================\nLogs\n========================================"
  28. }| sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"| tee "${scriptlogdir}/${servicename}-email.log" > /dev/null 2>&1
  29. echo -e "Script log\n===================\n" >> "${emaillog}"
  30. tail -25 "${scriptlog}" >> "${emaillog}"
  31. if [ ! -z "${consolelog}" ]; then
  32. echo -e "\n\nConsole log\n====================\n" >> "${emaillog}"
  33. tail -25 "${consolelog}" | awk '{ sub("\r$", ""); print }' >> "${emaillog}"
  34. fi
  35. if [ ! -z "${gamelogdir}" ]; then
  36. echo -e "\n\nServer log\n====================\n" >> "${emaillog}"
  37. tail "${gamelogdir}"/* | grep -v "==>" | sed '/^$/d' | tail -25 >> "${emaillog}"
  38. fi
  39. mail -s "${subject}" ${email} < "${emaillog}"
  40. fn_printok "Sending notification to ${email}"
  41. fn_scriptlog "Sent notification to ${email}"
  42. sleep 1
  43. echo -en "\n"