alert_pushbullet.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/bin/bash
  2. # LinuxGSM alert_pushbullet.sh module
  3. # Author: Daniel Gibbs
  4. # Contributors: http://linuxgsm.com/contrib
  5. # Website: https://linuxgsm.com
  6. # Description: Sends Pushbullet Messenger alert.
  7. moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  8. jsoninfo=$(
  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\nMore info\n${alerturl}\n\nServer Time\n$(date)"
  15. }
  16. EOF
  17. )
  18. jsonnoinfo=$(
  19. cat << EOF
  20. {
  21. "channel_tag": "${channeltag}",
  22. "type": "note",
  23. "title": "${alerttitle}",
  24. "body": "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)"
  25. }
  26. EOF
  27. )
  28. if [ -z "${alerturl}" ]; then
  29. json="${jsonnoinfo}"
  30. else
  31. json="${jsoninfo}"
  32. fi
  33. fn_print_dots "Sending Pushbullet alert"
  34. 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")
  35. if [ -n "${pushbulletsend}" ]; then
  36. fn_print_fail_nl "Sending Pushbullet alert: ${pushbulletsend}"
  37. fn_script_log_fail "Sending Pushbullet alert: ${pushbulletsend}"
  38. else
  39. fn_print_ok_nl "Sending Pushbullet alert"
  40. fn_script_log_pass "Sent Pushbullet alert"
  41. fi