From 450e0fc4235dec92f357fe9d74fe3be45aee7eb0 Mon Sep 17 00:00:00 2001 From: diamondburned Date: Mon, 15 Oct 2018 20:16:15 -0700 Subject: [PATCH 1/4] Design tweaks and JSON-safe escaping string --- lgsm/functions/alert_discord.sh | 92 +++++++++++++++++---------------- 1 file changed, 47 insertions(+), 45 deletions(-) diff --git a/lgsm/functions/alert_discord.sh b/lgsm/functions/alert_discord.sh index 4818f8721..75c8be2f0 100644 --- a/lgsm/functions/alert_discord.sh +++ b/lgsm/functions/alert_discord.sh @@ -5,60 +5,62 @@ # Website: https://linuxgsm.com # Description: Sends Discord alert. +if ! command -v jq > /dev/null; then + fn_print_fail_nl "Sending Discord alert: jq is missing." + fn_script_log_fatal "Sending Discord alert: jq is missing." +fi + +EscapedServername="$(echo -n "${servername}" | jq -sRr "@json")" +EscapedAlertBody="$(echo -n "${alertbody}" | jq -sRr "@json")" + +echo "$servername" > /tmp/servername + json=$(cat < Date: Mon, 15 Oct 2018 20:23:02 -0700 Subject: [PATCH 2/4] Fixed minify --- lgsm/functions/alert_discord.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lgsm/functions/alert_discord.sh b/lgsm/functions/alert_discord.sh index 75c8be2f0..5de1df245 100644 --- a/lgsm/functions/alert_discord.sh +++ b/lgsm/functions/alert_discord.sh @@ -54,8 +54,11 @@ EOF fn_print_dots "Sending Discord alert" -minified="$(echo -n "$json" | jq -c -M "@json")" -discordsend=$(${curlpath} -sSL -H "Content-Type: application/json" -X POST -d "${json}" "${discordwebhook}") +minified="$(echo -n "$json" | jq -c .)" + +echo "$minified" > /tmp/json + +discordsend=$(${curlpath} -sSL -H "Content-Type: application/json" -X POST -d "${minified}" "${discordwebhook}") if [ -n "${discordsend}" ]; then fn_print_fail_nl "Sending Discord alert: ${discordsend}" From 9fb6e69d76008e4a366bf4110b3ba40107beb876 Mon Sep 17 00:00:00 2001 From: diamondburned Date: Fri, 26 Oct 2018 11:45:33 -0700 Subject: [PATCH 3/4] Minor changes to fit merge requirements --- lgsm/functions/alert_discord.sh | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/lgsm/functions/alert_discord.sh b/lgsm/functions/alert_discord.sh index 5de1df245..9d7678baf 100644 --- a/lgsm/functions/alert_discord.sh +++ b/lgsm/functions/alert_discord.sh @@ -10,10 +10,8 @@ if ! command -v jq > /dev/null; then fn_script_log_fatal "Sending Discord alert: jq is missing." fi -EscapedServername="$(echo -n "${servername}" | jq -sRr "@json")" -EscapedAlertBody="$(echo -n "${alertbody}" | jq -sRr "@json")" - -echo "$servername" > /tmp/servername +escaped_servername="$(echo -n "${servername}" | jq -sRr "@json")" +escaped_alertbody="$(echo -n "${alertbody}" | jq -sRr "@json")" json=$(cat < /tmp/json - -discordsend=$(${curlpath} -sSL -H "Content-Type: application/json" -X POST -d "${minified}" "${discordwebhook}") +discordsend=$(${curlpath} -sSL -H "Content-Type: application/json" -X POST -d "$(echo -n "$json" | jq -c .)" "${discordwebhook}") if [ -n "${discordsend}" ]; then fn_print_fail_nl "Sending Discord alert: ${discordsend}" From c266a2fa7378a3d1fe92c496f397be7ebda31ebf Mon Sep 17 00:00:00 2001 From: diamondburned Date: Sat, 27 Oct 2018 14:59:46 -0700 Subject: [PATCH 4/4] Space -> Tab Not sure if this will be JSON-friendly... --- lgsm/functions/alert_discord.sh | 74 ++++++++++++++++----------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/lgsm/functions/alert_discord.sh b/lgsm/functions/alert_discord.sh index 9d7678baf..97e9ae2c1 100644 --- a/lgsm/functions/alert_discord.sh +++ b/lgsm/functions/alert_discord.sh @@ -1,13 +1,13 @@ #!/bin/bash # LinuxGSM alert_discord.sh function # Author: Daniel Gibbs -# Contributor: faflfama +# Contributor: faflfama, diamondburned # Website: https://linuxgsm.com # Description: Sends Discord alert. if ! command -v jq > /dev/null; then - fn_print_fail_nl "Sending Discord alert: jq is missing." - fn_script_log_fatal "Sending Discord alert: jq is missing." + fn_print_fail_nl "Sending Discord alert: jq is missing." + fn_script_log_fatal "Sending Discord alert: jq is missing." fi escaped_servername="$(echo -n "${servername}" | jq -sRr "@json")" @@ -15,37 +15,37 @@ escaped_alertbody="$(echo -n "${alertbody}" | jq -sRr "@json")" json=$(cat <