The JavaScript request filter is the most flexible of all response filters. It can potentially be called for any packet type, and can modify traffic in any way it sees fit.
Query pattern: optional. If specified, this filter will be invoked only if the current CQL for this packet's stream matches this pattern. Can be a string or a regular expression.
Packet types : optional. If specified, a comma-separated list of packet types for which this filter should be called, for instance: Supported,Event. Spaces are ignored.
Client IPs: optional. If specified, a comma-separated (or line break separated) list of IP4 or IP6 addresses or regular expressions for IP addresses.
Users: optional. If specified, a comma-separated (or line break separated) list of user names or regular expressions for user names.
We can intercept packets of type ResultRows and change them so that a column will show up differently.
The JavaScript response filter will have the parameter:
Packet types: ResultRows
Query pattern: regex:select.*mydb.mytable.*
The filter's code might then look like:
let colspec = context.packet.getColumnSpecByName("badColumnName");
colspec.columnName = "goodColumnName";
Obviously, you must ensure that this type of logic does not break the database clients.
You can catch response packets of type Error and log them to a file or some other system to keep track of certain problems:
let FileWriter = Java.type("java.io.FileWriter");
let BufferedWriter = Java.type("java.io.BufferedWriter");
let outFile = new FileWriter("/var/log/ErrorTrace.log", true);
let out = new BufferedWriter(outFile);
out.write("" + new Date() + " - Error packet received: " + context.packet + "\n");
out.close();
Note that, if performance is critical, it may be a good idea to store the out object in the connection context to avoid opening and closing it all the time:
let out = context.connectionContext.ErrorLogFilter_out;
if ( ! out) {
let FileWriter = Java.type("java.io.FileWriter");
let outFile = new FileWriter("/var/log/ErrorTrace.log", true);
let BufferedWriter = Java.type("java.io.BufferedWriter");
out = new BufferedWriter(outFile);
context.connectionContext.ErrorLogFilter_out = out;
}
out.write("" + new Date() + " - Error packet received: " + context.packet + "\n");
out.flush();