Table of Contents
Database Handler
A Log-Handler subclass to write log-events into a database. This Handler uses the HSE-DB library and the DB-CONNECTOR DQMH-module as a general backend to communicate with several different databases.
Installation
Copy Database Handler source code from the repository into the project or use the latest Log DB Handler release
To create a table with the correct schema, you can use the SQL-files Create Table (MySQL_MariaDB).sql
or Create Table (SQLite).sql
in the Documentation
folder. For other DB-system, you may have to adapt the SQL-files.
SQL to create an appropriate table in MySQL or MariaDB
CREATE TABLE IF NOT EXISTS `log` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `logger_name` VARCHAR(50) NOT NULL DEFAULT 'NA', `time` TIMESTAMP(3) NOT NULL, `level` enum('DEBUG','INFO','WARNING','ERROR','CRITICAL') NOT NULL, `source` VARCHAR(250) NOT NULL, `message` VARCHAR(5000) NOT NULL DEFAULT '''', `error_code` INT(11) NOT NULL DEFAULT 0, `error_message` VARCHAR(1000) NOT NULL DEFAULT '''', PRIMARY KEY (`id`), KEY `logger_name` (`logger_name`), KEY `level` (`level`), KEY `error_code` (`error_code`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='HSE-Logger DB-Handler content.';
SQL to create an appropriate table in SQLite
CREATE TABLE "log" ( "id" INTEGER, "logger_name" TEXT, "time" TEXT, "level" TEXT, "source" TEXT, "message" TEXT, "error_code" INTEGER, "error_message" INTEGER, PRIMARY KEY("id" AUTOINCREMENT) );
Configuration
A valid DB_CONNECTOR.ini
configuration file for the HSE DQMH DB Connector module must be provided. Usually it is provided in the configuration unit folder. Please see the section about Alternative Paths
for deploying on an RT system.
User Authentication
For MySQL and MariaDB, we are using our open driver MySQLNetCom. Because this driver doesn't yet support the latest authentication methods, make sure that the user has mysql_native_password access. You can enable mysql_native_password authentication in the DBMS configuration or with the following SQL query.
CREATE USER 'user'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
Usage
Use the method Create DB-Handler.vi
to instantiate a new DB-Handler instance. Additional to the default terminals Name
and Level
, the create method only needs the right configuration section in the DB-CONNECTOR.ini
, the db-table name to store the log-events in and a database-object for the DBMS in-use.
Grafana
Encryption
-
follow these steps to create a DB_Connector capable of reading encrypted credentials
-
create a child class of DB-Handler
-
create a wrapper for starting a database handler which uses a DB_Connector with the DB Interface class, which can read encrypted credentials