alert_pushbullet.sh 1.1 KB

123456789101112131415161718192021222324252627282930
  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. json=$(
  9. cat << EOF
  10. {
  11. "channel_tag": "${channeltag}",
  12. "type": "note",
  13. "title": "${alertemoji} ${alertsubject} ${alertemoji}",
  14. "body": "Server name\n${servername}\n\nMessage\n${alertbody}\n\nGame\n${gamename}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}\n\nMore info\n${alerturl}"
  15. }
  16. EOF
  17. )
  18. fn_print_dots "Sending Pushbullet alert"
  19. pushbulletsend=$(curl --connect-timeout 10 -sSL -u """${pushbullettoken}"":" -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)" "https://api.pushbullet.com/v2/pushes" | grep "error_code")
  20. if [ -n "${pushbulletsend}" ]; then
  21. fn_print_fail_nl "Sending Pushbullet alert: ${pushbulletsend}"
  22. fn_script_log_fatal "Sending Pushbullet alert: ${pushbulletsend}"
  23. else
  24. fn_print_ok_nl "Sending Pushbullet alert"
  25. fn_script_log_pass "Sent Pushbullet alert"
  26. fi