alert.sh 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #!/bin/bash
  2. # LinuxGSM alert.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://gameservermanagers.com
  5. # Description: Overall function for managing alerts.
  6. local commandname="ALERT"
  7. local commandaction="Alert"
  8. fn_alert_test(){
  9. fn_script_log_info "Sending test alert"
  10. alertsubject="Alert - ${servicename}: Test"
  11. alertemoji="🚨"
  12. alerturl="https://gameservermanagers.com"
  13. alertbody="Testing LinuxGSM Alert. No action to be taken."
  14. }
  15. fn_alert_restart(){
  16. fn_script_log_info "Sending alert: Restarted: ${executable} not running"
  17. alertsubject="Alert - ${servicename}: Restarted"
  18. alertemoji="🚨"
  19. alerturl="https://gameservermanagers.com"
  20. alertbody="${servicename} ${executable} not running"
  21. }
  22. fn_alert_restart_query(){
  23. fn_script_log_info "Sending alert: Restarted: ${gsquerycmd}"
  24. alertsubject="Alert - ${servicename}: Restarted"
  25. alertemoji="🚨"
  26. alerturl="https://gameservermanagers.com"
  27. alertbody="gsquery.py failed to query: ${gsquerycmd}"
  28. }
  29. fn_alert_update(){
  30. fn_script_log_info "Sending alert: Updated"
  31. alertsubject="Alert - ${servicename}: Updated"
  32. alertemoji="🎮"
  33. alerturl="https://gameservermanagers.com"
  34. alertbody="${gamename} received update"
  35. }
  36. fn_alert_permissions(){
  37. fn_script_log_info "Sending alert: Permissions error"
  38. alertsubject="Alert - ${servicename}: Permissions error"
  39. alertemoji="❗"
  40. alerturl="https://gameservermanagers.com"
  41. alertbody="${servicename} has permissions issues"
  42. }
  43. if [ "${alert}" == "permissions" ]; then
  44. fn_alert_permissions
  45. elif [ "${alert}" == "restart" ]; then
  46. fn_alert_restart
  47. elif [ "${alert}" == "restartquery" ]; then
  48. fn_alert_restart_query
  49. elif [ "${alert}" == "test" ]; then
  50. fn_alert_test
  51. elif [ "${alert}" == "update" ]; then
  52. fn_alert_update
  53. fi
  54. if [ "${emailalert}" == "on" ]&&[ -n "${email}" ]; then
  55. alert_email.sh
  56. elif [ "${emailalert}" != "on" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then
  57. fn_print_warn_nl "Email alerts not enabled"
  58. fn_script_log_warn "Email alerts not enabled"
  59. elif [ -z "${email}" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then
  60. fn_print_error_nl "Email not set"
  61. fn_script_log_error "Email not set"
  62. fi
  63. if [ "${pushbulletalert}" == "on" ]&&[ -n "${pushbullettoken}" ]; then
  64. alert_pushbullet.sh
  65. elif [ "${pushbulletalert}" != "on" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then
  66. fn_print_warn_nl "Pushbullet alerts not enabled"
  67. fn_script_log_warn "Pushbullet alerts not enabled"
  68. elif [ -z "${pushbullettoken}" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then
  69. fn_print_error_nl "Pushbullet token not set"
  70. echo " * https://github.com/GameServerManagers/LinuxGSM/wiki/Pushbullet"
  71. fn_script_error_warn "Pushbullet token not set"
  72. fi
  73. if [ "${telegramalert}" == "on" ]&&[ -n "${telegramtoken}" ]; then
  74. alert_telegram.sh
  75. elif [ "${telegramalert}" != "on" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then
  76. fn_print_warn_nl "Telegram Messages not enabled"
  77. fn_script_log_warn "Telegram Messages not enabled"
  78. elif [ -z "${telegramtoken}" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then
  79. fn_print_error_nl "Telegram token not set."
  80. echo " * https://github.com/GameServerManagers/LinuxGSM/wiki/Telegram"
  81. fn_script_error_warn "Telegram token not set."
  82. elif [ -z "${telegramchatid}" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then
  83. fn_print_error_nl "Telegram chat id not set."
  84. echo " * https://github.com/GameServerManagers/LinuxGSM/wiki/Telegram"
  85. fn_script_error_warn "Telegram chat id not set."
  86. fi
  87. if [ "${discordalert}" == "on" ]&&[ -n "${discordalert}" ]; then
  88. alert_discord.sh
  89. elif [ "${discordalert}" != "on" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then
  90. fn_print_warn_nl "Discord alerts not enabled"
  91. fn_script_log_warn "Discord alerts not enabled"
  92. elif [ -z "${discordtoken}" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then
  93. fn_print_error_nl "Discord token not set"
  94. echo " * https://github.com/GameServerManagers/LinuxGSM/wiki/Discord"
  95. fn_script_error_warn "Discord token not set"
  96. fi
  97. if [ "${pushoveralert}" == "on" ]&&[ -n "${pushoveralert}" ]; then
  98. alert_discord.sh
  99. elif [ "${pushoveralert}" != "on" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then
  100. fn_print_warn_nl "Pushover alerts not enabled"
  101. fn_script_log_warn "Pushover alerts not enabled"
  102. elif [ -z "${pushovertoken}" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then
  103. fn_print_error_nl "Pushover token not set"
  104. echo " * https://github.com/GameServerManagers/LinuxGSM/wiki/Pushover"
  105. fn_script_error_warn "Pushover token not set"
  106. fi