1
0
Fork 0
mirror of https://github.com/Luzifer/mqtt2influx.git synced 2024-12-29 22:01:16 +00:00

Allow overriding vars in env, add info on submit

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2020-07-11 18:48:23 +02:00
parent c3c4a0913c
commit bb1a81005e
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E

17
main.py
View file

@ -55,6 +55,10 @@ class MQTT2InfluxDB():
))
if len(points) > 0:
logging.info('Submitting {n} datapoints for topic {topic}'.format(
n=len(points),
topic=msg.topic,
))
self.influx.submit(points)
def run(self):
@ -66,19 +70,16 @@ class MQTT2InfluxDB():
mqtt_config = vault.read_data('secret/mqtt2influx/mqtt')
client.username_pw_set(
self.obj_get(mqtt_config, 'user', self.obj_get(
os.environ, 'MQTT_USER')),
self.obj_get(mqtt_config, 'pass', self.obj_get(
os.environ, 'MQTT_PASS')),
self.obj_get(os.environ, 'MQTT_USER', mqtt_config['user']),
self.obj_get(os.environ, 'MQTT_PASS', mqtt_config['pass']),
)
logging.debug('Connecting to MQTT broker...')
client.connect(
self.obj_get(mqtt_config, 'host', self.obj_get(
os.environ, 'MQTT_HOST')),
port=self.obj_get(mqtt_config, 'port', self.obj_get(
os.environ, 'MQTT_PORT', 1883)),
self.obj_get(os.environ, 'MQTT_HOST', mqtt_config['host']),
self.obj_get(os.environ, 'MQTT_HOST',
self.obj_get(mqtt_config, 'host', 1883)),
keepalive=10,
)