if os.access(databasename,os.W_OK and os.R_OK):
    infostr="sqlite-database:'{0}' created and access possible".format(databasename)
else:
    infostr="sqlite-database:'{0}' not available".format(databasename)
print(infostr)
logging.info(infostr)

sqlitedb.close()

infostr="------------------------------------------------"
logging.info(infostr)
print(infostr)
infostr="Create: rrdtool-database (if request is enabled)"
logging.info(infostr)
print(infostr)
rrdtool=db_rrdtool.cdb_rrdtool(configurationfilename, logger=logging)
if not rrdtool.is_rrdtool_db_enabled():
    infostr="rrdtool-database will not be created"
    logging.info(infostr)
    print(infostr)
    infostr="  enable-flag is set to 'False' in configuration"
    logging.info(infostr)
    print(infostr)
else:    
    rrdtool.createdb_rrdtool()
    if rrdtool.is_rrdtool_db_available():
        infostr="rrdtool-databases:'{0}' created and access possible".format(rrdtool.db_rrdtool_filename())
    else:
        infostr="rrdtool-databases:'{0}' not available".format(rrdtool.db_rrdtool_filename())

logging.info(infostr)
Beispiel #2
0
    def __DispatchThread(self, parameter):
        """
            Dispatch-Thread: open databases if required and storing the results in db.
             automatic draw for rrdtool-draw ist called every 60 sec. if db is enabled.
             automatic erase of old data is done in sqlite-db if it is enabled.
        """
        debug = 0
        rrdtooldb = None
        nextTimeStep = time.time()
        nextTimeautocreate = time.time()
        sqlite_autoerase = False

        # get db-instance
        database = db_sqlite.cdb_sqlite(self.__cfgfilename, logger=self._logging)
        database.connect()

        # set flag for erasing sqlite-db if enabled
        if database.is_sql_db_enabled() and ht3_cworker._gdata.Sqlite_autoerase_seconds() > 0:
            sqlite_autoerase = True

        if ht3_cworker._gdata.is_db_rrdtool_enabled():
            try:
                rrdtooldb = db_rrdtool.cdb_rrdtool(self.__cfgfilename, logger=self._logging)
                rrdtooldb.createdb_rrdtool()
                # setup the first 'nextTimeStep' to 3 times stepseconds waiting for valid data
                nextTimeStep = time.time() + int(ht3_cworker._gdata.db_rrdtool_stepseconds()) * 3
            except:
                errorstr = "ht3_cworker();Error; could not init rrdtool-db"
                self._logging.critical(errorstr)
                self._logging.info("ht3_cworker.run(); End   ----------------------")
                quit()
            # setup first timestep-value for autocreating draw
            if ht3_cworker._gdata.IsAutocreate_draw() > 0:
                nextTimeautocreate = time.time() + 240

        rawdata = ht_discode.cht_discode(self.__port, ht3_cworker._gdata, debug, self.__filehandle, logger=self._logging)

        while self.__threadrun:
            # get the decoded values and store them to db if enabled.
            (nickname, value) = rawdata.discoder()
            if value != None:
                if database.is_sql_db_enabled():
                    database.insert(str(ht3_cworker._gdata.getlongname(nickname)), value)
                    database.commit()

                if ht3_cworker._gdata.is_db_rrdtool_enabled() and rrdtooldb != None:
                    # write data to rrdtool-db after 'stepseconds' seconds
                    if time.time() >= nextTimeStep:
                        # setup next timestep
                        nextTimeStep = time.time() + int(ht3_cworker._gdata.db_rrdtool_stepseconds())
                        # update rrdtool database
                        for syspartshortname in rrdtooldb.syspartnames():
                            if syspartshortname.upper() == 'DT':
                                continue
                            syspartname = rrdtooldb.syspartnames()[syspartshortname]
                            itemvalue_array = ht3_cworker._gdata.getall_sorted_items_with_values(syspartshortname)
                            error = rrdtooldb.update(syspartname, itemvalue_array, time.time())
                            if error:
                                self._logging.critical("rrdtooldb.update();Error;syspartname:{0}".format(syspartname))

                if ht3_cworker._gdata.is_db_rrdtool_enabled() and ht3_cworker._gdata.IsAutocreate_draw() > 0:
                    if time.time() >= nextTimeautocreate:
                        # setup next timestep for autocreating draw
                        nextTimeautocreate = time.time() + 60 * ht3_cworker._gdata.IsAutocreate_draw()
                        # create draw calling script
                        (db_path, dbfilename) = ht3_cworker._gdata.db_rrdtool_filepathname()
                        (html_path, filename) = ht3_cworker._gdata.db_rrdtool_filepathname('.')
                        self.__Autocreate_draw(db_path, html_path, ht3_cworker._gdata.heatercircuits_amount())

                if sqlite_autoerase:
                    self.__Autoerasing_sqlitedb(database)

        #close db at the end of thread
        database.close()
