diff --git a/lgsm/config-default/config-lgsm/rustserver/_default.cfg b/lgsm/config-default/config-lgsm/rustserver/_default.cfg index 7167acd03e..255f99db9c 100644 --- a/lgsm/config-default/config-lgsm/rustserver/_default.cfg +++ b/lgsm/config-default/config-lgsm/rustserver/_default.cfg @@ -97,6 +97,13 @@ telegramtoken="accesstoken" telegramchatid="" curlcustomstring="" +mqttalert="off" +mqtthost="mqtt.example.com" +mqttport="1883" +mqttuser="someuser" +mqttpassword="somepassword" +mqtttopic="/lgsm/rustserver" + ## Updating | https://docs.linuxgsm.com/commands/update updateonstart="off" diff --git a/lgsm/functions/alert.sh b/lgsm/functions/alert.sh index a5b753f0d8..09d9780254 100644 --- a/lgsm/functions/alert.sh +++ b/lgsm/functions/alert.sh @@ -190,3 +190,25 @@ elif [ -z "${telegramchatid}" ]&&[ "${function_selfname}" == "command_test_alert echo " * https://docs.linuxgsm.com/alerts/telegram" fn_script_error "Telegram chat id not set." fi + +if [ "${mqttalert}" == "on" ]&&[ -n "${mqtthost}" ]; then + alert_mqtt.sh +elif [ "${mqttalert}" != "on" ]&&[ -n "${function_selfname}" == "command_test_alert.sh"]; then + fn_print_warn_nl "MQTT Messages not enabled" + fn_script_log_warn "MQTT Messages not enabled" +elif [ -z "${mqtthost}" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then + fn_print_error_nl "MQTT host not set" + fn_script_error "MQTT host not set" +elif [ -z "${mqttport}" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then + fn_print_error_nl "MQTT port not set" + fn_script_error "MQTT port not set" +elif [ -z "${mqttuser}" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then + fn_print_error_nl "MQTT User not set" + fn_script_error "MQTT User not set" +elif [ -z "${mqttpassword}" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then + fn_print_error_nl "MQTT Password not set" + fn_script_error "MQTT Password not set" +elif [ -z "${mqtttopic}" ]&&[ "${function_selfname}" == "command_test_alert.sh" ]; then + fn_print_error_nl "MQTT Topic not set" + fn_script_error "MQTT Topic not set" +fi diff --git a/lgsm/functions/alert_mqtt.sh b/lgsm/functions/alert_mqtt.sh new file mode 100644 index 0000000000..f1d9d1873f --- /dev/null +++ b/lgsm/functions/alert_mqtt.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# LinuxGSM alert_ifttt.sh function +# Author: Daniel Gibbs +# Website: https://linuxgsm.com +# Description: Sends IFTTT alert. + +local commandname="ALERT" +local commandaction="Alert" +local function_selfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")" + +json=$(cat </dev/null) if [ "$(basename "${curlpath}")" != "curl" ]; then echo "[ FAIL ] Curl is not installed" exit 1 -fi \ No newline at end of file +fi + +#Defines mqttpubpath path. +mqttpubpath=$(command -v mosquitto_pub2>/dev/null) +if [ "$(basename "${mqttpubpath}")" != "mosquitto_pub" ]; then + echo "[ INFO ] mosquitto_pub is not installed. MQTT alerts not available" +fi diff --git a/lgsm/functions/core_functions.sh b/lgsm/functions/core_functions.sh index 43ce5984e8..d2ab0ab05e 100644 --- a/lgsm/functions/core_functions.sh +++ b/lgsm/functions/core_functions.sh @@ -490,6 +490,11 @@ functionfile="${FUNCNAME}" fn_fetch_function } +alert_mqtt.sh(){ +functionfile="${FUNCNAME}" +fn_fetch_function +} + # Logs logs.sh(){