email.sh 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/bash
  2. # LGSM email.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://gameservermanagers.com
  5. lgsm_version="240416"
  6. # Description: Sends email notification if monitor picks up a failure.
  7. local modulename="Email"
  8. fn_print_dots "Sending notification to ${email}"
  9. info_distro.sh
  10. info_config.sh
  11. check_ip.sh
  12. if [ $(type -t fn_parms;echo $?) == 0 ]; then
  13. fn_parms
  14. fi
  15. {
  16. echo -e "========================================\n${servicename} details\n========================================"
  17. echo -e "Service name: ${servicename}"
  18. echo -e "Server name: ${servername}"
  19. echo -e "Game name: ${gamename}"
  20. echo -e "Server IP: ${ip}:${port}"
  21. echo -e "Failure reason: ${failurereason}"
  22. echo -e "Action Taken: ${actiontaken}\n"
  23. echo -e ""
  24. echo -e "========================================\nDistro Details\n========================================"
  25. echo -e "Date: $(date)"
  26. echo -e "Distro: ${os}"
  27. echo -e "Arch: ${arch}"
  28. echo -e "Kernel: ${kernel}"
  29. echo -e "Hostname: $HOSTNAME"
  30. echo -e "tmux: ${tmuxv}"
  31. echo -e "GLIBC: ${glibcversion}"
  32. echo -e ""
  33. echo -e "========================================\nPerformance\n========================================"
  34. echo -e "Uptime: ${days}d, ${hours}h, ${minutes}m"
  35. echo -e "Avg Load: ${load}"
  36. echo -e ""
  37. echo -e "Mem: total used free"
  38. echo -e "Physical: ${physmemtotal} ${physmemused} ${physmemfree}"
  39. echo -e "Swap: ${swaptotal}${swapused} ${swapfree}"
  40. echo -e ""
  41. echo -e "========================================\nStorage\n========================================"
  42. echo -e "\e[34mFilesystem:\t\e[0m${filesystem}"
  43. echo -e "\e[34mTotal:\t\e[0m${totalspace}"
  44. echo -e "\e[34mUsed:\t\e[0m${usedspace}"
  45. echo -e "\e[34mAvailable:\t\e[0m${availspace}"
  46. echo -e "\e[34mServerfiles:\t\e[0m${filesdirdu}"
  47. if [ -d "${backupdir}" ]; then
  48. echo -e "\e[34mBackups:\t\e[0m${backupdirdu}"
  49. fi
  50. echo -e ""
  51. echo -e "========================================\nLogs\n========================================"
  52. }| sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"| tee "${scriptlogdir}/${servicename}-email.log" > /dev/null 2>&1
  53. echo -e "\n\n Script log\n===================" >> "${emaillog}"
  54. tail -25 "${scriptlog}" >> "${emaillog}"
  55. if [ -n "${consolelog}" ]; then
  56. echo -e "\n\n Console log\n====================" >> "${emaillog}"
  57. tail -25 "${consolelog}" | awk '{ sub("\r$", ""); print }' >> "${emaillog}"
  58. fi
  59. if [ -n "${gamelogdir}" ]; then
  60. echo -e "\n\n Server log\n====================" >> "${emaillog}"
  61. tail "${gamelogdir}"/* | grep -v "==>" | sed '/^$/d' | tail -25 >> "${emaillog}"
  62. fi
  63. mail -s "${subject}" ${email} < "${emaillog}"
  64. fn_print_ok_nl "Sending notification to ${email}"
  65. fn_scriptlog "Sent notification to ${email}"