Skip to content

Commit

Permalink
refactor: update alert emojis and add server time
Browse files Browse the repository at this point in the history
- 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`).
  • Loading branch information
dgibbs64 committed Oct 19, 2023
1 parent 672c824 commit af08ac1
Show file tree
Hide file tree
Showing 10 changed files with 170 additions and 23 deletions.
8 changes: 4 additions & 4 deletions lgsm/modules/alert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
21 changes: 18 additions & 3 deletions lgsm/modules/alert_discord.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
}
}
]
Expand All @@ -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}",
Expand Down Expand Up @@ -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)"
}
}
]
Expand Down
4 changes: 2 additions & 2 deletions lgsm/modules/alert_gotify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
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": "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
)
Expand All @@ -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
)
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": "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
)
Expand All @@ -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
)
Expand Down
4 changes: 2 additions & 2 deletions lgsm/modules/alert_pushover.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=" <b>Server name</b><br>${servername}<br><br><b>Information</b><br>${alertmessage}<br><br><b>Game</b><br>${gamename}<br><br><b>Server IP</b><br>${alertip}:${port}<br><br><b>Hostname</b><br>${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=" <b>Server name</b><br>${servername}<br><br><b>Information</b><br>${alertmessage}<br><br><b>Game</b><br>${gamename}<br><br><b>Server IP</b><br>${alertip}:${port}<br><br><b>Hostname</b><br>${HOSTNAME}<br><br>Server Time<br>$(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=" <b>Server name</b><br>${servername}<br><br><b>Information</b><br>${alertmessage}<br><br><b>Game</b><br>${gamename}<br><br><b>Server IP</b><br>${alertip}:${port}<br><br><b>Hostname</b><br>${HOSTNAME}<br><br><b>More info</b><br><a href='${alerturl}'>${alerturl}</a>" "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=" <b>Server name</b><br>${servername}<br><br><b>Information</b><br>${alertmessage}<br><br><b>Game</b><br>${gamename}<br><br><b>Server IP</b><br>${alertip}:${port}<br><br><b>Hostname</b><br>${HOSTNAME}<br><br><b>More info</b><br><a href='${alerturl}'>${alerturl}</a><br><br>Server Time<br>$(date)" "https://api.pushover.net/1/messages.json" | grep errors)
fi

if [ -n "${pushoversend}" ]; then
Expand Down
40 changes: 36 additions & 4 deletions lgsm/modules/alert_rocketchat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
}
]
}
Expand Down Expand Up @@ -76,6 +103,11 @@ jsonnoinfo=$(
"short": false,
"title": "Hostname",
"value": "${HOSTNAME}"
},
{
"short": false,
"title": "Server Time",
"value": "$(date)"
}
]
}
Expand Down
101 changes: 99 additions & 2 deletions lgsm/modules/alert_slack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"

json=$(
jsonnoinfo=$(
cat << EOF
{
"attachments": [
Expand Down Expand Up @@ -53,6 +53,10 @@ json=$(
{
"type": "mrkdwn",
"text": "*Hostname*\n${HOSTNAME}"
},
{
"type": "mrkdwn",
"text": "*Server Time*\n$(date)"
}
],
"accessory": {
Expand All @@ -71,7 +75,7 @@ json=$(
},
{
"type": "plain_text",
"text": "Sent by LinuxGSM ${version}",
"text": "Sent by LinuxGSM ${version} - $(date)",
"emoji": true
}
]
Expand All @@ -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}")
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>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>\n\n<b>Server Time</b>\n$(date)",
"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}",
"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>Server Time</b>\n$(date)",
"disable_web_page_preview": "yes"
}
EOF
Expand Down
3 changes: 3 additions & 0 deletions lgsm/modules/info_messages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit af08ac1

Please sign in to comment.