From d291f564ced1c19d0cfaa349b9f3b4b91e615151 Mon Sep 17 00:00:00 2001 From: b3nj1 Date: Mon, 8 Feb 2021 07:00:32 -0800 Subject: [PATCH] mosquitto: Set mosquitto.conf log_type based on logging level (#1708) * config option for mosquitto log_type * change log_type to be based on LOGGING * remove extra whitespace * use bashio::log. for logging * set run.sh and auth_srv.sh bashio logging level to match supervisor level * lint fixes * Update mosquitto/data/auth_srv.sh Co-authored-by: Pascal Vizeli * HomeMatic: s6-overlay & tempio (#1713) * HomeMatic: s6-overlay & tempio * Use tempio * fix line end * Fix dev version * Fix bugs * S6-overlay cleanup for HM & deCONZ (#1717) * HomeMatic: take container down on ReGaHss (#1719) * HomeMatic: Fix ingress (#1720) * HomeMatic: Fix ingress * Fix count * Fix template HM * set run.sh and auth_srv.sh bashio logging level to match supervisor level * lint fixes * Update mosquitto/data/auth_srv.sh Co-authored-by: Pascal Vizeli Co-authored-by: Pascal Vizeli Co-authored-by: Pascal Vizeli --- mosquitto/data/auth_srv.sh | 13 ++++++++----- mosquitto/data/mosquitto.conf | 4 ++++ mosquitto/data/run.sh | 6 ++++++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/mosquitto/data/auth_srv.sh b/mosquitto/data/auth_srv.sh index dab29d6..95c92e5 100755 --- a/mosquitto/data/auth_srv.sh +++ b/mosquitto/data/auth_srv.sh @@ -1,11 +1,13 @@ -#!/bin/bash +#!/usr/bin/env bashio # shellcheck disable=SC2244,SC1117 +set +u set -e CONFIG_PATH=/data/options.json SYSTEM_USER=/data/system_user.json REQUEST=() REQUEST_BODY="" +LOGGING=$(bashio::info.logging) declare -A LOCAL_DB @@ -81,6 +83,7 @@ function get_var() { ## MAIN ## +bashio::log.level "${LOGGING}" read_request @@ -97,10 +100,10 @@ password="$(get_var password)" # If local user if [ "${LOCAL_DB["${username}"]}" == "${password}" ]; then - echo "[INFO] found ${username} on local database" >&2 + bashio::log.info "[INFO] found ${username} on local database" http_ok elif [ ${LOCAL_DB["${username}"]+_} ]; then - echo "[WARN] Not found ${username} on local database" >&2 + bashio::log.warning "[WARN] Not found ${username} on local database" http_error fi @@ -109,9 +112,9 @@ auth_header="X-Hassio-Key: ${HASSIO_TOKEN}" content_type="Content-Type: application/x-www-form-urlencoded" if curl -s -f -X POST -d "${REQUEST_BODY}" -H "${content_type}" -H "${auth_header}" http://hassio/auth > /dev/null; then - echo "[INFO] found ${username} on Home Assistant" >&2 + bashio::log.info "[INFO] found ${username} on Home Assistant" http_ok fi -echo "[ERROR] Auth error with ${username}" >&2 +bashio::log.error "[ERROR] Auth error with ${username}" http_error diff --git a/mosquitto/data/mosquitto.conf b/mosquitto/data/mosquitto.conf index 7df9ae9..55ac451 100644 --- a/mosquitto/data/mosquitto.conf +++ b/mosquitto/data/mosquitto.conf @@ -6,6 +6,10 @@ user root ## # logging log_dest stdout +log_type error +log_type warning +log_type notice +log_type information ## # datastore diff --git a/mosquitto/data/run.sh b/mosquitto/data/run.sh index 65e6913..fa92faa 100755 --- a/mosquitto/data/run.sh +++ b/mosquitto/data/run.sh @@ -84,6 +84,7 @@ function constrain_discovery() { } ## Main ## +bashio::log.level "${LOGGING}" bashio::log.info "Setup mosquitto configuration" sed -i "s/%%ANONYMOUS%%/$ANONYMOUS/g" /etc/mosquitto.conf @@ -92,6 +93,11 @@ if [ "${LOGGING}" == "debug" ]; then sed -i "s/%%AUTH_QUIET_LOGS%%/false/g" /etc/mosquitto.conf else sed -i "s/%%AUTH_QUIET_LOGS%%/true/g" /etc/mosquitto.conf + if [ "${LOGGING}" == "critical" ] || [ "${LOGGING}" == "fatal" ] || [ "${LOGGING}" == "error" ]; then + sed -i -e "s/^log_type warning//" -e "s/^log_type notice//" -e "s/^log_type information//" /etc/mosquitto.conf + elif [ "${LOGGING}" == "warning" ] || [ "${LOGGING}" == "warn" ]; then + sed -i -e "s/^log_type notice//" -e "s/^log_type information//" /etc/mosquitto.conf + fi fi # Enable SSL if exists configs