From a1ab4c6f4bce3413525d1fd538f470cb2f21833c Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Sun, 20 Aug 2017 21:36:46 +0100 Subject: [PATCH] further improvements to alerts --- lgsm/functions/alert.sh | 24 ++++++++++++------------ lgsm/functions/alert_email.sh | 3 ++- lgsm/functions/alert_pushbullet.sh | 22 ++++++++++++---------- lgsm/functions/alert_telegram.sh | 9 +++++---- 4 files changed, 31 insertions(+), 27 deletions(-) diff --git a/lgsm/functions/alert.sh b/lgsm/functions/alert.sh index 3d51cbe1e..7427d9e4a 100644 --- a/lgsm/functions/alert.sh +++ b/lgsm/functions/alert.sh @@ -9,42 +9,42 @@ local commandaction="Alert" fn_alert_test(){ fn_script_log_info "Sending test alert" - alertsubject="LinuxGSM Alert - Test - ${servername}" + alertsubject="Alert - ${servicename}: Test" alertemoji="🚨" alerturl="https://gameservermanagers.com" alertbody="Testing LinuxGSM Alert. No action to be taken." } fn_alert_restart(){ - fn_script_log_info "Sending restart alert: ${executable} process not running" - alertsubject="LinuxGSM Alert - Restarted - ${servername}" + fn_script_log_info "Sending alert: Restarted: ${executable} not running" + alertsubject="Alert - ${servicename}: Restarted" alertemoji="🚨" alerturl="https://gameservermanagers.com" - alertbody="${servicename} ${executable} process not running" + alertbody="${servicename} ${executable} not running" } fn_alert_restart_query(){ - fn_script_log_info "Sending restart alert: ${gsquerycmd}" - alertsubject="LinuxGSM Alert- Restarted - ${servername}" + fn_script_log_info "Sending alert: Restarted: ${gsquerycmd}" + alertsubject="Alert - ${servicename}: Restarted" alertemoji="🚨" alerturl="https://gameservermanagers.com" alertbody="gsquery.py failed to query: ${gsquerycmd}" } fn_alert_update(){ - fn_script_log_info "Sending update alert" - alertsubject="LinuxGSM Alert- Updated - ${servername}" + fn_script_log_info "Sending alert: Updated" + alertsubject="Alert - ${servicename}: Updated" alertemoji="🎮" alerturl="https://gameservermanagers.com" - alertbody="${servicename} received update" + alertbody="${gamename} received update" } fn_alert_permissions(){ - fn_script_log_info "Sending permissions error alert" - alertsubject="LinuxGSM Alert - Error - ${servername}" + fn_script_log_info "Sending alert: Permissions error" + alertsubject="Alert - ${servicename}: Permissions error" alertemoji="❗" alerturl="https://gameservermanagers.com" - alertbody="${servicename} has permissions issues." + alertbody="${servicename} has permissions issues" } if [ "${alert}" == "permissions" ]; then diff --git a/lgsm/functions/alert_email.sh b/lgsm/functions/alert_email.sh index ab6922d0f..0fb99223d 100644 --- a/lgsm/functions/alert_email.sh +++ b/lgsm/functions/alert_email.sh @@ -2,7 +2,7 @@ # LinuxGSM alert_email.sh function # Author: Daniel Gibbs # Website: https://gameservermanagers.com -# Description: Sends email alert including server details and logs. +# Description: Sends email alert. local commandname="ALERT" local commandaction="Alert" @@ -211,6 +211,7 @@ fn_alert_email_template_logs(){ } fn_print_dots "Sending alert: ${email}" +sleep 0.5 fn_script_log_info "Sending alert: ${email}" info_distro.sh info_config.sh diff --git a/lgsm/functions/alert_pushbullet.sh b/lgsm/functions/alert_pushbullet.sh index 9a632899b..27e8d2ba3 100644 --- a/lgsm/functions/alert_pushbullet.sh +++ b/lgsm/functions/alert_pushbullet.sh @@ -2,7 +2,7 @@ # LinuxGSM alert_pushbullet.sh function # Author: Daniel Gibbs # Website: https://gameservermanagers.com -# Description: Sends Pushbullet alert including the server status. +# Description: Sends Pushbullet alert. local commandname="ALERT" local commandaction="Alert" @@ -24,20 +24,22 @@ fn_rawurlencode() { esac encoded+="${o}" done - echo "${encoded}" # If echo is faster, let's just echo it. + echo "${encoded}" } -pbalertbody=$(fn_rawurlencode "${alertbody}") +pbalertbody=$(fn_rawurlencode "Message: ${alertbody} - More Info: ${alerturl}") pbalertsubject=$(fn_rawurlencode "${alertsubject}") fn_print_dots "Sending Pushbullet alert" -sleep 1 -pushbulletsend=$(curl --silent -u """${pushbullettoken}"":" -d channel_tag="${channeltag}" -d type="note" -d body="${pbalertbody}" -d title="${pbalertsubject}" 'https://api.pushbullet.com/v2/pushes'|grep -o invalid_access_token|uniq) +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') -if [ "${pushbulletsend}" == "invalid_access_token" ]; then - fn_print_fail_nl "Sending Pushbullet alert: invalid_access_token" - fn_script_log_fatal "Sending Pushbullet alert: invalid_access_token" +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}" 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 \ No newline at end of file diff --git a/lgsm/functions/alert_telegram.sh b/lgsm/functions/alert_telegram.sh index e0e0bde54..ad94fb3ed 100644 --- a/lgsm/functions/alert_telegram.sh +++ b/lgsm/functions/alert_telegram.sh @@ -2,7 +2,7 @@ # LinuxGSM alert_telegram.sh function # Author: Bennet Becker # Website: https://bytegaming.de -# Description: Sends Telegram Message alert including the server status. +# Description: Sends Telegram Message alert. local commandname="ALERT" local commandaction="Alert" @@ -12,14 +12,15 @@ local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))" json=$(cat <${alertsubject} ${alertemoji}\n\n${alertbody}", "parse_mode": "HTML", + "text": "${alertemoji} ${alertsubject} ${alertemoji}\nMessage: ${alertbody}\nServer name: ${servername}\nHostname: ${HOSTNAME}\nMore info: ${alerturl}", + "disable_web_page_preview": "yes", } EOF ) -fn_print_dots "Sending Telegram Message" -sleep 1 +fn_print_dots "Sending Telegram Alert" +sleep 0.5 telegramsend=$(curl -sSL -H "Content-Type: application/json" -X POST -d """$json""" "https://api.telegram.org/bot${telegramtoken}/sendMessage" | grep -Po '(?<="description":").*?(?=")'|uniq) if [ -n "${telegramsend}" ]; then