email.sh 2.7 KB

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