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
No known key found for this signature in database
GPG Key ID: 2076B128385E8C55
3 changed files with
81 additions and
51 deletions
lgsm/modules/alert_pushbullet.sh
lgsm/modules/alert_slack.sh
lgsm/modules/alert_telegram.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
@ -10,54 +10,68 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
json = $(
cat << EOF
{
"attachments" : [
{
"color" : "#36a64f" ,
"blocks" : [
{
"type" : "section" ,
"text" : {
"type" : "mrkdwn" ,
"text" : "*LinuxGSM Alert*"
}
} ,
{
"type" : "section" ,
"text" : {
"type" : "mrkdwn" ,
"text" : " * ${ alertemoji } ${ alerttitle } * \n ${ alertmessage } "
}
} ,
{
"type" : "divider"
} ,
{
"type" : "section" ,
"fields" : [
{
"type" : "mrkdwn" ,
"text" : " *Game:* \n ${ gamename } "
} ,
{
"type" : "mrkdwn" ,
"text" : " *Server IP:* \n ${ alertip } : ${ port } "
} ,
{
"type" : "mrkdwn" ,
"text" : " *Server Name:* \n ${ servername } "
}
]
} ,
{
"type" : "section" ,
"text" : {
"type" : "mrkdwn" ,
"text" : " Hostname: ${ HOSTNAME } / More info: ${ alerturl } "
}
}
]
}
]
"attachments" : [
{
"color" : " ${ alertcolourhex } " ,
"blocks" : [
{
"type" : "header" ,
"text" : {
"type" : "plain_text" ,
"text" : " ${ alerttitle } " ,
"emoji" : true
}
} ,
{
"type" : "divider"
} ,
{
"type" : "section" ,
"fields" : [
{
"type" : "mrkdwn" ,
"text" : " *Game*\n ${ gamename } "
} ,
{
"type" : "mrkdwn" ,
"text" : " *Server IP*\n\` ${ alertip } : ${ port } \` "
} ,
{
"type" : "mrkdwn" ,
"text" : " *Hostname*\n ${ HOSTNAME } "
}
] ,
"accessory" : {
"type" : "image" ,
"image_url" : " ${ alerticon } " ,
"alt_text" : "cute cat"
}
} ,
{
"type" : "section" ,
"text" : {
"type" : "mrkdwn" ,
"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
}
]
}
]
}
]
}
EOF
)
@ -7,17 +7,34 @@
moduleselfname = " $( basename " $( readlink -f " ${ BASH_SOURCE [0] } " ) " ) "
json = $(
jsoninfo = $(
cat << EOF
{
"chat_id" : " ${ telegramchatid } " ,
"parse_mode" : "HTML" ,
"text" : " <b> ${ alertemoji } ${ alert title } ${ 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" )