alert_pushover.sh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/bin/bash
  2. # LinuxGSM alert_pushover.sh module
  3. # Author: Daniel Gibbs
  4. # Contributors: https://linuxgsm.com/contrib
  5. # Website: https://linuxgsm.com
  6. # Description: Sends Pushover alert.
  7. moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  8. fn_print_dots "Sending Pushover alert"
  9. # Different alerts are given different priorities and notification sounds.
  10. if [ "${alertsound}" == "1" ]; then
  11. alertsound=""
  12. alertpriority="0"
  13. elif [ "${alertsound}" == "2" ]; then
  14. # restarted.
  15. alertsound="siren"
  16. alertpriority="1"
  17. else
  18. alertsound=""
  19. alertpriority="0"
  20. fi
  21. message=" <b>Server name</b><br>${servername}<br><br><b>Information</b><br>${alertmessage}<br><br><b>Game</b><br>${gamename}<br><br><b>Server IP</b><br>${alertip}:${port}<br><br><b>Hostname</b><br>${HOSTNAME}<br><br>"
  22. if [ -n "${querytype}" ]; then
  23. message+="<b>Is my Game Server Online?</b><br><a href='https://ismygameserver.online/${imgsoquerytype}/${alertip}:${queryport}'>Check here</a><br><br>"
  24. fi
  25. if [ -n "${alerturl}" ]; then
  26. message+="<b>More info</b><br><a href='${alerturl}'>${alerturl}</a><br><br>"
  27. fi
  28. message+="Server Time<br>$(date)"
  29. pushoversend=$(curl --connect-timeout 3 -sS \
  30. -F token="${pushovertoken}" \
  31. -F user="${pushoveruserkey}" \
  32. -F html="1" \
  33. -F sound="${alertsound}" \
  34. -F priority="${alertpriority}" \
  35. -F title="${alerttitle}" \
  36. -F message="${message}" \
  37. "https://api.pushover.net/1/messages.json" | grep errors)
  38. if [ -n "${pushoversend}" ]; then
  39. fn_print_fail_nl "Sending Pushover alert: ${pushoversend}"
  40. fn_script_log_fail "Sending Pushover alert: ${pushoversend}"
  41. else
  42. fn_print_ok_nl "Sending Pushover alert"
  43. fn_script_log_pass "Sent Pushover alert"
  44. fi