-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Route Homie-style MQTT sensor value publications to check_mk spool files
- Loading branch information
Showing
3 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# -*- coding: utf-8 -*- | ||
# Demonstrate Homie function extensions for mqttwarn | ||
|
||
; ======== | ||
; Synopsis | ||
; ======== | ||
; | ||
; Run mqttwarn:: | ||
; | ||
; export MQTTWARNINI=examples/homie/homie.ini | ||
; ./mqttwarn.py | ||
; | ||
; Send some homie-like data:: | ||
; | ||
; mosquitto_pub -t homie/bee1/weight/value -m 42.42 | ||
|
||
|
||
; ================== | ||
; Base configuration | ||
; ================== | ||
|
||
[defaults] | ||
hostname = 'localhost' | ||
clientid = 'mqttwarn' | ||
|
||
; logging | ||
logformat = '%(asctime)-15s %(levelname)-5s [%(module)s] %(message)s' | ||
logfile = stream://sys.stderr | ||
|
||
; one of: CRITICAL, DEBUG, ERROR, INFO, WARN | ||
#loglevel = INFO | ||
loglevel = DEBUG | ||
|
||
; enable service providers | ||
launch = log, file | ||
|
||
; number of notification dispatcher threads | ||
num_workers = 3 | ||
|
||
; path to file containing self-defined functions | ||
functions = 'examples.homie.homie' | ||
|
||
|
||
; ================ | ||
; check_mk routing | ||
; ================ | ||
|
||
; See also https://github.com/jpmens/mqttwarn/wiki/Incorporating-topic-names#incorporate-topic-names-into-topic-targets | ||
|
||
[check_mk_universal] | ||
topic = homie/+/+/value | ||
datamap = decode_homie_topic() | ||
targets = file:cmk_spool | ||
format = <<<<{device}>>>>\n<<<local>>>\n 0 {node} {node}={payload} {node}: {payload} | ||
|
||
[config:file] | ||
append_newline = True | ||
overwrite = True | ||
targets = { | ||
'cmk_spool': ['/var/lib/check_mk_agent/spool/300{device}-{node}'], | ||
} | ||
|
||
|
||
; =============== | ||
; Regular logging | ||
; =============== | ||
|
||
[homie-logging] | ||
; Just log all incoming messages | ||
topic = homie/# | ||
targets = log:info | ||
|
||
[config:log] | ||
targets = { | ||
'debug' : [ 'debug' ], | ||
'info' : [ 'info' ], | ||
'warn' : [ 'warn' ], | ||
'crit' : [ 'crit' ], | ||
'error' : [ 'error' ] | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# -*- coding: utf-8 -*- | ||
# Homie function extensions for mqttwarn | ||
import re | ||
|
||
|
||
# ------------------------------------------ | ||
# Synopsis | ||
# ------------------------------------------ | ||
# | ||
# Run mqttwarn:: | ||
# | ||
# export MQTTWARNINI=examples/homie/homie.ini | ||
# ./mqttwarn.py | ||
# | ||
# Send some homie-like data:: | ||
# | ||
# mosquitto_pub -t homie/bee1/weight/value -m 42.42 | ||
|
||
|
||
def decode_homie_topic(topic): | ||
""" | ||
Split Homie-style MQTT topic path into segments for | ||
enriching transformation data inside mqttwarn. | ||
""" | ||
if type(topic) == str: | ||
try: | ||
pattern = r'^(?P<realm>.+?)/(?P<device>.+?)/(?P<node>.+?)/(?P<property>.+?)$' | ||
p = re.compile(pattern) | ||
m = p.match(topic) | ||
topology = m.groupdict() | ||
except: | ||
topology = {} | ||
return topology | ||
return None | ||
|