Commit e0035c82 authored by julric's avatar julric

check for matching number of sensors vs. RRD DataSources

parent b35de1bf
import output
import datetime
import rrdtool
from subprocess import check_output
from rrdtool import update as rrd_update
class rrd(output.Output):
......@@ -14,6 +14,9 @@ class rrd(output.Output):
rrd_value = "N"
# build the RRD-update-string in the following order:
# TemperatureBMP:TemperatureDHT:Pressure:Relative_Humidity:Light_Level:Hitrogen_Dioxide:Carbon_Monoxide:Volume:Smoke_Level
if [i for i, x in enumerate(dataPoints) if x["name"] == "TemperatureBMP" and x["sensor"] == "BMP085"]:
array_index = [i for i, x in enumerate(dataPoints) if x["name"] == "TemperatureBMP" and x["sensor"] == "BMP085"][0]
rrd_value = rrd_value + ":" + str(int(round(dataPoints[array_index]["value"])))
......@@ -61,5 +64,32 @@ class rrd(output.Output):
rrd_value = rrd_value + ":U"
# print rrd_value
# prints something like "N:20:21:999:44:14127:34286:641304:2758:17073"
# get the number of datasources in the RRD-file
last = check_output(["rrdtool", "lastupdate", self.rrd_file])
lastvalues = last.split( )
datasources = (len(lastvalues)-1)/2
# array lastvalues consists of every sensor-name, then the time and the sensor-values:
# ['tempbmp', 'tempdht', 'press', 'humi', 'light', 'no2', 'co', 'vol', 'smoke', '1406917791:', '9969', '28', '30', '993', '40', '1840', '64672', '424615', '3081']
# check if number of sensor values matches number of items in the RRD-file
if datasources == (len(rrd_value.split(':'))-1):
ret = rrd_update(self.rrd_file, rrd_value);
return True
print "ERROR: Your RRD-datasources missmatch the number of polled sensors!"
return False
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment