Browse Source

Pushbullet now uses json

pull/1601/head
Daniel Gibbs 8 years ago
parent
commit
4ee4ead9a5
  1. 42
      lgsm/functions/alert_pushbullet.sh

42
lgsm/functions/alert_pushbullet.sh

@ -2,44 +2,30 @@
# LinuxGSM alert_pushbullet.sh function # LinuxGSM alert_pushbullet.sh function
# Author: Daniel Gibbs # Author: Daniel Gibbs
# Website: https://gameservermanagers.com # Website: https://gameservermanagers.com
# Description: Sends Pushbullet alert. # Description: Sends Pushbullet Messenger alert.
local commandname="ALERT" local commandname="ALERT"
local commandaction="Alert" local commandaction="Alert"
local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))" local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
# converts text to ascii then passes to curl. allowing special characters to be sent e.g % json=$(cat <<EOF
# http://stackoverflow.com/a/10660730 {
fn_rawurlencode() { "channel_tag": "${channeltag}",
local string="${1}" "type": "note",
local strlen=${#string} "title": "${alertemoji} ${alertsubject} ${alertemoji}",
local encoded="" "body": "${alertbody}"
local pos c o
for (( pos=0 ; pos<strlen ; pos++ )); do
c=${string:$pos:1}
case "$c" in
[-_.~a-zA-Z0-9] ) o="${c}" ;;
* ) printf -v o '%%%02x' "'$c"
esac
encoded+="${o}"
done
echo "${encoded}"
} }
EOF
pbalertbody=$(fn_rawurlencode "Message: ${alertbody} - More Info: ${alerturl}") )
pbalertsubject=$(fn_rawurlencode "${alertsubject}")
fn_print_dots "Sending Pushbullet alert" fn_print_dots "Sending Pushbullet alert"
sleep 0.5 sleep 0.5
pushbulletsend=$(curl --silent -u """${pushbullettoken}"":" -d channel_tag="${channeltag}" -d type="note" -d body="${pbalertbody}" -d title="${alertemoji} ${pbalertsubject} ${alertemoji}" 'https://api.pushbullet.com/v2/pushes') pushbulletsend=$(curl -sSL -u """${pushbullettoken}"":" -H "Content-Type: application/json" -X POST -d """${json}""" "https://api.pushbullet.com/v2/pushes" | grep "error_code")
pberror=$(echo "${pushbulletsend}" |grep "error_code") if [ -n "${pushbulletsend}" ]; then
pberrormsg=$(echo "${pushbulletsend}" |sed -n -e 's/^.*error_code//p' | tr -d '=\";,:{}') fn_print_fail_nl "Sending Pushbullet alert: ${pushbulletsend}"
if [ -n "${pberror}" ]; then fn_script_log_fatal "Sending Pushbullet alert: ${pushbulletsend}"
fn_print_fail_nl "Sending Pushbullet alert: ${pberrormsg}"
fn_script_log_fatal "Sending Pushbullet alert: ${pberrormsg}"
else else
fn_print_ok_nl "Sending Pushbullet alert" fn_print_ok_nl "Sending Pushbullet alert"
fn_script_log_pass "Sent Pushbullet alert" fn_script_log_pass "Sent Pushbullet alert"
fi fi

Loading…
Cancel
Save