Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mosquitto: Set mosquitto.conf log_type based on logging level #1708

Merged
merged 19 commits into from
Feb 8, 2021
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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