Beispiel #3
0
    def __DispatchThread(self, parameter):
        """
            Dispatch-Thread: open databases if required and storing the results in db.
             automatic draw for rrdtool-draw ist called every 60 sec. if db is enabled.
             automatic erase of old data is done in sqlite-db if it is enabled.
        """
        debug = 0
        rrdtooldb = None
        nextTimeStep = time.time()
        nextTimeautocreate = time.time()
        sqlite_autoerase = False

        # get db-instance
        database = db_sqlite.cdb_sqlite(self.__cfgfilename, logger=self._logging)
        database.connect()

        # set flag for erasing sqlite-db if enabled
        if database.is_sql_db_enabled() and ht3_cworker._gdata.Sqlite_autoerase_seconds() > 0:
            sqlite_autoerase = True

        if ht3_cworker._gdata.is_db_rrdtool_enabled():
            try:
                rrdtooldb = db_rrdtool.cdb_rrdtool(self.__cfgfilename, logger=self._logging)
                rrdtooldb.createdb_rrdtool()
                # setup the first 'nextTimeStep' to 3 times stepseconds waiting for valid data
                nextTimeStep = time.time() + int(ht3_cworker._gdata.db_rrdtool_stepseconds()) * 3
            except:
                errorstr = "ht3_cworker();Error; could not init rrdtool-db"
                self._logging.critical(errorstr)
                self._logging.info("ht3_cworker.run(); End   ----------------------")
                quit()
            # setup first timestep-value for autocreating draw
            if ht3_cworker._gdata.IsAutocreate_draw() > 0:
                nextTimeautocreate = time.time() + 240

        rawdata = ht_discode.cht_discode(self.__port, ht3_cworker._gdata, debug, self.__filehandle, logger=self._logging)

        while self.__threadrun:
            # get the decoded values and store them to db if enabled.
            (nickname, value) = rawdata.discoder()
            if value != None:
                if database.is_sql_db_enabled():
                    database.insert(str(ht3_cworker._gdata.getlongname(nickname)), value)
                    database.commit()

                if ht3_cworker._gdata.is_db_rrdtool_enabled() and rrdtooldb != None:
                    # write data to rrdtool-db after 'stepseconds' seconds
                    if time.time() >= nextTimeStep:
                        # setup next timestep
                        nextTimeStep = time.time() + int(ht3_cworker._gdata.db_rrdtool_stepseconds())
                        # update rrdtool database
                        for syspartshortname in rrdtooldb.syspartnames():
                            if syspartshortname.upper() == 'DT':
                                continue
                            syspartname = rrdtooldb.syspartnames()[syspartshortname]
                            itemvalue_array = ht3_cworker._gdata.getall_sorted_items_with_values(syspartshortname)
                            error = rrdtooldb.update(syspartname, itemvalue_array, time.time())
                            if error:
                                self._logging.critical("rrdtooldb.update();Error;syspartname:{0}".format(syspartname))

                if ht3_cworker._gdata.is_db_rrdtool_enabled() and ht3_cworker._gdata.IsAutocreate_draw() > 0:
                    if time.time() >= nextTimeautocreate:
                        # setup next timestep for autocreating draw
                        nextTimeautocreate = time.time() + 60 * ht3_cworker._gdata.IsAutocreate_draw()
                        # create draw calling script
                        (db_path, dbfilename) = ht3_cworker._gdata.db_rrdtool_filepathname()
                        (html_path, filename) = ht3_cworker._gdata.db_rrdtool_filepathname('.')
                        rrdtooldb.create_draw(db_path, html_path,
                                              ht3_cworker._gdata.heatercircuits_amount(),
                                              ht3_cworker._gdata.controller_type_nr(),
                                              ht3_cworker._gdata.GetAllMixerFlags(),
                                              int(ht3_cworker._gdata.IsTempSensor_Hydrlic_Switch()),
                                              int(ht3_cworker._gdata.IsSolarAvailable()),
                                              int(ht3_cworker._gdata.IsSecondCollectorValue_SO()))
                if sqlite_autoerase:
                    self.__Autoerasing_sqlitedb(database)

        #close db at the end of thread
        database.close()
