Browse Source

refactor: improve alert message formatting and remove unnecessary code

The commit refactors the alert message formatting in the `alert_pushbullet.sh`, `alert_slack.sh`, and `alert_telegram.sh` files. It improves the structure and readability of the messages by using proper markdown syntax. Additionally, it removes unnecessary code from the files to simplify their implementation.
pull/4345/head
Daniel Gibbs 2 years ago
parent
commit
3912d02caa
No known key found for this signature in database GPG Key ID: 2076B128385E8C55
  1. 1
      lgsm/modules/alert_pushbullet.sh
  2. 46
      lgsm/modules/alert_slack.sh
  3. 21
      lgsm/modules/alert_telegram.sh

1
lgsm/modules/alert_pushbullet.sh

@ -36,7 +36,6 @@ else
fi
fn_print_dots "Sending Pushbullet alert"
pushbulletsend=$(curl --connect-timeout 10 -sSL -H "Access-Token: ${pushbullettoken}" -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)" "https://api.pushbullet.com/v2/pushes" | grep "error_code")
if [ -n "${pushbulletsend}" ]; then

46
lgsm/modules/alert_slack.sh

@ -12,20 +12,14 @@ json=$(
{
"attachments": [
{
"color": "#36a64f",
"color": "${alertcolourhex}",
"blocks": [
{
"type": "section",
"type": "header",
"text": {
"type": "mrkdwn",
"text": "*LinuxGSM Alert*"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*${alertemoji} ${alerttitle}* \n ${alertmessage}"
"type": "plain_text",
"text": "${alerttitle}",
"emoji": true
}
},
{
@ -36,24 +30,44 @@ json=$(
"fields": [
{
"type": "mrkdwn",
"text": "*Game:* \n ${gamename}"
"text": "*Game*\n${gamename}"
},
{
"type": "mrkdwn",
"text": "*Server IP:* \n ${alertip}:${port}"
"text": "*Server IP*\n\`${alertip}:${port}\`"
},
{
"type": "mrkdwn",
"text": "*Server Name:* \n ${servername}"
"text": "*Hostname*\n${HOSTNAME}"
}
],
"accessory": {
"type": "image",
"image_url": "${alerticon}",
"alt_text": "cute cat"
}
]
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Hostname: ${HOSTNAME} / More info: ${alerturl}"
"text": "*Information*\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}",
"emoji": true
}
]
}
]
}

21
lgsm/modules/alert_telegram.sh

@ -7,17 +7,34 @@
moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
json=$(
jsoninfo=$(
cat << EOF
{
"chat_id": "${telegramchatid}",
"parse_mode": "HTML",
"text": "<b>${alertemoji} ${alerttitle} ${alertemoji}</b>\n\n<b>Server name</b>\n${servername}\n\n<b>Message</b>\n${alertmessage}\n\n<b>Game</b>\n${gamename}\n\n<b>Server IP</b>\n<a href='https://www.gametracker.com/server_info/${alertip}:${port}'>${alertip}:${port}</a>\n\n<b>Hostname</b>\n${HOSTNAME}\n\n<b>More info</b>\n<a href='${alerturl}'>${alerturl}</a>",
"text": "<b>${alerttitle}</b>\n\n<b>Server name</b>\n${servername}\n\n<b>Information</b>\n${alertmessage}\n\n<b>Game</b>\n${gamename}\n\n<b>Server IP</b>\n${alertip}:${port}\n\n<b>Hostname</b>\n${HOSTNAME}\n\n<b>More info</b>\n<a href='${alerturl}'>${alerturl}</a>",
"disable_web_page_preview": "yes"
}
EOF
)
jsonnoinfo=$(
cat << EOF
{
"chat_id": "${telegramchatid}",
"parse_mode": "HTML",
"text": "<b>${alerttitle}</b>\n\n<b>Server name</b>\n${servername}\n\n<b>Information</b>\n${alertmessage}\n\n<b>Game</b>\n${gamename}\n\n<b>Server IP</b>\n${alertip}:${port}\n\n<b>Hostname</b>\n${HOSTNAME}\n\n<b>More info</b>\n<a href='${alerturl}'>${alerturl}</a>",
"disable_web_page_preview": "yes"
}
EOF
)
if [ -z "${alerturl}" ]; then
json="${jsonnoinfo}"
else
json="${jsoninfo}"
fi
fn_print_dots "Sending Telegram alert"
telegramsend=$(curl --connect-timeout 10 -sSL -H "Content-Type: application/json" -X POST -d "$(echo -n "${json}" | jq -c .)" ${curlcustomstring} "https://${telegramapi}/bot${telegramtoken}/sendMessage" | grep "error_code")

Loading…
Cancel
Save