The persistence of the data published by the Auditing mechanism can be controlled. Product provides two persistence strategies:
Persistence strategy is defined in the config.ini using the AUDIT_PERSISTENCE_STRATEGY parameter, which by default, is set to com.k2view.fabric.auditing.persistence.CassandraBeanPersistence.
In addition to the above product strategies, a new strategy can be defined by creating your own class. The steps on how to do it are explained further on in this article.
In order to switch the persistence strategy to Kafka, do the following:
AUDIT_PERSISTENCY_STRATEGY = com.k2view.fabric.auditing.persistence.KafkaBeanPersistence
AUDIT=ON
Configure the Kafka producer using the relevant parameters in the [audit_kafka_producer] section of the config.ini file.
Restart the Fabric node.
When you have a requirement to make the audit records available to another channel, the persistence strategy should be changed from Cassandra to Kafka.
For example, when you need to log the Audit records into some relational DB (e.g. PostgreSQL), you can publish them to Kafka. To do so, update the AUDIT_PERSISTENCY_STRATEGY parameter in the config.ini to com.k2view.fabric.auditing.persistence.KafkaBeanPersistence and restart the Fabric node as explained above.
Then, create a Broadway flow that will consume the Kafka messages and load them into your required target DB.
The below Broadway flow consumes the Audit messages from Kafka topic and loads them into the target PostgreSQL DB.
The Kafka message looks as follows:
{
"action": "GetCommand",
"username": "admin",
"result": "LU type 'OracleLu' not found. Please deploy it using K2view Fabric Studio",
"sessionId": "264adf99",
"query": "get OracleLu.5 ",
"params": {
"DC_NAME": "null",
"LU_NAME": "OracleLu",
"IID": "5"
},
"protocol": "DRIVER",
"address": "127.0.0.1"
}
In order to define a new persistency strategy, create your own persistency strategy class. Alternatively, you can start from the sample class com.k2view.external.fabric.audit.persistencies.SamplePersist provided as part of the Fabric installation and modify it according to your needs.
In case of your own class, it must be created under the com.k2view.external.fabric.audit.persistencies folder and it should implement the com.k2view.external.fabric.audit.filters.AuditBeanPersistence interface.
Build artifacts by doing the same steps as described in the Filtering Strategy article. Then, do the following:
AUDIT_PERSISTENCY_STRATEGY = com.k2view.external.fabric.audit.persistencies.SamplePersist
AUDIT=ON
The following example displays the persistency class com.k2view.external.fabric.audit.persistencies.SamplePersist which writes the Audit operations into a file.
package com.k2view.external.fabric.audit.persistencies;
import com.k2view.fabric.common.Log;
import com.k2view.fabric.auditing.AuditBean;
import com.k2view.fabric.auditing.persistence.AuditBeanPersistence;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.Date;
public class SamplePersist implements AuditBeanPersistence {
@Override
public void persist(AuditBean auditBean) throws Exception {
/*
* Here you should add your way of how to persist the bean
*/
Date d = new Date();
String fileName="/home/k2view/AuditFiles/AuditFile.txt";
BufferedWriter writer = new BufferedWriter(new FileWriter(fileName, true));
writer.write("Bean {} will not be persisted "+ auditBean.toString());
writer.flush();
writer.close();
Log.a(SamplePersist.class).info("Bean {} will not be persisted", auditBean.toString());
}
}
The persistence of the data published by the Auditing mechanism can be controlled. Product provides two persistence strategies:
Persistence strategy is defined in the config.ini using the AUDIT_PERSISTENCE_STRATEGY parameter, which by default, is set to com.k2view.fabric.auditing.persistence.CassandraBeanPersistence.
In addition to the above product strategies, a new strategy can be defined by creating your own class. The steps on how to do it are explained further on in this article.
In order to switch the persistence strategy to Kafka, do the following:
AUDIT_PERSISTENCY_STRATEGY = com.k2view.fabric.auditing.persistence.KafkaBeanPersistence
AUDIT=ON
Configure the Kafka producer using the relevant parameters in the [audit_kafka_producer] section of the config.ini file.
Restart the Fabric node.
When you have a requirement to make the audit records available to another channel, the persistence strategy should be changed from Cassandra to Kafka.
For example, when you need to log the Audit records into some relational DB (e.g. PostgreSQL), you can publish them to Kafka. To do so, update the AUDIT_PERSISTENCY_STRATEGY parameter in the config.ini to com.k2view.fabric.auditing.persistence.KafkaBeanPersistence and restart the Fabric node as explained above.
Then, create a Broadway flow that will consume the Kafka messages and load them into your required target DB.
The below Broadway flow consumes the Audit messages from Kafka topic and loads them into the target PostgreSQL DB.
The Kafka message looks as follows:
{
"action": "GetCommand",
"username": "admin",
"result": "LU type 'OracleLu' not found. Please deploy it using K2view Fabric Studio",
"sessionId": "264adf99",
"query": "get OracleLu.5 ",
"params": {
"DC_NAME": "null",
"LU_NAME": "OracleLu",
"IID": "5"
},
"protocol": "DRIVER",
"address": "127.0.0.1"
}
In order to define a new persistency strategy, create your own persistency strategy class. Alternatively, you can start from the sample class com.k2view.external.fabric.audit.persistencies.SamplePersist provided as part of the Fabric installation and modify it according to your needs.
In case of your own class, it must be created under the com.k2view.external.fabric.audit.persistencies folder and it should implement the com.k2view.external.fabric.audit.filters.AuditBeanPersistence interface.
Build artifacts by doing the same steps as described in the Filtering Strategy article. Then, do the following:
AUDIT_PERSISTENCY_STRATEGY = com.k2view.external.fabric.audit.persistencies.SamplePersist
AUDIT=ON
The following example displays the persistency class com.k2view.external.fabric.audit.persistencies.SamplePersist which writes the Audit operations into a file.
package com.k2view.external.fabric.audit.persistencies;
import com.k2view.fabric.common.Log;
import com.k2view.fabric.auditing.AuditBean;
import com.k2view.fabric.auditing.persistence.AuditBeanPersistence;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.Date;
public class SamplePersist implements AuditBeanPersistence {
@Override
public void persist(AuditBean auditBean) throws Exception {
/*
* Here you should add your way of how to persist the bean
*/
Date d = new Date();
String fileName="/home/k2view/AuditFiles/AuditFile.txt";
BufferedWriter writer = new BufferedWriter(new FileWriter(fileName, true));
writer.write("Bean {} will not be persisted "+ auditBean.toString());
writer.flush();
writer.close();
Log.a(SamplePersist.class).info("Bean {} will not be persisted", auditBean.toString());
}
}