Skip to content

Commit

Permalink
feat: add server name and information fields to Discord alert
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dgibbs64 committed Oct 17, 2023
1 parent f63b586 commit 3921e59
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 33 deletions.
32 changes: 18 additions & 14 deletions lgsm/modules/alert_discord.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ jsoninfo=$(
"url": "${alerticon}"
},
"fields": [
{
"name": "Server Name",
"value": "${servername}"
},
{
"name": "Information",
"value": "${alertmessage}"
},
{
"name": "Game",
"value": "${gamename}",
Expand All @@ -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",
Expand Down Expand Up @@ -85,6 +85,14 @@ jsonnoinfo=$(
"url": "${alerticon}"
},
"fields": [
{
"name": "Server Name",
"value": "${servername}"
},
{
"name": "Information",
"value": "${alertmessage}"
},
{
"name": "Game",
"value": "${gamename}",
Expand All @@ -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",
Expand Down
21 changes: 18 additions & 3 deletions lgsm/modules/alert_gotify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lgsm/modules/alert_ifttt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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
)
Expand Down
4 changes: 2 additions & 2 deletions lgsm/modules/alert_pushbullet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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
)
Expand Down
41 changes: 38 additions & 3 deletions lgsm/modules/alert_rocketchat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -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
Expand Down
21 changes: 14 additions & 7 deletions lgsm/modules/alert_slack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -47,13 +61,6 @@ json=$(
"alt_text": "cute cat"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Information*\n${alertmessage}"
}
},
{
"type": "context",
"elements": [
Expand Down
4 changes: 2 additions & 2 deletions lgsm/modules/alert_telegram.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jsoninfo=$(
{
"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>",
"text": "<b>${alerttitle}</b>\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
Expand All @@ -23,7 +23,7 @@ jsonnoinfo=$(
{
"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>",
"text": "<b>${alerttitle}</b>\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}",
"disable_web_page_preview": "yes"
}
EOF
Expand Down

0 comments on commit 3921e59

Please sign in to comment.