瀏覽代碼

Merge pull request #11 from adnidor/master

enable setting the carbon key to a value combining a constant string and the MQTT topic
JP Mens 7 年之前
父節點
當前提交
3533ea678f
共有 2 個文件被更改,包括 7 次插入0 次删除
  1. 5 0
      map
  2. 2 0
      mqtt2graphite.py

+ 5 - 0
map

@@ -15,6 +15,8 @@
 #	Use periods as separators, just like Carbon expects them. If 
 #	this value is not specified, the MQTT topic name will be used,
 #	with slashes (/) converted to dots (.)
+#	If the # character is present, it will be replaced by the
+#	MQTT topic name with the points converted to slashes
 
 n	test/mosquitto/messages/load/received
 n	test/mosquitto/messages/load/#
@@ -24,6 +26,9 @@ n	test/jp/j1
 n	$SYS/broker/load/messages/received/1min		test.mosquitto.messages.load.received
 n	$SYS/broker/load/messages/sent/1min		test.mosquitto.messages.load.sent
 
+# Will be sent to "homeautomation.sensor.temperature.bedroom"
+n	sensor/temperature/bedroom	homeautomation.#
+
 j	test/jp/j2
 
 j	test/jp/j3					test.jp.json

+ 2 - 0
mqtt2graphite.py

@@ -76,6 +76,8 @@ def on_message(mosq, userdata, msg):
             if remap is None:
                 carbonkey = msg.topic.replace('/', '.')
             else:
+                if '#' in remap:
+                    remap = remap.replace('#', msg.topic.replace('/', '.'))
                 carbonkey = remap.replace('/', '.')
             logging.debug("CARBONKEY is [%s]" % carbonkey)