4
0

alert_gotify.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  8. json=$(
  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\n
  13. EOF
  14. )
  15. if [ -n "${querytype}" ]; then
  16. json+=$(
  17. cat << EOF
  18. Is my Game Server Online?\nhttps://ismygameserver.online/${imgsoquerytype}/${alertip}:${queryport}\n\n
  19. EOF
  20. )
  21. fi
  22. if [ -n "${alerturl}" ]; then
  23. json+=$(
  24. cat << EOF
  25. More info\n${alerturl}\n\n
  26. EOF
  27. )
  28. fi
  29. json+=$(
  30. cat << EOF
  31. Server Time\n$(date)",
  32. "priority": 5
  33. }
  34. EOF
  35. )
  36. fn_print_dots "Sending Gotify alert"
  37. gotifysend=$(curl --connect-timeout 3 -sSL "${gotifywebhook}/message"?token="${gotifytoken}" -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)")
  38. if [ -n "${gotifysend}" ]; then
  39. fn_print_ok_nl "Sending Gotify alert"
  40. fn_script_log_pass "Sending Gotify alert"
  41. else
  42. fn_print_fail_nl "Sending Gotify alert: ${gotifysend}"
  43. fn_script_log_fail "Sending Gotify alert: ${gotifysend}"
  44. fi