From 3921e591200070455018b0716ccaabbf33195b6e Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Tue, 17 Oct 2023 23:33:58 +0100 Subject: [PATCH] feat: add server name and information fields to Discord alert The code changes in the `alert_discord.sh` file include adding new fields for server name and information to the JSON payload sent in a Discord alert. This allows for more detailed information about the server to be included in the alert message. refactor: improve conditional logic for Gotify alerts In the `alert_gotify.sh` file, the code changes involve improving the conditional logic for determining which JSON payload to use when sending a Gotify alert. The updated logic checks if an alert URL is provided and selects the appropriate JSON payload accordingly. chore: update field names in IFTTT alerts The changes made in `alert_ifttt.sh` involve updating field names in the JSON payloads used for IFTTT alerts. The field names have been modified to match a consistent format across all fields. fix: correct body formatting in Pushbullet alerts The code changes made in `alert_pushbullet.sh` address an issue with incorrect body formatting in Pushbullet alerts. The body of the alert now includes separate lines for each piece of information, such as server name, information, game, server IP, hostname, and more info. refactor: improve attachment structure in RocketChat alerts In `alert_rocketchat.sh`, the code changes involve improving the attachment structure of RocketChat alerts. The updated structure includes separate sections for server name, information, game, server IP, hostname, and more info. feat: add additional sections to Slack alerts The changes made in `alert_slack.sh` include adding additional sections to Slack alerts. These sections provide separate blocks of text for server name and information within each message. feat: add HTML formatting to Telegram alerts In `alert_telegram.sh`, HTML formatting has been added to Telegram alerts. This allows for bold text styling and clickable links within each message sent via Telegram. --- lgsm/modules/alert_discord.sh | 32 ++++++++++++++----------- lgsm/modules/alert_gotify.sh | 21 +++++++++++++--- lgsm/modules/alert_ifttt.sh | 4 ++-- lgsm/modules/alert_pushbullet.sh | 4 ++-- lgsm/modules/alert_rocketchat.sh | 41 +++++++++++++++++++++++++++++--- lgsm/modules/alert_slack.sh | 21 ++++++++++------ lgsm/modules/alert_telegram.sh | 4 ++-- 7 files changed, 94 insertions(+), 33 deletions(-) diff --git a/lgsm/modules/alert_discord.sh b/lgsm/modules/alert_discord.sh index 574f6248b..8bfea9fa2 100644 --- a/lgsm/modules/alert_discord.sh +++ b/lgsm/modules/alert_discord.sh @@ -29,6 +29,14 @@ jsoninfo=$( "url": "${alerticon}" }, "fields": [ + { + "name": "Server Name", + "value": "${servername}" + }, + { + "name": "Information", + "value": "${alertmessage}" + }, { "name": "Game", "value": "${gamename}", @@ -43,15 +51,7 @@ jsoninfo=$( "name": "Hostname", "value": "${HOSTNAME}", "inline": true - }, - { - "name": "Information", - "value": "${alertmessage}" - }, - { - "name": "More Information", - "value": "${alerturl}" - } + } ], "footer": { "icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg", @@ -85,6 +85,14 @@ jsonnoinfo=$( "url": "${alerticon}" }, "fields": [ + { + "name": "Server Name", + "value": "${servername}" + }, + { + "name": "Information", + "value": "${alertmessage}" + }, { "name": "Game", "value": "${gamename}", @@ -99,11 +107,7 @@ jsonnoinfo=$( "name": "Hostname", "value": "${HOSTNAME}", "inline": true - }, - { - "name": "Information", - "value": "${alertmessage}" - } + } ], "footer": { "icon_url": "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/alert_discord_logo.jpg", diff --git a/lgsm/modules/alert_gotify.sh b/lgsm/modules/alert_gotify.sh index 7cda98489..232c10893 100644 --- a/lgsm/modules/alert_gotify.sh +++ b/lgsm/modules/alert_gotify.sh @@ -7,18 +7,33 @@ module_selfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" -json=$( +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}", "priority": 5 } EOF ) -fn_print_dots "Sending Gotify alert" +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}", + "priority": 5 +} +EOF +) + +if [ -z "${alerturl}" ]; then + json="${jsonnoinfo}" +else + json="${jsoninfo}" +fi +fn_print_dots "Sending Gotify alert" gotifysend=$(curl --connect-timeout 10 -sSL "${gotifywebhook}/message"?token="${gotifytoken}" -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)") if [ -n "${gotifysend}" ]; then diff --git a/lgsm/modules/alert_ifttt.sh b/lgsm/modules/alert_ifttt.sh index 12a9a9fec..d6affa622 100644 --- a/lgsm/modules/alert_ifttt.sh +++ b/lgsm/modules/alert_ifttt.sh @@ -12,7 +12,7 @@ jsoninfo=$( { "value1": "${selfname}", "value2": "${alerttitle}", - "value3": "Information \n${alertmessage}\n\nGame: \n${gamename}\n\nServer name \n${servername}\n\nHostname \n${HOSTNAME}\n\nServer IP \n${alertip}:${port}\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}" } EOF ) @@ -22,7 +22,7 @@ jsonnoinfo=$( { "value1": "${selfname}", "value2": "${alerttitle}", - "value3": "Information \n${alertmessage}\n\nGame: \n${gamename}\n\nServer name \n${servername}\n\nHostname \n${HOSTNAME}\n\nServer IP \n${alertip}:${port}" + "value3": "Server Name\n${servername}\n\nInformation\n${alertmessage}\n\nGame\n${gamename}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}" } EOF ) diff --git a/lgsm/modules/alert_pushbullet.sh b/lgsm/modules/alert_pushbullet.sh index a8f8e56b5..47419e663 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": "Information\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}" } EOF ) @@ -24,7 +24,7 @@ jsonnoinfo=$( "channel_tag": "${channeltag}", "type": "note", "title": "${alerttitle}", - "body": "Information\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}" } EOF ) diff --git a/lgsm/modules/alert_rocketchat.sh b/lgsm/modules/alert_rocketchat.sh index fa9b6fdfe..136039e05 100644 --- a/lgsm/modules/alert_rocketchat.sh +++ b/lgsm/modules/alert_rocketchat.sh @@ -7,11 +7,11 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" -json=$( +jsoninfo=$( cat << EOF { "alias": "LinuxGSM", - "text": "*${alerttitle}* \n ${alertmessage} \n More info: ${alerturl}", + "text": "*${alerttitle}*\n${alertmessage}\nMore info: ${alerturl}", "attachments": [ { "fields": [ @@ -37,8 +37,43 @@ json=$( EOF ) -fn_print_dots "Sending Rocketchat alert" +jsonnoinfo=$( + cat << EOF +{ + "alias": "LinuxGSM", + "text": "*${alerttitle}*\n${alertmessage}", + "attachments": [ + { + "fields": [ + { + "short": true, + "title": "Game", + "value": "${gamename}" + }, + { + "short": true, + "title": "Server IP", + "value": "${alertip}:${port}" + }, + { + "short": true, + "title": "Hostname", + "value": "${HOSTNAME}" + } + ] + } + ] +} +EOF +) +if [ -z "${alerturl}" ]; then + json="${jsonnoinfo}" +else + json="${jsoninfo}" +fi + +fn_print_dots "Sending Rocketchat alert" rocketchatsend=$(curl --connect-timeout 10 -sSL -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)" "${rocketchatwebhook}") if [ -n "${rocketchatsend}" ]; then diff --git a/lgsm/modules/alert_slack.sh b/lgsm/modules/alert_slack.sh index d192e4cd4..8f8ccb61f 100644 --- a/lgsm/modules/alert_slack.sh +++ b/lgsm/modules/alert_slack.sh @@ -25,6 +25,20 @@ json=$( { "type": "divider" }, + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "*Server Name*\n${servername}" + } + }, + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "*Information*\n${alertmessage}" + } + }, { "type": "section", "fields": [ @@ -47,13 +61,6 @@ json=$( "alt_text": "cute cat" } }, - { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "*Information*\n${alertmessage}" - } - }, { "type": "context", "elements": [ diff --git a/lgsm/modules/alert_telegram.sh b/lgsm/modules/alert_telegram.sh index 085c1d8f4..fb89263a6 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\nInformation\n${alertmessage}\n\nGame\n${gamename}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}\n\nMore info\n${alerturl}", "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}\n\nMore info\n${alerturl}", + "text": "${alerttitle}\n\nInformation\n${alertmessage}\n\nGame\n${gamename}\n\nServer IP\n${alertip}:${port}\n\nHostname\n${HOSTNAME}", "disable_web_page_preview": "yes" } EOF