alert.sh 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. alertsound="1"
  13. alerturl="https://gameservermanagers.com"
  14. alertbody="Testing LinuxGSM Alert. No action to be taken."
  15. }
  16. fn_alert_restart(){
  17. fn_script_log_info "Sending alert: Restarted: ${executable} not running"
  18. alertsubject="Alert - ${servicename} - Restarted"
  19. alertemoji="🚨"
  20. alertsound="2"
  21. alerturl="https://gameservermanagers.com"
  22. alertbody="${servicename} ${executable} not running"
  23. }
  24. fn_alert_restart_query(){
  25. fn_script_log_info "Sending alert: Restarted: ${gsquerycmd}"
  26. alertsubject="Alert - ${servicename} - Restarted"
  27. alertemoji="🚨"
  28. alertsound="2"
  29. alerturl="https://gameservermanagers.com"
  30. alertbody="gsquery.py failed to query: ${gsquerycmd}"
  31. }
  32. fn_alert_update(){
  33. fn_script_log_info "Sending alert: Updated"
  34. alertsubject="Alert - ${servicename} - Updated"
  35. alertemoji="🎮"
  36. alertsound="1"
  37. alerturl="https://gameservermanagers.com"
  38. alertbody="${gamename} received update"
  39. }
  40. fn_alert_permissions(){
  41. fn_script_log_info "Sending alert: Permissions error"
  42. alertsubject="Alert - ${servicename}: Permissions error"
  43. alertemoji="❗"
  44. alertsound="2"
  45. alerturl="https://gameservermanagers.com"
  46. alertbody="${servicename} has permissions issues"
  47. }
  48. if [ "${alert}" == "permissions" ]; then
  49. fn_alert_permissions
  50. elif [ "${alert}" == "restart" ]; then
  51. fn_alert_restart
  52. elif [ "${alert}" == "restartquery" ]; then
  53. fn_alert_restart_query
  54. elif [ "${alert}" == "test" ]; then
  55. fn_alert_test
  56. elif [ "${alert}" == "update" ]; then
  57. fn_alert_update
  58. fi
  59. if [ "${discordalert}" == "on" ]&&[ -n "${discordalert}" ]; then
  60. alert_discord.sh
  61. elif [ "${discordalert}" != "on" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then
  62. fn_print_warn_nl "Discord alerts not enabled"
  63. fn_script_log_warn "Discord alerts not enabled"
  64. elif [ -z "${discordtoken}" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then
  65. fn_print_error_nl "Discord token not set"
  66. echo " * https://github.com/GameServerManagers/LinuxGSM/wiki/Discord"
  67. fn_script_error_warn "Discord token not set"
  68. fi
  69. if [ "${emailalert}" == "on" ]&&[ -n "${email}" ]; then
  70. alert_email.sh
  71. elif [ "${emailalert}" != "on" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then
  72. fn_print_warn_nl "Email alerts not enabled"
  73. fn_script_log_warn "Email alerts not enabled"
  74. elif [ -z "${email}" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then
  75. fn_print_error_nl "Email not set"
  76. fn_script_log_error "Email not set"
  77. fi
  78. if [ "${iftttalert}" == "on" ]&&[ -n "${iftttalert}" ]; then
  79. alert_ifttt.sh
  80. elif [ "${iftttalert}" != "on" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then
  81. fn_print_warn_nl "IFTTT alerts not enabled"
  82. fn_script_log_warn "IFTTT alerts not enabled"
  83. elif [ -z "${ifttttoken}" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then
  84. fn_print_error_nl "IFTTT token not set"
  85. echo " * https://github.com/GameServerManagers/LinuxGSM/wiki/IFTTT"
  86. fn_script_error_warn "IFTTT token not set"
  87. fi
  88. if [ "${mailgunalert}" == "on" ]&&[ -n "${mailgunalert}" ]; then
  89. alert_mailgun.sh
  90. elif [ "${mailgunalert}" != "on" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then
  91. fn_print_warn_nl "Mailgun alerts not enabled"
  92. fn_script_log_warn "Mailgun alerts not enabled"
  93. elif [ -z "${mailguntoken}" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then
  94. fn_print_error_nl "Mailgun token not set"
  95. echo " * https://github.com/GameServerManagers/LinuxGSM/wiki/Mailgun"
  96. fn_script_error_warn "Mailgun token not set"
  97. fi
  98. if [ "${pushbulletalert}" == "on" ]&&[ -n "${pushbullettoken}" ]; then
  99. alert_pushbullet.sh
  100. elif [ "${pushbulletalert}" != "on" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then
  101. fn_print_warn_nl "Pushbullet alerts not enabled"
  102. fn_script_log_warn "Pushbullet alerts not enabled"
  103. elif [ -z "${pushbullettoken}" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then
  104. fn_print_error_nl "Pushbullet token not set"
  105. echo " * https://github.com/GameServerManagers/LinuxGSM/wiki/Pushbullet"
  106. fn_script_error_warn "Pushbullet token not set"
  107. fi
  108. if [ "${pushoveralert}" == "on" ]&&[ -n "${pushoveralert}" ]; then
  109. alert_pushover.sh
  110. elif [ "${pushoveralert}" != "on" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then
  111. fn_print_warn_nl "Pushover alerts not enabled"
  112. fn_script_log_warn "Pushover alerts not enabled"
  113. elif [ -z "${pushovertoken}" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then
  114. fn_print_error_nl "Pushover token not set"
  115. echo " * https://github.com/GameServerManagers/LinuxGSM/wiki/Pushover"
  116. fn_script_error_warn "Pushover token not set"
  117. fi
  118. if [ "${telegramalert}" == "on" ]&&[ -n "${telegramtoken}" ]; then
  119. alert_telegram.sh
  120. elif [ "${telegramalert}" != "on" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then
  121. fn_print_warn_nl "Telegram Messages not enabled"
  122. fn_script_log_warn "Telegram Messages not enabled"
  123. elif [ -z "${telegramtoken}" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then
  124. fn_print_error_nl "Telegram token not set."
  125. echo " * https://github.com/GameServerManagers/LinuxGSM/wiki/Telegram"
  126. fn_script_error_warn "Telegram token not set."
  127. elif [ -z "${telegramchatid}" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then
  128. fn_print_error_nl "Telegram chat id not set."
  129. echo " * https://github.com/GameServerManagers/LinuxGSM/wiki/Telegram"
  130. fn_script_error_warn "Telegram chat id not set."
  131. fi