diff options
| author | Blaise Thompson <blaise@untzag.com> | 2020-10-30 15:14:38 -0500 | 
|---|---|---|
| committer | Blaise Thompson <blaise@untzag.com> | 2020-10-30 15:14:38 -0500 | 
| commit | 008a3dfe234a0207f7c558559cebae993083099f (patch) | |
| tree | e2233fbc448552b3a330f1d04fc584d3fcd503b8 /write-influx | |
| parent | 78279423aee348977163064898ed2c9658ecf840 (diff) | |
hardcoded influx passwords
Diffstat (limited to 'write-influx')
| -rw-r--r-- | write-influx/write_influx.py | 25 | 
1 files changed, 20 insertions, 5 deletions
diff --git a/write-influx/write_influx.py b/write-influx/write_influx.py index 78e4da5..7337c9d 100644 --- a/write-influx/write_influx.py +++ b/write-influx/write_influx.py @@ -9,7 +9,6 @@ from typing import List, Dict  class Topic(dict): -      def __init__(self):          super().__init__()          self["__value__"] = None @@ -43,7 +42,14 @@ def on_message(client, userdata, msg):      tags = {}      tags["device_id"] = topics[1]      # case of device attribute -    device_attributes = ["$homie", "$name", "$state", "$nodes", "$extensions", "$implementation"] +    device_attributes = [ +        "$homie", +        "$name", +        "$state", +        "$nodes", +        "$extensions", +        "$implementation", +    ]      if len(topics) == 3 and topics[2] in device_attributes:          measurement = topics[2]          fields = {"value": payload} @@ -60,11 +66,21 @@ def on_message(client, userdata, msg):          write_point(measurement, tags, fields) -influx_client = InfluxDBClient("db", 8086, 'root', 'root', "homie") +influx_client = InfluxDBClient(host="db", +                               port=8086, +                               username="admin", +                               password="mypassword", +                               database="homie")  influx_client.create_database("homie")  try: -    influx_client.create_retention_policy(name="two-years", database="homie", duration="18000h", default=True, replication=1) +    influx_client.create_retention_policy( +        name="two-years", +        database="homie", +        duration="18000h", +        default=True, +        replication=1, +    )  except:      pass @@ -81,7 +97,6 @@ def write_point(measurement, tags, fields):      print(json) -  client = mqtt.Client()  client.on_connect = on_connect  client.on_message = on_message  | 
