alert.sh 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/bin/bash
  2. # LGSM 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="LGSM - Test Alert - ${servername}"
  11. alertbody="LGSM test alert, how you read?"
  12. }
  13. fn_alert_restart(){
  14. fn_script_log_info "Sending restart alert: ${executable} process not running"
  15. alertsubject="LGSM - 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="LGSM - 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="LGSM - Updated - ${servername}"
  26. alertbody="${servicename} received update"
  27. }
  28. if [ "${alert}" == "restart" ]; then
  29. fn_alert_restart
  30. elif [ "${alert}" == "restartquery" ]; then
  31. fn_alert_restart_query
  32. elif [ "${alert}" == "update" ]; then
  33. fn_alert_update
  34. elif [ "${alert}" == "test" ]; then
  35. fn_alert_test
  36. fi
  37. if [ "${emailnotification}" == "on" ]||[ "${emailalert}" == "on" ]&&[ -n "${email}" ]; then
  38. alert_email.sh
  39. elif [ "${emailnotification}" != "on" ]||[ "${emailalert}" != "on" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then
  40. fn_print_warn_nl "Email alerts not enabled"
  41. fn_script_log_warn "Email alerts not enabled"
  42. elif [ -z "${email}" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then
  43. fn_print_error_nl "Email not set"
  44. fn_script_log_error "Email not set"
  45. fi
  46. if [ "${pushbulletalert}" == "on" ]&&[ -n "${pushbullettoken}" ]; then
  47. alert_pushbullet.sh
  48. elif [ "${pushbulletalert}" != "on" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then
  49. fn_print_warn_nl "Pushbullet alerts not enabled"
  50. fn_script_log_warn "Pushbullet alerts not enabled"
  51. elif [ -z "${pushbullettoken}" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then
  52. fn_print_error_nl "Pushbullet token not set"
  53. fn_script_error_warn "Pushbullet token not set"
  54. fi