From af08ac11c2dccec0a4cf69d4a0ba3780a0e07189 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Thu, 19 Oct 2023 20:06:48 +0100 Subject: [PATCH] refactor: update alert emojis and add server time - Updated the alert emojis in the `alert.sh` module. - Added the server time to the alert messages in various modules (`alert_discord.sh`, `alert_gotify.sh`, `alert_ifttt.sh`, `alert_pushbullet.sh`, `alert_pushover.sh`, `alert_rocketchat.sh`, and `alert_slack.sh`). --- lgsm/modules/alert.sh | 8 +-- lgsm/modules/alert_discord.sh | 21 ++++++- lgsm/modules/alert_gotify.sh | 4 +- lgsm/modules/alert_ifttt.sh | 4 +- lgsm/modules/alert_pushbullet.sh | 4 +- lgsm/modules/alert_pushover.sh | 4 +- lgsm/modules/alert_rocketchat.sh | 40 ++++++++++-- lgsm/modules/alert_slack.sh | 101 ++++++++++++++++++++++++++++++- lgsm/modules/alert_telegram.sh | 4 +- lgsm/modules/info_messages.sh | 3 + 10 files changed, 170 insertions(+), 23 deletions(-) diff --git a/lgsm/modules/alert.sh b/lgsm/modules/alert.sh index 30da09e955..5e06f84d66 100644 --- a/lgsm/modules/alert.sh +++ b/lgsm/modules/alert.sh @@ -53,7 +53,7 @@ fn_alert_stopped() { fn_alert_started() { fn_script_log_info "Sending alert: ${selfname} has started" alertaction="Started" - alertemoji="✅" + alertemoji="✔️" alertsound="1" alertmessage="${selfname} has been started." # Green @@ -64,7 +64,7 @@ fn_alert_started() { fn_alert_restarted() { fn_script_log_info "Sending alert: ${selfname} has restarted" alertaction="Restarted" - alertemoji="↺" + alertemoji="🗘" alertsound="1" alertmessage="${selfname} has been restarted." # Green @@ -110,7 +110,7 @@ fn_alert_update() { fn_alert_check_update() { fn_script_log_info "Sending alert: ${gamename} update available: ${remotebuildversion}" alertaction="Checked for Update" - alertemoji="🎮" + alertemoji="🎉" alertsound="1" alertmessage="${gamename} update available: ${remotebuildversion}" # Blue @@ -144,7 +144,7 @@ fn_alert_permissions() { fn_alert_config() { fn_script_log_info "Sending alert: ${selfname} has received a new _default.cfg" alertaction="Updated _default.cfg" - alertemoji="🎮" + alertemoji="🎉" alertsound="1" alertmessage="${selfname} has received a new _default.cfg." # Blue diff --git a/lgsm/modules/alert_discord.sh b/lgsm/modules/alert_discord.sh index 8bfea9fa2f..e8d7d7a9cb 100644 --- a/lgsm/modules/alert_discord.sh +++ b/lgsm/modules/alert_discord.sh @@ -51,11 +51,21 @@ jsoninfo=$( "name": "Hostname", "value": "${HOSTNAME}", "inline": true + }, + { + "name": "More info", + "value": "${alerturl}", + "inline": true + }, + { + "name": "Server Time", + "value": "$(date)", + "inline": true } ], "footer": { "icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg", - "text": "Sent by LinuxGSM ${version}" + "text": "Sent by LinuxGSM ${version} - $(date)" } } ] @@ -76,7 +86,7 @@ jsonnoinfo=$( "url": "", "icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg" }, - "title": "${alertemoji} ${alertaction} - ${servername} ${alertemoji}", + "title": "${alerttitle}", "url": "", "description": "", "color": "${alertcolourdec}", @@ -107,11 +117,16 @@ jsonnoinfo=$( "name": "Hostname", "value": "${HOSTNAME}", "inline": true + }, + { + "name": "Server Time", + "value": "$(date)", + "inline": true } ], "footer": { "icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg", - "text": "Sent by LinuxGSM ${version}" + "text": "Sent by LinuxGSM ${version} - $(date)" } } ] diff --git a/lgsm/modules/alert_gotify.sh b/lgsm/modules/alert_gotify.sh index 232c108933..2ab6e9eb7c 100644 --- a/lgsm/modules/alert_gotify.sh +++ b/lgsm/modules/alert_gotify.sh @@ -11,7 +11,7 @@ jsoninfo=$( cat << EOF { "title": "${alerttitle}", - "message": "Server Name\n${servername}\n\nInformation\n${alertmessage}\n\nGame\n${gamename}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}\n\nMore info\n${alerturl}", + "message": "Server Name\n${servername}\n\nInformation\n${alertmessage}\n\nGame\n${gamename}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}\n\nMore info\n${alerturl}\n\nServer Time\n$(date)", "priority": 5 } EOF @@ -21,7 +21,7 @@ jsonnoinfo=$( cat << EOF { "title": "${alerttitle}", - "message": "Server Name\n${servername}\n\nInformation\n${alertmessage}\n\nGame\n${gamename}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}", + "message": "Server Name\n${servername}\n\nInformation\n${alertmessage}\n\nGame\n${gamename}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}\n\nServer Time\n$(date)", "priority": 5 } EOF diff --git a/lgsm/modules/alert_ifttt.sh b/lgsm/modules/alert_ifttt.sh index d6affa6222..77932569bf 100644 --- a/lgsm/modules/alert_ifttt.sh +++ b/lgsm/modules/alert_ifttt.sh @@ -12,7 +12,7 @@ jsoninfo=$( { "value1": "${selfname}", "value2": "${alerttitle}", - "value3": "Server Name\n${servername}\n\nInformation\n${alertmessage}\n\nGame\n${gamename}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}\n\nMore info\n${alerturl}" + "value3": "Server Name\n${servername}\n\nInformation\n${alertmessage}\n\nGame\n${gamename}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}\n\nMore info\n${alerturl}\n\nServer Time\n$(date)" } EOF ) @@ -22,7 +22,7 @@ jsonnoinfo=$( { "value1": "${selfname}", "value2": "${alerttitle}", - "value3": "Server Name\n${servername}\n\nInformation\n${alertmessage}\n\nGame\n${gamename}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}" + "value3": "Server Name\n${servername}\n\nInformation\n${alertmessage}\n\nGame\n${gamename}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}\n\nServer Time\n$(date)" } EOF ) diff --git a/lgsm/modules/alert_pushbullet.sh b/lgsm/modules/alert_pushbullet.sh index 47419e663e..dedd432686 100644 --- a/lgsm/modules/alert_pushbullet.sh +++ b/lgsm/modules/alert_pushbullet.sh @@ -13,7 +13,7 @@ jsoninfo=$( "channel_tag": "${channeltag}", "type": "note", "title": "${alerttitle}", - "body": "Server Name\n${servername}\n\nInformation\n${alertmessage}\n\nGame\n${gamename}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}\n\nMore info\n${alerturl}" + "body": "Server Name\n${servername}\n\nInformation\n${alertmessage}\n\nGame\n${gamename}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}\n\nMore info\n${alerturl}\n\nServer Time\n$(date)" } EOF ) @@ -24,7 +24,7 @@ jsonnoinfo=$( "channel_tag": "${channeltag}", "type": "note", "title": "${alerttitle}", - "body": "Server Name\n${servername}\n\nInformation\n${alertmessage}\n\nGame\n${gamename}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}" + "body": "Server Name\n${servername}\n\nInformation\n${alertmessage}\n\nGame\n${gamename}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}\n\nServer Time\n$(date)" } EOF ) diff --git a/lgsm/modules/alert_pushover.sh b/lgsm/modules/alert_pushover.sh index 48009ab2c2..c436a4a91e 100644 --- a/lgsm/modules/alert_pushover.sh +++ b/lgsm/modules/alert_pushover.sh @@ -23,9 +23,9 @@ else fi if [ -z "${alerturl}" ]; then - pushoversend=$(curl --connect-timeout 10 -sS -F token="${pushovertoken}" -F user="${pushoveruserkey}" -F html="1" -F sound="${alertsound}" -F priority="${alertpriority}" -F title="${alerttitle}" -F message=" Server name
${servername}

Information
${alertmessage}

Game
${gamename}

Server IP
${alertip}:${port}

Hostname
${HOSTNAME}" "https://api.pushover.net/1/messages.json" | grep errors) + pushoversend=$(curl --connect-timeout 10 -sS -F token="${pushovertoken}" -F user="${pushoveruserkey}" -F html="1" -F sound="${alertsound}" -F priority="${alertpriority}" -F title="${alerttitle}" -F message=" Server name
${servername}

Information
${alertmessage}

Game
${gamename}

Server IP
${alertip}:${port}

Hostname
${HOSTNAME}

Server Time
$(date)" "https://api.pushover.net/1/messages.json" | grep errors) else - pushoversend=$(curl --connect-timeout 10 -sS -F token="${pushovertoken}" -F user="${pushoveruserkey}" -F html="1" -F sound="${alertsound}" -F priority="${alertpriority}" -F title="${alerttitle}" -F message=" Server name
${servername}

Information
${alertmessage}

Game
${gamename}

Server IP
${alertip}:${port}

Hostname
${HOSTNAME}

More info
${alerturl}" "https://api.pushover.net/1/messages.json" | grep errors) + pushoversend=$(curl --connect-timeout 10 -sS -F token="${pushovertoken}" -F user="${pushoveruserkey}" -F html="1" -F sound="${alertsound}" -F priority="${alertpriority}" -F title="${alerttitle}" -F message=" Server name
${servername}

Information
${alertmessage}

Game
${gamename}

Server IP
${alertip}:${port}

Hostname
${HOSTNAME}

More info
${alerturl}

Server Time
$(date)" "https://api.pushover.net/1/messages.json" | grep errors) fi if [ -n "${pushoversend}" ]; then diff --git a/lgsm/modules/alert_rocketchat.sh b/lgsm/modules/alert_rocketchat.sh index 65d6f1cf66..3291114942 100644 --- a/lgsm/modules/alert_rocketchat.sh +++ b/lgsm/modules/alert_rocketchat.sh @@ -11,24 +11,51 @@ jsoninfo=$( cat << EOF { "alias": "LinuxGSM", - "text": "*${alerttitle}*\nInformation\n${alertmessage}\nMore info: ${alerturl}", + "text": "*${alerttitle}*", "attachments": [ { + "title": "", + "color": "${alertcolourhex}", + "author_name": "LinuxGSM Alert", + "author_link": "https://linuxgsm.com", + "author_icon": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg", + "thumb_url": "${alerticon}", + "text": "", "fields": [ { - "short": true, + "short": false, + "title": "Server Name", + "value": "${servername}" + }, + { + "short": false, + "title": "Information", + "value": "${alertmessage}" + }, + { + "short": false, "title": "Game", "value": "${gamename}" }, { - "short": true, + "short": false, "title": "Server IP", "value": "${alertip}:${port}" }, { - "short": true, + "short": false, "title": "Hostname", "value": "${HOSTNAME}" + }, + { + "short": false, + "title": "More info", + "value": "${alerturl}" + }, + { + "short": false, + "title": "Server Time", + "value": "$(date)" } ] } @@ -76,6 +103,11 @@ jsonnoinfo=$( "short": false, "title": "Hostname", "value": "${HOSTNAME}" + }, + { + "short": false, + "title": "Server Time", + "value": "$(date)" } ] } diff --git a/lgsm/modules/alert_slack.sh b/lgsm/modules/alert_slack.sh index 8f8ccb61f7..f3e45dd83b 100644 --- a/lgsm/modules/alert_slack.sh +++ b/lgsm/modules/alert_slack.sh @@ -7,7 +7,7 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" -json=$( +jsonnoinfo=$( cat << EOF { "attachments": [ @@ -53,6 +53,10 @@ json=$( { "type": "mrkdwn", "text": "*Hostname*\n${HOSTNAME}" + }, + { + "type": "mrkdwn", + "text": "*Server Time*\n$(date)" } ], "accessory": { @@ -71,7 +75,7 @@ json=$( }, { "type": "plain_text", - "text": "Sent by LinuxGSM ${version}", + "text": "Sent by LinuxGSM ${version} - $(date)", "emoji": true } ] @@ -83,6 +87,99 @@ json=$( EOF ) +jsoninfo=$( + cat << EOF +{ + "attachments": [ + { + "color": "${alertcolourhex}", + "blocks": [ + { + "type": "header", + "text": { + "type": "plain_text", + "text": "${alerttitle}", + "emoji": true + } + }, + { + "type": "divider" + }, + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "*Server Name*\n${servername}" + } + }, + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "*Information*\n${alertmessage}" + } + }, + { + "type": "section", + "fields": [ + { + "type": "mrkdwn", + "text": "*Game*\n${gamename}" + }, + { + "type": "mrkdwn", + "text": "*Server IP*\n\`${alertip}:${port}\`" + }, + { + "type": "mrkdwn", + "text": "*Hostname*\n${HOSTNAME}" + }, + { + "type": "mrkdwn", + "text": "*Server Time*\n$(date)" + } + ], + "accessory": { + "type": "image", + "image_url": "${alerticon}", + "alt_text": "cute cat" + } + }, + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "*Server Time*\n${alertmessage}" + } + }, + { + "type": "context", + "elements": [ + { + "type": "image", + "image_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg", + "alt_text": "LinuxGSM icon" + }, + { + "type": "plain_text", + "text": "Sent by LinuxGSM ${version} - $(date)", + "emoji": true + } + ] + } + ] + } + ] +} +EOF +) + +if [ -z "${alerturl}" ]; then + json="${jsonnoinfo}" +else + json="${jsoninfo}" +fi + fn_print_dots "Sending Slack alert" slacksend=$(curl --connect-timeout 10 -sSL -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)" "${slackwebhook}") diff --git a/lgsm/modules/alert_telegram.sh b/lgsm/modules/alert_telegram.sh index 1a03aec132..3b3ec99120 100644 --- a/lgsm/modules/alert_telegram.sh +++ b/lgsm/modules/alert_telegram.sh @@ -12,7 +12,7 @@ jsoninfo=$( { "chat_id": "${telegramchatid}", "parse_mode": "HTML", - "text": "${alerttitle}\n\nServer name\n${servername}\n\nInformation\n${alertmessage}\n\nGame\n${gamename}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}\n\nMore info\n${alerturl}", + "text": "${alerttitle}\n\nServer name\n${servername}\n\nInformation\n${alertmessage}\n\nGame\n${gamename}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}\n\nMore info\n${alerturl}\n\nServer Time\n$(date)", "disable_web_page_preview": "yes" } EOF @@ -23,7 +23,7 @@ jsonnoinfo=$( { "chat_id": "${telegramchatid}", "parse_mode": "HTML", - "text": "${alerttitle}\n\nServer name\n${servername}\n\nInformation\n${alertmessage}\n\nGame\n${gamename}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}", + "text": "${alerttitle}\n\nServer name\n${servername}\n\nInformation\n${alertmessage}\n\nGame\n${gamename}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}\n\nServer Time\n$(date)", "disable_web_page_preview": "yes" } EOF diff --git a/lgsm/modules/info_messages.sh b/lgsm/modules/info_messages.sh index bcad2e759d..1213418782 100644 --- a/lgsm/modules/info_messages.sh +++ b/lgsm/modules/info_messages.sh @@ -65,6 +65,9 @@ fn_info_message_head() { echo -e "" echo -e "Hostname" echo -e "${HOSTNAME}" + echo -e "" + echo -e "Server Time" + echo -e "$(date)" } fn_info_message_distro() {