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 | |
| parent | 78279423aee348977163064898ed2c9658ecf840 (diff) | |
hardcoded influx passwords
| -rw-r--r-- | docker-compose.yml | 2 | ||||
| -rw-r--r-- | influxdb/dockerfile | 6 | ||||
| -rw-r--r-- | web/index.html | 5 | ||||
| -rw-r--r-- | write-influx/write_influx.py | 25 | 
4 files changed, 32 insertions, 6 deletions
diff --git a/docker-compose.yml b/docker-compose.yml index d5b0812..9201a9a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,7 +19,7 @@ services:    web:      build: ./web      ports: -      - 80:80 +      - 8080:80      depends_on:        - broker        - db diff --git a/influxdb/dockerfile b/influxdb/dockerfile index d3f86a2..0a36f75 100644 --- a/influxdb/dockerfile +++ b/influxdb/dockerfile @@ -3,4 +3,10 @@ FROM influxdb:1.8  ENV TZ=America/Chicago  RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone +ENV INFLUXDB_DB="homie" +ENV INFLUXDB_ADMIN_USER="admin" +ENV INFLUXDB_ADMIN_PASSWORD="mypassword" +ENV INFLUXDB_READ_USER="millikan" +ENV INFLUXDB_READ_USER_PASSWORD="1.602e-19" +  RUN ./init-influxdb.sh diff --git a/web/index.html b/web/index.html index 78d52a6..fbbbf1c 100644 --- a/web/index.html +++ b/web/index.html @@ -81,6 +81,11 @@ Device history older than two years will automatically be deleted.  </p>  <p> +Homie data is written to the database with each [node] as one [field]. +All of the additional information that is represented within the homie hierarchy is stored as tags. +</p> + +<p>  EXAMPLE CURL  </p> 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  | 
