fn_email 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/bash
  2. # LGSM fn_email function
  3. # Author: Daniel Gibbs
  4. # Website: http://gameservermanagers.com
  5. lgsm_version="061115"
  6. # Description: Sends email notification if monitor picks up a failure.
  7. local modulename="Email"
  8. fn_printdots "Sending notification to ${email}"
  9. echo -en "\n"
  10. fn_details_distro
  11. {
  12. echo -e "========================================\n${servicename} details\n========================================\n"
  13. echo -e "Service: ${servicename}"
  14. echo -e "Server: ${servername}"
  15. echo -e "Game: ${gamename}"
  16. echo -e "Failure reason: ${failurereason}"
  17. echo -e "Action Taken: ${actiontaken}\n"
  18. echo -e "========================================\nServer details\n========================================\n"
  19. echo -e "Date: $(date)"
  20. echo -e "Distro: ${os}"
  21. echo -e "Arch: ${arch}"
  22. echo -e "Kernel: ${kernel}"
  23. echo -e "Hostname: $HOSTNAME"
  24. echo -e "Uptime: ${days}d, ${hours}h, ${minutes}m"
  25. echo -e "Avg Load${load}\n"
  26. echo -e "========================================\nLogs\n========================================\n"
  27. echo -e "Script log\n===================\n"
  28. fn_details
  29. }|sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"|tee "${scriptlogdir}/${servicename}-email.log"
  30. tail -25 "${scriptlog}" >> "${emaillog}"
  31. if [ ! -z "${consolelog}" ]; then
  32. echo -e "\n\nConsole log\n====================\n" >> "${emaillog}"
  33. tail -25 "${consolelog}" >> "${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"