Browse Source

feat: add alert types for server start, stop, restart, and wipe

- Added new alert types for server start, stop, restart, and wipe.
- Updated the `alert.sh` module to include functions for handling these new alert types.
- Modified the `command_start.sh`, `command_stop.sh`, and `command_wipe.sh` modules to trigger the corresponding alerts when appropriate.
- Updated the `alert_rocketchat.sh` module to display the relevant information for each alert type in Rocket.Chat notifications.
pull/4345/head
Daniel Gibbs 2 years ago
parent
commit
39c9b27022
No known key found for this signature in database GPG Key ID: 2076B128385E8C55
  1. 16
      lgsm/modules/alert.sh
  2. 25
      lgsm/modules/alert_rocketchat.sh
  3. 7
      lgsm/modules/command_start.sh
  4. 16
      lgsm/modules/command_stop.sh
  5. 4
      lgsm/modules/command_wipe.sh

16
lgsm/modules/alert.sh

@ -190,12 +190,24 @@ elif [ "${alert}" == "update" ]; then
fn_alert_update fn_alert_update
elif [ "${alert}" == "check-update" ]; then elif [ "${alert}" == "check-update" ]; then
fn_alert_check_update fn_alert_check_update
elif [ "${alert}" == "update-restart" ]; then
fn_alert_update_restart
elif [ "${alert}" == "config" ]; then elif [ "${alert}" == "config" ]; then
fn_alert_config fn_alert_config
elif [ "${alert}" == "wipe" ]; then elif [ "${alert}" == "wipe" ]; then
fn_alert_wipe fn_alert_wipe
elif [ "${alert}" == "info" ]; then
fn_alert_info
elif [ "${alert}" == "started" ]; then
fn_alert_started
elif [ "${alert}" == "stopped" ]; then
fn_alert_stopped
elif [ "${alert}" == "restarted" ]; then
fn_alert_restarted
elif [ "${alert}" == "update-linuxgsm" ]; then
fn_alert_update_linuxgsm
else
fn_print_fail_nl "Missing alert type"
fn_script_log_fatal "Missing alert type"
core_exit.sh
fi fi
alerttitle="${alertemoji} ${alertaction} - ${servername} ${alertemoji}" alerttitle="${alertemoji} ${alertaction} - ${servername} ${alertemoji}"

25
lgsm/modules/alert_rocketchat.sh

