4
0

alert.sh 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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