Skip to content

Commit

Permalink
feat(alert): add new alert types
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
dgibbs64 committed Oct 7, 2023
1 parent e0b7739 commit 2baf370
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 18 deletions.
71 changes: 56 additions & 15 deletions lgsm/modules/alert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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="🚨"
Expand All @@ -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="🚨"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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
Expand All @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions lgsm/modules/command_monitor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2baf370

Please sign in to comment.