Skip to content

Commit

Permalink
mosquitto: Set mosquitto.conf log_type based on logging level (#1708)
Browse files Browse the repository at this point in the history
* config option for mosquitto log_type

* change log_type to be based on LOGGING

* remove extra whitespace

* use bashio::log.<level> 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 <pascal.vizeli@syshack.ch>

* 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 <pascal.vizeli@syshack.ch>

Co-authored-by: Pascal Vizeli <pascal.vizeli@syshack.ch>
Co-authored-by: Pascal Vizeli <pvizeli@syshack.ch>
  • Loading branch information
3 people committed Feb 8, 2021
1 parent a114116 commit d291f56
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
13 changes: 8 additions & 5 deletions mosquitto/data/auth_srv.sh
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -81,6 +83,7 @@ function get_var() {


## MAIN ##
bashio::log.level "${LOGGING}"

read_request

Expand All @@ -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

Expand All @@ -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
4 changes: 4 additions & 0 deletions mosquitto/data/mosquitto.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ user root
##
# logging
log_dest stdout
log_type error
log_type warning
log_type notice
log_type information

##
# datastore
Expand Down
6 changes: 6 additions & 0 deletions mosquitto/data/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit d291f56

Please sign in to comment.