Beispiel #4
0
import db_sqlite
import db_rrdtool

configurationfilename='./etc/config/HT3_db_cfg.xml'
sqlitedb=db_sqlite.cdb_sqlite(configurationfilename)
sqlitedb.connect()
print("------------------------")
print("Create: sqlite -database")
sqlitedb.createdb_sqlite()
#check created sqlite-database for read/write access
databasename=sqlitedb.db_sqlite_filename()
if os.access(databasename,os.W_OK and os.R_OK):
    print("sqlite-database:'{0}' created and access possible".format(databasename))
else:
    print("sqlite-database:'{0}' not available".format(databasename))

sqlitedb.close()

print("------------------------------------------------")
print("Create: rrdtool-database (if request is enabled)")
rrdtool=db_rrdtool.cdb_rrdtool(configurationfilename)
if not rrdtool.is_rrdtool_db_enabled():
    print("rrdtool-database will not be created")
    print("  enable-flag is set to 'False' in configuration")
else:    
    rrdtool.createdb_rrdtool()
    if rrdtool.is_rrdtool_db_available():
        print("rrdtool-databases:'{0}' created and access possible".format(rrdtool.db_rrdtool_filename()))
    else:
        print("rrdtool-databases:'{0}' not available".format(rrdtool.db_rrdtool_filename()))
    infostr = "sqlite-database:'{0}' created and access possible".format(
        databasename)
else:
    infostr = "sqlite-database:'{0}' not available".format(databasename)
print(infostr)
logging.info(infostr)

sqlitedb.close()

infostr = "------------------------------------------------"
logging.info(infostr)
print(infostr)
infostr = "Create: rrdtool-database (if request is enabled)"
logging.info(infostr)
print(infostr)
rrdtool = db_rrdtool.cdb_rrdtool(configurationfilename, logger=logging)
if not rrdtool.is_rrdtool_db_enabled():
    infostr = "rrdtool-database will not be created"
    logging.info(infostr)
    print(infostr)
    infostr = "  enable-flag is set to 'False' in configuration"
    logging.info(infostr)
    print(infostr)
else:
    rrdtool.createdb_rrdtool()
    if rrdtool.is_rrdtool_db_available():
        infostr = "rrdtool-databases:'{0}' created and access possible".format(
            rrdtool.db_rrdtool_filename())
    else:
        infostr = "rrdtool-databases:'{0}' not available".format(
            rrdtool.db_rrdtool_filename())
