alert.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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="LinuxGSM - Test Alert - ${servername}"
  11. alertbody="LinuxGSM test alert, how you read?"
  12. }
  13. fn_alert_restart(){
  14. fn_script_log_info "Sending restart alert: ${executable} process not running"
  15. alertsubject="LinuxGSM - Restarted - ${servername}"
  16. alertbody="${servicename} ${executable} process not running"
  17. }
  18. fn_alert_restart_query(){
  19. fn_script_log_info "Sending restart alert: ${gsquerycmd}"
  20. alertsubject="LinuxGSM - Restarted - ${servername}"
  21. alertbody="gsquery.py failed to query: ${gsquerycmd}"
  22. }
  23. fn_alert_update(){
  24. fn_script_log_info "Sending update alert"
  25. alertsubject="LinuxGSM - Updated - ${servername}"
  26. alertbody="${servicename} received update"
  27. }
  28. fn_alert_permissions(){
  29. fn_script_log_info "Sending permissions error alert"
  30. alertsubject="LinuxGSM - Error - ${servername}"
  31. alertbody="${servicename} has permissions issues."
  32. }
  33. if [ "${alert}" == "permissions" ]; then
  34. fn_alert_permissions
  35. elif [ "${alert}" == "restart" ]; then
  36. fn_alert_restart
  37. elif [ "${alert}" == "restartquery" ]; then
  38. fn_alert_restart_query
  39. elif [ "${alert}" == "test" ]; then
  40. fn_alert_test
  41. elif [ "${alert}" == "update" ]; then
  42. fn_alert_update
  43. fi
  44. if [ "${emailalert}" == "on" ]&&[ -n "${email}" ]; then
  45. alert_email.sh
  46. elif [ "${emailalert}" != "on" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then
  47. fn_print_warn_nl "Email alerts not enabled"
  48. fn_script_log_warn "Email alerts not enabled"
  49. elif [ -z "${email}" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then
  50. fn_print_error_nl "Email not set"
  51. fn_script_log_error "Email not set"
  52. fi
  53. if [ "${pushbulletalert}" == "on" ]&&[ -n "${pushbullettoken}" ]; then
  54. alert_pushbullet.sh
  55. elif [ "${pushbulletalert}" != "on" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then
  56. fn_print_warn_nl "Pushbullet alerts not enabled"
  57. fn_script_log_warn "Pushbullet alerts not enabled"
  58. elif [ -z "${pushbullettoken}" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then
  59. fn_print_error_nl "Pushbullet token not set"
  60. fn_script_error_warn "Pushbullet token not set"
  61. fi
  62. if [ "${telegramalert}" == "on" ]&&[ -n "${telegramapikey}" ]; then
  63. alert_telegram.sh
  64. elif [ "${telegramalert}" != "on" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then
  65. fn_print_warn_nl "Telegram Messages not enabled"
  66. fn_script_log_warn "Telegram Messages not enabled"
  67. elif [ -z "${telegramapikey}" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then
  68. fn_print_error_nl "Telegram API-key not set. Get one from @botfather"
  69. fn_script_error_warn "Telegram API-key not set. Get one from @botfather"
  70. fi
  71. if [ "${discordalert}" == "on" ]&&[ -n "${discordalert}" ]; then
  72. alert_discord.sh
  73. elif [ "${discordalert}" != "on" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then
  74. fn_print_warn_nl "Discord alerts not enabled"
  75. fn_script_log_warn "Discord alerts not enabled"
  76. elif [ -z "${discordalert}" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then
  77. fn_print_error_nl "Discord token not set"
  78. fn_script_error_warn "Discord token not set"
  79. fi