alert_pushbullet.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/bash
  2. # LinuxGSM alert_pushbullet.sh module
  3. # Author: Daniel Gibbs
  4. # Contributors: https://linuxgsm.com/contrib
  5. # Website: https://linuxgsm.com
  6. # Description: Sends Pushbullet Messenger alert.
  7. moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  8. json=$(
  9. cat << EOF
  10. {
  11. "channel_tag": "${channeltag}",
  12. "type": "note",
  13. "title": "${alerttitle}",
  14. "body": "Server Name\n${servername}\n\nInformation\n${alertmessage}\n\nGame\n${gamename}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}\n\n
  15. EOF
  16. )
  17. if [ -n "${querytype}" ]; then
  18. json+=$(
  19. cat << EOF
  20. Is my Game Server Online?\nhttps://ismygameserver.online/${imgsoquerytype}/${alertip}:${queryport}\n\n
  21. EOF
  22. )
  23. fi
  24. if [ -n "${alerturl}" ]; then
  25. json+=$(
  26. cat << EOF
  27. More info\n${alerturl}\n\n
  28. EOF
  29. )
  30. fi
  31. json+=$(
  32. cat << EOF
  33. Server Time\n$(date)"
  34. }
  35. EOF
  36. )
  37. fn_print_dots "Sending Pushbullet alert"
  38. pushbulletsend=$(curl --connect-timeout 3 -sSL -H "Access-Token: ${pushbullettoken}" -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)" "https://api.pushbullet.com/v2/pushes" | grep "error_code")
  39. if [ -n "${pushbulletsend}" ]; then
  40. fn_print_fail_nl "Sending Pushbullet alert: ${pushbulletsend}"
  41. fn_script_log_fail "Sending Pushbullet alert: ${pushbulletsend}"
  42. else
  43. fn_print_ok_nl "Sending Pushbullet alert"
  44. fn_script_log_pass "Sent Pushbullet alert"
  45. fi