@ -41,22 +41,39 @@ jsonnoinfo=$(
cat << EOF cat << EOF
{ {
"alias": "LinuxGSM", "alias": "LinuxGSM",
"text": "*${alerttitle}*\nInformation\n${alertmessage}", "text": "*${alerttitle}*",
"attachments": [ "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": [ "fields": [
{ {
"short": true, "short": false,
"title": "Server Name",
"value": "${servername}"
},
{
"short": false,
"title": "Information",
"value": "${alertmessage}"
},
{
"short": false,
"title": "Game", "title": "Game",
"value": "${gamename}" "value": "${gamename}"
}, },
{ {
"short": true, "short": false,
"title": "Server IP", "title": "Server IP",
"value": "${alertip}:${port}" "value": "${alertip}:${port}"
}, },
{ {
"short": true, "short": false,
"title": "Hostname", "title": "Hostname",
"value": "${HOSTNAME}" "value": "${HOSTNAME}"
} }

7
lgsm/modules/command_start.sh

@ -176,6 +176,13 @@ fn_start_tmux() {
fn_print_ok "${servername}" fn_print_ok "${servername}"
fn_script_log_pass "Started ${servername}" fn_script_log_pass "Started ${servername}"
if [ "${firstcommandname}" == "START" ]; then
alert="started"
alert.sh
elif [ "${firstcommandname}" == "RESTART" ]; then
alert="restarted"
alert.sh
fi
fi fi
rm -f "${lgsmlogdir:?}/.${selfname}-tmux-error.tmp" 2> /dev/null rm -f "${lgsmlogdir:?}/.${selfname}-tmux-error.tmp" 2> /dev/null
echo -en "\n" echo -en "\n"

16
lgsm/modules/command_stop.sh

@ -51,6 +51,9 @@ fn_stop_graceful_cmd() {
fn_print_ok "Graceful: sending \"${1}\": ${seconds}: " fn_print_ok "Graceful: sending \"${1}\": ${seconds}: "
fn_print_ok_eol_nl fn_print_ok_eol_nl
fn_script_log_pass "Graceful: sending \"${1}\": OK: ${seconds} seconds" fn_script_log_pass "Graceful: sending \"${1}\": OK: ${seconds} seconds"
if [ "${firstcommandname}" == "STOP" ]; then
alert="stopped"
fi
break break
fi fi
fn_sleep_time_1 fn_sleep_time_1
@ -80,6 +83,9 @@ fn_stop_graceful_goldsrc() {
fn_print_ok "Graceful: sending \"quit\": ${seconds}: " fn_print_ok "Graceful: sending \"quit\": ${seconds}: "
fn_print_ok_eol_nl fn_print_ok_eol_nl
fn_script_log_pass "Graceful: sending \"quit\": OK: ${seconds} seconds" fn_script_log_pass "Graceful: sending \"quit\": OK: ${seconds} seconds"
if [ "${firstcommandname}" == "STOP" ]; then
alert="stopped"
fi
} }
# telnet command for sdtd graceful shutdown. # telnet command for sdtd graceful shutdown.
@ -152,6 +158,10 @@ fn_stop_graceful_sdtd() {
fn_print_ok "Graceful: telnet: ${telnetip}:${telnetport} : " fn_print_ok "Graceful: telnet: ${telnetip}:${telnetport} : "
fn_print_ok_eol_nl fn_print_ok_eol_nl
fn_script_log_pass "Graceful: telnet: ${telnetip}:${telnetport} : ${seconds} seconds" fn_script_log_pass "Graceful: telnet: ${telnetip}:${telnetport} : ${seconds} seconds"
if [ "${firstcommandname}" == "STOP" ]; then
alert="stopped"
alert.sh
fi
break break
fi fi
fn_sleep_time_1 fn_sleep_time_1
@ -195,6 +205,9 @@ fn_stop_graceful_avorion() {
fn_print_ok "Graceful: /save /stop: ${seconds}: " fn_print_ok "Graceful: /save /stop: ${seconds}: "
fn_print_ok_eol_nl fn_print_ok_eol_nl
fn_script_log_pass "Graceful: /save /stop: OK: ${seconds} seconds" fn_script_log_pass "Graceful: /save /stop: OK: ${seconds} seconds"
if [ "${firstcommandname}" == "STOP" ]; then
alert="stopped"
fi
break break
fi fi
fn_sleep_time_1 fn_sleep_time_1
@ -246,6 +259,9 @@ fn_stop_tmux() {
if [ "${status}" == "0" ]; then if [ "${status}" == "0" ]; then
fn_print_ok_nl "${servername}" fn_print_ok_nl "${servername}"
fn_script_log_pass "Stopped ${servername}" fn_script_log_pass "Stopped ${servername}"
if [ "${firstcommandname}" == "STOP" ]; then
alert="stopped"
fi
else else
fn_print_fail_nl "Unable to stop ${servername}" fn_print_fail_nl "Unable to stop ${servername}"
fn_script_log_fail "Unable to stop ${servername}" fn_script_log_fail "Unable to stop ${servername}"

4
lgsm/modules/command_wipe.sh

@ -167,6 +167,8 @@ if [ -n "$(find "${serveridentitydir}" -type f -name "*.map")" ] || [ -n "$(find
fn_wipe_random_seed fn_wipe_random_seed
fn_print_complete_nl "${wipetype}" fn_print_complete_nl "${wipetype}"
fn_script_log_pass "${wipetype}" fn_script_log_pass "${wipetype}"
alert="wipe"
alert.sh
exitbypass=1 exitbypass=1
command_start.sh command_start.sh
fn_firstcommand_reset fn_firstcommand_reset
@ -175,6 +177,8 @@ if [ -n "$(find "${serveridentitydir}" -type f -name "*.map")" ] || [ -n "$(find
fn_wipe_random_seed fn_wipe_random_seed
fn_print_complete_nl "${wipetype}" fn_print_complete_nl "${wipetype}"
fn_script_log_pass "${wipetype}" fn_script_log_pass "${wipetype}"
alert="wipe"
alert.sh
fi fi
else else
fn_print_ok_nl "Wipe not required" fn_print_ok_nl "Wipe not required"

Loading…
Cancel
Save