Browse Source

Alert updates

pull/1601/head
Daniel Gibbs 8 years ago
parent
commit
2546170efd
  1. 18
      lgsm/functions/alert_discord.sh
  2. 34
      lgsm/functions/alert_pushbullet.sh

18
lgsm/functions/alert_discord.sh

@ -5,6 +5,10 @@
# Website: https://gameservermanagers.com
# Description: Sends Discord alert including the server status.
local commandname="ALERT"
local commandaction="Alert"
local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"
json=$(cat <<EOF
{
"username":"LinuxGSM",
@ -51,8 +55,14 @@ json=$(cat <<EOF
EOF
)
#curl -X POST --data "Content-Type: application/json" -X POST -d """${json}""" "${discordwebhook}"
fn_print_dots "Sending Discord alert"
sleep 0.5
discordsend=$(curl -sSL -H "Content-Type: application/json" -X POST -d """${json}""" ${discordwebhook})
echo "$json" >f
curl -v -X POST --data @f ${discordwebhook}
if [ -n "${discordsend}" ]; then
fn_print_fail_nl "Sending Discord alert: ${discordsend}"
fn_script_log_fatal "Sending Discord alert: ${discordsend}"
else
fn_print_ok_nl "Sending Discord alert"
fn_script_log_pass "Sending Discord alert"
fi

34
lgsm/functions/alert_pushbullet.sh

@ -11,20 +11,20 @@ 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 %
# http://stackoverflow.com/a/10660730
fn_rawurlencode() {
local string="${1}"
local strlen=${#string}
local encoded=""
local pos c o
local string="${1}"
local strlen=${#string}
local encoded=""
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}"
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}"
}
pbalertbody=$(fn_rawurlencode "Message: ${alertbody} - More Info: ${alerturl}")
@ -37,9 +37,9 @@ pushbulletsend=$(curl --silent -u """${pushbullettoken}"":" -d channel_tag="${ch
pberror=$(echo "${pushbulletsend}" |grep "error_code")
pberrormsg=$(echo "${pushbulletsend}" |sed -n -e 's/^.*error_code//p' | tr -d '=\";,:{}')
if [ -n "${pberror}" ]; then
fn_print_fail_nl "Sending Pushbullet alert: ${pberrormsg}"
fn_script_log_fatal "Sending Pushbullet alert: ${pberrormsg}"
fn_print_fail_nl "Sending Pushbullet alert: ${pberrormsg}"
fn_script_log_fatal "Sending Pushbullet alert: ${pberrormsg}"
else
fn_print_ok_nl "Sending Pushbullet alert"
fn_script_log_pass "Sent Pushbullet alert"
fn_print_ok_nl "Sending Pushbullet alert"
fn_script_log_pass "Sent Pushbullet alert"
fi
Loading…
Cancel
Save