Merge pull request #103 from mstrinzha/influxdb

InfluxDB: support non-ASCII symbols in sensor names
This commit is contained in:
pascal1404 2023-03-23 22:01:59 +01:00 committed by GitHub
commit 6996a93d2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 14 deletions

View file

@ -57,12 +57,9 @@ class LogController:
id = name id = name
try: try:
chars = {'ö':'oe','ä':'ae','ü':'ue','Ö':'Oe','Ä':'Ae','Ü':'Ue'}
sensor=self.cbpi.sensor.find_by_id(name) sensor=self.cbpi.sensor.find_by_id(name)
if sensor is not None: if sensor is not None:
itemname=sensor.name.replace(" ", "_") itemname=sensor.name.replace(" ", "_")
for char in chars:
itemname = itemname.replace(char,chars[char])
out=str(self.influxdbmeasurement)+",source=" + itemname + ",itemID=" + str(id) + " value="+str(value) out=str(self.influxdbmeasurement)+",source=" + itemname + ",itemID=" + str(id) + " value="+str(value)
except Exception as e: except Exception as e:
logging.error("InfluxDB ID Error: {}".format(e)) logging.error("InfluxDB ID Error: {}".format(e))
@ -72,7 +69,7 @@ class LogController:
try: try:
header = {'User-Agent': name, 'Authorization': "Token {}".format(self.influxdbpwd)} header = {'User-Agent': name, 'Authorization': "Token {}".format(self.influxdbpwd)}
http = urllib3.PoolManager() http = urllib3.PoolManager()
req = http.request('POST',self.influxdburl, body=out, headers = header) req = http.request('POST',self.influxdburl, body=out.encode(), headers = header)
except Exception as e: except Exception as e:
logging.error("InfluxDB cloud write Error: {}".format(e)) logging.error("InfluxDB cloud write Error: {}".format(e))
@ -82,7 +79,7 @@ class LogController:
try: try:
header = {'User-Agent': name, 'Content-Type': 'application/x-www-form-urlencoded','Authorization': 'Basic %s' % self.base64string.decode('utf-8')} header = {'User-Agent': name, 'Content-Type': 'application/x-www-form-urlencoded','Authorization': 'Basic %s' % self.base64string.decode('utf-8')}
http = urllib3.PoolManager() http = urllib3.PoolManager()
req = http.request('POST',self.influxdburl, body=out, headers = header) req = http.request('POST',self.influxdburl, body=out.encode(), headers = header)
except Exception as e: except Exception as e:
logging.error("InfluxDB write Error: {}".format(e)) logging.error("InfluxDB write Error: {}".format(e))

View file

@ -225,18 +225,10 @@ class ConfigUpdate(CBPiExtension):
if influxdbaddr is None: if influxdbaddr is None:
logger.info("INIT Influxdbaddr") logger.info("INIT Influxdbaddr")
try: try:
await self.cbpi.config.add("INFLUXDBADDR", "localhost", ConfigType.STRING, "IP Address of your influxdb server (If INFLUXDBCLOUD set to Yes use URL Address of your influxdb cloud server)") await self.cbpi.config.add("INFLUXDBADDR", "http://localhost:8086", ConfigType.STRING, "URL Address of your influxdb server (If INFLUXDBCLOUD set to Yes use URL Address of your influxdb cloud server)")
except: except:
logger.warning('Unable to update config') logger.warning('Unable to update config')
## Check if influxdbport is in config
#if influxdbport is None:
# logger.info("INIT Influxdbport")
# try:
# await self.cbpi.config.add("INFLUXDBPORT", "8086", ConfigType.STRING, "Port of your influxdb server")
# except:
# logger.warning('Unable to update config')
## Check if influxdbname is in config ## Check if influxdbname is in config
if influxdbname is None: if influxdbname is None:
logger.info("INIT Influxdbname") logger.info("INIT Influxdbname")