Beispiel #6
0
    def run(self):
        """worker thread for sqlite-db using 'threading.Thread'"""
        import sqlite3
        import db_sqlite
        import db_rrdtool
        debug = 0
        rrdtooldb = None
        nextTimeStep = time.time()
        nextTimeautocreate = time.time()
        sqlite_autoerase = False

        # get db-instance
        database = db_sqlite.cdb_sqlite(self._cfg_file, logger=self._logging)
        database.connect()

        # set flag for erasing sqlite-db if enabled
        if database.is_sql_db_enabled() and self._ht_if.ht_if_data().Sqlite_autoerase_seconds() > 0:
            sqlite_autoerase = True

        if self._ht_if.ht_if_data().is_db_rrdtool_enabled():
            try:
                rrdtooldb = db_rrdtool.cdb_rrdtool(self._cfg_file, self._logging)
                rrdtooldb.createdb_rrdtool()
                # setup the first 'nextTimeStep' to 3 times stepseconds waiting for valid data
                nextTimeStep = time.time() + int(self._ht_if.ht_if_data().db_rrdtool_stepseconds()) * 3
            except:
                errorstr = "cstore2db.run();Error; could not init rrdtool-db"
                self._logging.critical(errorstr)
                self._logging.info("cstore2db.run(); End   ----------------------")
                quit()
            # setup first timestep-value for autocreating draw
            if self._ht_if.ht_if_data().IsAutocreate_draw() > 0:
                nextTimeautocreate = time.time() + 240

        while self.__thread_run:
            try:
                # read values from queue, wait if empty or stop if (None, None)
                (nickname, value) = self._ht_if.decoded_data_4_DBs().get()
                # terminate thread if both values are None, else process them
                if (nickname, value) == (None, None):
                    self.stop()
                    break

                if database.is_sql_db_enabled():
                    database.insert(str(self._ht_if.ht_if_data().getlongname(nickname)), value)
                    database.commit()

                if self._ht_if.ht_if_data().is_db_rrdtool_enabled() and rrdtooldb != None:
                    # write data to rrdtool-db after 'stepseconds' seconds
                    if time.time() >= nextTimeStep:
                        # setup next timestep
                        nextTimeStep = time.time() + int(self._ht_if.ht_if_data().db_rrdtool_stepseconds())
                        # update rrdtool database
                        for syspartshortname in rrdtooldb.syspartnames():
                            if syspartshortname.upper() == 'DT':
                                continue
                            syspartname = rrdtooldb.syspartnames()[syspartshortname]
                            itemvalue_array = self._ht_if.ht_if_data().getall_sorted_items_with_values(syspartshortname)
                            error = rrdtooldb.update(syspartname, itemvalue_array, time.time())
                            if error:
                                self._logging.critical("rrdtooldb.update();Error;syspartname:{0}".format(syspartname))

                if self._ht_if.ht_if_data().is_db_rrdtool_enabled() and self._ht_if.ht_if_data().IsAutocreate_draw() > 0:
                    if time.time() >= nextTimeautocreate:
                        # setup next timestep for autocreating draw
                        nextTimeautocreate = time.time() + 60 * self._ht_if.ht_if_data().IsAutocreate_draw()
                        # create draw calling script
                        (db_path, dbfilename) = self._ht_if.ht_if_data().db_rrdtool_filepathname()
                        (html_path, filename) = self._ht_if.ht_if_data().db_rrdtool_filepathname('.')
                        rrdtooldb.create_draw(db_path, html_path,
                                              self._ht_if.ht_if_data().heatercircuits_amount(),
                                              self._ht_if.ht_if_data().controller_type_nr(),
                                              self._ht_if.ht_if_data().GetAllMixerFlags())

                if sqlite_autoerase:
                    self.__Autoerasing_sqlitedb(database)

                # clear last queue-entry with task_done()
                self._ht_if.decoded_data_4_DBs().task_done()
            except:
                errorstr = "cstore2db.run();Error; on ht_if.decoded_data_4_DBs().get()"
                self._logging.critical(errorstr)
                self.stop()
                raise
        #close db at the end of thread
        database.close()
        errorstr = "cstore2db.run();Error; thread terminated unexpected"
        self._logging.critical(errorstr)