From 2baf370f907250f3828194893594e80fe2441b63 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Sun, 8 Oct 2023 00:03:19 +0100 Subject: [PATCH] feat(alert): add new alert types - Added new alert types for different scenarios such as stopped, started, restarted, monitor session failure, monitor query failure, wipe, and info. - Updated the `alert.sh` script to include functions for each new alert type. - Modified the `command_monitor.sh` script to use the appropriate alert type based on the monitoring results. --- lgsm/modules/alert.sh | 71 ++++++++++++++++++++++++++------- lgsm/modules/command_monitor.sh | 6 +-- 2 files changed, 59 insertions(+), 18 deletions(-) diff --git a/lgsm/modules/alert.sh b/lgsm/modules/alert.sh index b8b668ef42..a9994dfccf 100644 --- a/lgsm/modules/alert.sh +++ b/lgsm/modules/alert.sh @@ -36,7 +36,36 @@ fn_alert_test() { alertbody="Testing LinuxGSM Alert. No action to be taken." } -fn_alert_restart() { +# Running command manually +fn_alert_stopped() { + fn_script_log_info "Sending alert: Stopped" + alertsubject="Alert - ${selfname} - Stopped" + alertemoji="๐ŸŸ " + alertsound="1" + alerturl="not enabled" + alertbody="${selfname} has stopped" +} + +fn_alert_started() { + fn_script_log_info "Sending alert: Stopped" + alertsubject="Alert - ${selfname} - Stopped" + alertemoji="๐ŸŸ " + alertsound="1" + alerturl="not enabled" + alertbody="${selfname} has started" +} + +fn_alert_restarted() { + fn_script_log_info "Sending alert: Restarted" + alertsubject="Alert - ${selfname} - Restarted" + alertemoji="๐ŸŸ " + alertsound="1" + alerturl="not enabled" + alertbody="${selfname} has restarted" +} + +# Failed monitor checks +fn_alert_monitor_session() { fn_script_log_info "Sending alert: Restarted: ${executable} not running" alertsubject="Alert - ${selfname} - Restarted" alertemoji="๐Ÿšจ" @@ -45,7 +74,7 @@ fn_alert_restart() { alertbody="${selfname} ${executable} not running" } -fn_alert_restart_query() { +fn_alert_monitor_query() { fn_script_log_info "Sending alert: Restarted: ${selfname}" alertsubject="Alert - ${selfname} - Restarted" alertemoji="๐Ÿšจ" @@ -54,6 +83,7 @@ fn_alert_restart_query() { alertbody="Unable to query: ${selfname}" } +# Update alerts fn_alert_update() { fn_script_log_info "Sending alert: Updated" alertsubject="Alert - ${selfname} - Updated" @@ -72,15 +102,6 @@ fn_alert_check_update() { alertbody="${gamename} update available: ${remotebuildversion}" } -fn_alert_update_restart() { - fn_script_log_info "Sending alert: Restarted" - alertsubject="Alert - ${selfname} - Restarted" - alertemoji="๐ŸŽฎ" - alertsound="1" - alerturl="not enabled" - alertbody="${gamename} received update: ${remotebuildversion} and required restarting" -} - fn_alert_permissions() { fn_script_log_info "Sending alert: Permissions error" alertsubject="Alert - ${selfname}: Permissions error" @@ -99,12 +120,30 @@ fn_alert_config() { alertbody="${selfname} has received a new _default.cfg. Check file for changes." } +fn_alert_wipe() { + fn_script_log_info "Sending alert: Wipe" + alertsubject="Alert - ${selfname} - Wipe" + alertemoji="๐Ÿงน" + alertsound="1" + alerturl="not enabled" + alertbody="${selfname} has been wiped" +} + +fn_alert_info() { + fn_script_log_info "Sending alert: Info" + alertsubject="Alert - ${selfname} - Info" + alertemoji="๐Ÿ“„" + alertsound="1" + alerturl="not enabled" + alertbody="${selfname} info" +} + if [ "${alert}" == "permissions" ]; then fn_alert_permissions -elif [ "${alert}" == "restart" ]; then - fn_alert_restart -elif [ "${alert}" == "restartquery" ]; then - fn_alert_restart_query +elif [ "${alert}" == "monitor-session" ]; then + fn_alert_monitor_session +elif [ "${alert}" == "monitor-query" ]; then + fn_alert_monitor_query elif [ "${alert}" == "test" ]; then fn_alert_test elif [ "${alert}" == "update" ]; then @@ -115,6 +154,8 @@ elif [ "${alert}" == "update-restart" ]; then fn_alert_update_restart elif [ "${alert}" == "config" ]; then fn_alert_config +elif [ "${alert}" == "wipe" ]; then + fn_alert_wipe fi # Generate alert log. diff --git a/lgsm/modules/command_monitor.sh b/lgsm/modules/command_monitor.sh index 079ad334d3..95442e0e33 100644 --- a/lgsm/modules/command_monitor.sh +++ b/lgsm/modules/command_monitor.sh @@ -154,7 +154,7 @@ fn_monitor_check_update_source() { fn_print_ok "Checking update: " fn_print_ok_eol_nl fn_script_log_info "Checking update: Monitor is restarting ${selfname} to apply update" - alert="update-restart" + alert="update" alert.sh command_restart.sh core_exit.sh @@ -207,7 +207,7 @@ fn_monitor_check_session() { fn_print_error "Checking session: " fn_print_fail_eol_nl fn_script_log_fail "Checking session: FAIL" - alert="restart" + alert="monitor-session" alert.sh fn_script_log_info "Checking session: Monitor is restarting ${selfname}" command_restart.sh @@ -319,7 +319,7 @@ fn_monitor_query() { fn_print_fail_eol_nl fn_script_log_warn "Querying port: ${querymethod}: ${queryip}:${queryport} : ${queryattempt} : FAIL" # Send alert if enabled. - alert="restartquery" + alert="monitor-query" alert.sh command_restart.sh fn_firstcommand_reset