Skip to content

Commit

Permalink
Debug: log MQTT message (optional) (#33)
Browse files Browse the repository at this point in the history
* Log mqtt original message in debug mode
* Make mqtt message logging optional
  • Loading branch information
kpetremann authored Aug 26, 2022
1 parent 8bba488 commit 774617e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Parameters are passed using environment variables.

The list of parameters are:
* `LOG_LEVEL`: Logging level (default: INFO)
* `LOG_MQTT_MESSAGE`: Log MQTT original message, only if LOG_LEVEL is set to DEBUG (default: False)
* `MQTT_IGNORED_TOPICS`: Comma-separated lists of topics to ignore. Accepts wildcards. (default: None)
* `MQTT_ADDRESS`: IP or hostname of MQTT broker (default: 127.0.0.1)
* `MQTT_PORT`: TCP port of MQTT broker (default: 1883)
Expand Down
3 changes: 3 additions & 0 deletions mqtt_exporter/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ def expose_metrics(_, userdata, msg):
LOG.debug('Topic "%s" was ignored by entry "%s"', msg.topic, ignore)
return

if settings.LOG_MQTT_MESSAGE:
LOG.debug("New message from MQTT: %s - %s", msg.topic, msg.payload)

topic, payload = _parse_message(msg.topic, msg.payload)

if not topic or not payload:
Expand Down
1 change: 1 addition & 0 deletions mqtt_exporter/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

ZIGBEE2MQTT_AVAILABILITY = os.getenv("ZIGBEE2MQTT_AVAILABILITY", "False") == "True"
LOG_LEVEL = os.getenv("LOG_LEVEL", "INFO")
LOG_MQTT_MESSAGE = os.getenv("LOG_MQTT_MESSAGE", "False") == "True"
MQTT_ADDRESS = os.getenv("MQTT_ADDRESS", "127.0.0.1")
MQTT_PORT = int(os.getenv("MQTT_PORT", "1883"))
MQTT_KEEPALIVE = int(os.getenv("MQTT_KEEPALIVE", "60"))
Expand Down

0 comments on commit 774617e

Please sign in to comment.