Addition of user and source to all filter
Bug fix in timestamp for topfilter
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -31,6 +31,7 @@
|
||||
* Date Who Description
|
||||
* 03/06/2014 Mark Riddoch Initial implementation
|
||||
* 11/06/2014 Mark Riddoch Addition of source and match parameters
|
||||
* 19/06/2014 Mark Riddoch Addition of user parameter
|
||||
*
|
||||
*/
|
||||
#include <stdio.h>
|
||||
@ -54,7 +55,7 @@ MODULE_INFO info = {
|
||||
"A simple query logging filter"
|
||||
};
|
||||
|
||||
static char *version_str = "V1.1.0";
|
||||
static char *version_str = "V1.1.1";
|
||||
|
||||
/*
|
||||
* The filter entry points
|
||||
@ -92,6 +93,7 @@ typedef struct {
|
||||
int sessions; /* The count of sessions */
|
||||
char *filebase; /* The filemane base */
|
||||
char *source; /* The source of the client connection */
|
||||
char *userName; /* The user name to filter on */
|
||||
char *match; /* Optional text to match against */
|
||||
regex_t re; /* Compiled regex text */
|
||||
char *nomatch; /* Optional text to match against for exclusion */
|
||||
@ -168,6 +170,7 @@ int i;
|
||||
else
|
||||
my_instance->filebase = strdup("qla");
|
||||
my_instance->source = NULL;
|
||||
my_instance->userName = NULL;
|
||||
my_instance->match = NULL;
|
||||
my_instance->nomatch = NULL;
|
||||
if (params)
|
||||
@ -184,6 +187,8 @@ int i;
|
||||
}
|
||||
else if (!strcmp(params[i]->name, "source"))
|
||||
my_instance->source = strdup(params[i]->value);
|
||||
else if (!strcmp(params[i]->name, "user"))
|
||||
my_instance->userName = strdup(params[i]->value);
|
||||
else if (!strcmp(params[i]->name, "filebase"))
|
||||
{
|
||||
if (my_instance->filebase)
|
||||
@ -247,7 +252,7 @@ newSession(FILTER *instance, SESSION *session)
|
||||
{
|
||||
QLA_INSTANCE *my_instance = (QLA_INSTANCE *)instance;
|
||||
QLA_SESSION *my_session;
|
||||
char *remote;
|
||||
char *remote, *userName;
|
||||
|
||||
if ((my_session = calloc(1, sizeof(QLA_SESSION))) != NULL)
|
||||
{
|
||||
@ -265,6 +270,13 @@ char *remote;
|
||||
if (strcmp(remote, my_instance->source))
|
||||
my_session->active = 0;
|
||||
}
|
||||
if (session && session->client && session->client->user)
|
||||
userName = session->client->user;
|
||||
else
|
||||
userName = NULL;
|
||||
if (my_instance->userName && strcmp(userName,
|
||||
my_instance->userName))
|
||||
my_session->active = 0;
|
||||
sprintf(my_session->filename, "%s.%d", my_instance->filebase,
|
||||
my_instance->sessions);
|
||||
my_instance->sessions++;
|
||||
|
@ -33,6 +33,12 @@ extern int lm_enabled_logfiles_bitmask;
|
||||
* Two parameters should be defined in the filter configuration
|
||||
* match=<regular expression>
|
||||
* replace=<replacement text>
|
||||
* Two optional parameters
|
||||
* source=<source address to limit filter>
|
||||
* user=<username to limit filter>
|
||||
*
|
||||
* Date Who Description
|
||||
* 19/06/2014 Mark Riddoch Addition of source and user parameters
|
||||
*/
|
||||
|
||||
MODULE_INFO info = {
|
||||
@ -42,7 +48,7 @@ MODULE_INFO info = {
|
||||
"A query rewrite filter that uses regular expressions to rewite queries"
|
||||
};
|
||||
|
||||
static char *version_str = "V1.0.0";
|
||||
static char *version_str = "V1.1.0";
|
||||
|
||||
static FILTER *createInstance(char **options, FILTER_PARAMETER **params);
|
||||
static void *newSession(FILTER *instance, SESSION *session);
|
||||
@ -70,6 +76,8 @@ static FILTER_OBJECT MyObject = {
|
||||
* Instance structure
|
||||
*/
|
||||
typedef struct {
|
||||
char *source; /* Source address to restrict matches */
|
||||
char *user; /* User name to restrict matches */
|
||||
char *match; /* Regular expression to match */
|
||||
char *replace; /* Replacement text */
|
||||
regex_t re; /* Compiled regex text */
|
||||
@ -79,9 +87,10 @@ typedef struct {
|
||||
* The session structure for this regex filter
|
||||
*/
|
||||
typedef struct {
|
||||
DOWNSTREAM down;
|
||||
int no_change;
|
||||
int replacements;
|
||||
DOWNSTREAM down; /* The downstream filter */
|
||||
int no_change; /* No. of unchanged requests */
|
||||
int replacements; /* No. of changed requests */
|
||||
int active; /* Is filter active */
|
||||
} REGEX_SESSION;
|
||||
|
||||
/**
|
||||
@ -143,6 +152,10 @@ int i, cflags = REG_ICASE;
|
||||
my_instance->match = strdup(params[i]->value);
|
||||
else if (!strcmp(params[i]->name, "replace"))
|
||||
my_instance->replace = strdup(params[i]->value);
|
||||
else if (!strcmp(params[i]->name, "source"))
|
||||
my_instance->source = strdup(params[i]->value);
|
||||
else if (!strcmp(params[i]->name, "user"))
|
||||
my_instance->user = strdup(params[i]->value);
|
||||
else if (!filter_standard_parameter(params[i]->name))
|
||||
{
|
||||
LOGIF(LE, (skygw_log_write_flush(
|
||||
@ -203,12 +216,28 @@ int i, cflags = REG_ICASE;
|
||||
static void *
|
||||
newSession(FILTER *instance, SESSION *session)
|
||||
{
|
||||
REGEX_INSTANCE *my_instance = (REGEX_INSTANCE *)instance;
|
||||
REGEX_SESSION *my_session;
|
||||
char *remote;
|
||||
|
||||
if ((my_session = calloc(1, sizeof(REGEX_SESSION))) != NULL)
|
||||
{
|
||||
my_session->no_change = 0;
|
||||
my_session->replacements = 0;
|
||||
my_session->active = 1;
|
||||
if (my_instance->source
|
||||
&& (remote = session_get_remote(session)) != NULL)
|
||||
{
|
||||
if (strcmp(remote, my_instance->source))
|
||||
my_session->active = 0;
|
||||
}
|
||||
if (my_instance->user
|
||||
&& session && session->client && session->client->user
|
||||
&& strcmp(session->client->user,
|
||||
my_instance->user))
|
||||
{
|
||||
my_session->active = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return my_session;
|
||||
|
@ -27,6 +27,9 @@
|
||||
* A single option may be passed to the filter, this is the name of the
|
||||
* file to which the queries are logged. A serial number is appended to this
|
||||
* name in order that each session logs to a different file.
|
||||
*
|
||||
* Date Who Description
|
||||
* 18/06/2014 Mark Riddoch Addition of source and user filters
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
@ -49,7 +52,7 @@ MODULE_INFO info = {
|
||||
"A top N query logging filter"
|
||||
};
|
||||
|
||||
static char *version_str = "V1.0.0";
|
||||
static char *version_str = "V1.0.1";
|
||||
|
||||
/*
|
||||
* The filter entry points
|
||||
@ -357,7 +360,7 @@ FILE *fp;
|
||||
}
|
||||
fprintf(fp, "-----------+-----------------------------------------------------------------\n");
|
||||
fprintf(fp, "\n\nSession started %s",
|
||||
asctime(localtime(&my_session->connect)));
|
||||
asctime(localtime(&my_session->connect.tv_sec)));
|
||||
if (my_session->clientHost)
|
||||
fprintf(fp, "Connection from %s\n",
|
||||
my_session->clientHost);
|
||||
|
Reference in New Issue
Block a user