alert_gotify.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/bash
  2. # LinuxGSM alert_gotify.sh module
  3. # Author: Daniel Gibbs
  4. # Contributors: https://linuxgsm.com/contrib
  5. # Website: https://linuxgsm.com
  6. # Description: Sends Gotify alert.
  7. module_selfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  8. jsoninfo=$(
  9. cat << EOF
  10. {
  11. "title": "${alerttitle}",
  12. "message": "Server Name\n${servername}\n\nInformation\n${alertmessage}\n\nGame\n${gamename}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}\n\nMore info\n${alerturl}\n\nServer Time\n$(date)",
  13. "priority": 5
  14. }
  15. EOF
  16. )
  17. jsonnoinfo=$(
  18. cat << EOF
  19. {
  20. "title": "${alerttitle}",
  21. "message": "Server Name\n${servername}\n\nInformation\n${alertmessage}\n\nGame\n${gamename}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}\n\nServer Time\n$(date)",
  22. "priority": 5
  23. }
  24. EOF
  25. )
  26. if [ -z "${alerturl}" ]; then
  27. json="${jsonnoinfo}"
  28. else
  29. json="${jsoninfo}"
  30. fi
  31. fn_print_dots "Sending Gotify alert"
  32. gotifysend=$(curl --connect-timeout 3 -sSL "${gotifywebhook}/message"?token="${gotifytoken}" -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)")
  33. if [ -n "${gotifysend}" ]; then
  34. fn_print_ok_nl "Sending Gotify alert"
  35. fn_script_log_pass "Sending Gotify alert"
  36. else
  37. fn_print_fail_nl "Sending Gotify alert: ${gotifysend}"
  38. fn_script_log_fail "Sending Gotify alert: ${gotifysend}"
  39. fi