diff --git a/lgsm/functions/alert.sh b/lgsm/functions/alert.sh index 5fd999728..438f1be8f 100755 --- a/lgsm/functions/alert.sh +++ b/lgsm/functions/alert.sh @@ -221,3 +221,22 @@ elif [ -z "${slacktoken}" ]&&[ "${commandname}" == "TEST-ALERT" ]; then echo -e "* https://docs.linuxgsm.com/alerts/slack" fn_script_error "Slack token not set" fi + +if [ "${matrixalert}" == "on" ]&&[ -n "${matrixtoken}" ]; then + alert_matrix.sh +elif [ "${matrixalert}" != "on" ]&&[ "${commandname}" == "TEST-ALERT" ]; then + fn_print_warn_nl "Matrix alerts not enabled" + fn_script_log_warn "Matrix alerts not enabled" +elif [ -z "${matrixhomeserver}" ]&&[ "${commandname}" == "TEST-ALERT" ]; then + fn_print_error_nl "Matrix homeserver not set." + echo -e "* https://docs.linuxgsm.com/alerts/matrix" + fn_script_error "Matrix homeserver not set." +elif [ -z "${matrixtoken}" ]&&[ "${commandname}" == "TEST-ALERT" ]; then + fn_print_error_nl "Matrix token not set." + echo -e "* https://docs.linuxgsm.com/alerts/matrix" + fn_script_error "Matrix token not set." +elif [ -z "${matrixroom}" ]&&[ "${commandname}" == "TEST-ALERT" ]; then + fn_print_error_nl "Matrix room not set." + echo -e "* https://docs.linuxgsm.com/alerts/matrix" + fn_script_error "Matrix room not set." +fi diff --git a/lgsm/functions/alert_matrix.sh b/lgsm/functions/alert_matrix.sh index 0fe0942a7..1d32a1a4b 100644 --- a/lgsm/functions/alert_matrix.sh +++ b/lgsm/functions/alert_matrix.sh @@ -17,7 +17,7 @@ EOF ) fn_print_dots "Sending Matrix alert" -matrixsend=$(curl --connect-timeout 10 -sSL -H "Content-Type: application/json" -X POST -d """${json}""" "https://${matrixhomeserver}/_matrix/client/r0/rooms/${matrixroom}/send/m.room.message?access_token=${matrixaccesstoken} | grep "error") +matrixsend=$(curl --connect-timeout 10 -sSL -H "Content-Type: application/json" -X POST -d """${json}""" "https://${matrixhomeserver}/_matrix/client/r0/rooms/${matrixroom}/send/m.room.message?access_token=${matrixtoken} | grep "error") if [ -n "${matrixsend}" ]; then