alert.sh 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 commandnane="ALERT"
  7. local commandaction="Alert"
  8. # Cannot have selfname as breaks the function.
  9. #local selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
  10. fn_alert_test(){
  11. fn_script_log_info "Sending test alert"
  12. alertsubject="LGSM - Test Alert - ${servername}"
  13. alertbody="LGSM test alert, how you read?"
  14. }
  15. fn_alert_restart(){
  16. fn_script_log_info "Sending restart alert: ${executable} process not running"
  17. alertsubject="LGSM - Restarted - ${servername}"
  18. alertbody="${servicename} ${executable} process not running"
  19. }
  20. fn_alert_restart_query(){
  21. fn_script_log_info "Sending restart alert: ${gsquerycmd}"
  22. alertsubject="LGSM - Restarted - ${servername}"
  23. alertbody="gsquery.py failed to query: ${gsquerycmd}"
  24. }
  25. fn_alert_update(){
  26. fn_script_log_info "Sending update alert"
  27. alertsubject="LGSM - Updated - ${servername}"
  28. alertbody="${servicename} recieved update"
  29. }
  30. if [ "${alert}" == "restart" ]; then
  31. fn_alert_restart
  32. elif [ "${alert}" == "restartquery" ]; then
  33. fn_alert_restart_query
  34. elif [ "${alert}" == "update" ]; then
  35. fn_alert_update
  36. elif [ "${alert}" == "test" ]; then
  37. fn_alert_test
  38. fi
  39. if [ "${emailnotification}" == "on" ]||[ "${emailalert}" == "on" ]&&[ -n "${email}" ]; then
  40. alert_email.sh
  41. elif [ "${emailnotification}" != "on" ]||[ "${emailalert}" != "on" ]&&[ "${selfname}" == "command_test_alert.sh" ]; then
  42. fn_print_warn_nl "Email alerts not enabled"
  43. fn_script_log_warn "Email alerts not enabled"
  44. elif [ -z "${email}" ]&&[ "${selfname}" == "command_test_alert.sh" ]; then
  45. fn_print_error_nl "Email not set"
  46. fn_script_log_error "Email not set"
  47. fi
  48. if [ "${pushbulletalert}" == "on" ]&&[ -n "${pushbullettoken}" ]; then
  49. alert_pushbullet.sh
  50. elif [ "${pushbulletalert}" != "on" ]&&[ "${selfname}" == "command_test_alert.sh" ]; then
  51. fn_print_warn_nl "Pushbullet alerts not enabled"
  52. fn_script_log_warn "Pushbullet alerts not enabled"
  53. elif [ -z "${pushbullettoken}" ]&&[ "${selfname}" == "command_test_alert.sh" ]; then
  54. fn_print_error_nl "Pushbullet token not set"
  55. fn_script_error_warn "Pushbullet token not set"
  56. fi