K2BAudit MySQL Configuration

Introduction

This page contains configuration instructions to use K2BAudit with MySQL. These instructions steps must be followed whenever a new environment using this DBMS is created. Some of them also apply when deploying an application with K2BAudit that uses MySQL.

Step 1 - Configure the K2BAudit datastore

In your KB, a new DataStore called “K2BAudit” will appear after executing the “Initialize Audit” action. This DataStore is the location where the audit logs are stored. This DataStore must be configured to connect to the K2BAuditAnalyzer database.

If you are configuring the DataStore in the GeneXus IDE, you can find it in the DataStores section of your environment’s configuration.

K2BAuditDataStoreMySQL
K2BAudit DataStore

If you are configuring the DataStore in the generated application, you must use the configuration file.

Step 2 - Application user retrieval configuration

When an operation is audited, the user that is currently using the application is saved together with the operation values.

In order to get the application user, K2BAudit uses a procedure that is configured in the “After connect” property in the generator. The procedure that should be used in MySQL environments is the “K2BSaveAuditUserMySQL”.

K2BAuditAfterConnectProcedures
K2BAudit After connect procedures

In this procedure there is a section delimited by comments with the text “Set User Code”. The developer must update this section’s contents to load the correct User Code in the &User variable. The default implementation loads the user code from the application context.

K2BAuditAfterConnectSetUserCodeSection
Set User Code section

After updating the procedure’s code, the “After connect” property in the model must be updated to reference this procedure.

K2BAuditAfterConnectPropertyMySQL
After connect property

Step 3 - MySQL configuration

3.1 - Grant “SUPER PRIVILEGE” to the DBMS user configured in the default DataStore in the KB.

The DBMS user must have this privilege in order to create triggers in the database. To grant this privilege, use the following command as “root” in the MySQL console:

GRANT ALL PRIVILEGES ON *.* TO <dbmsUser>@localhost IDENTIFIED BY ‘<password>’

3.2 - Create the “K2BSetAppInfo” stored procedure

This stored procedure is used by the GeneXus procedure configured in the second step. In order to create this stored procedure, open the MySQL console, select the application’s database and execute the script located in: <GX_INSTALL_DIR>\Packages\K2BTools\Audit\MYSQL\ K2BAuditProcedures.sql