#include <stdio.h>
#include <mysql/plugin.h>
#include <mysql/plugin_audit.h>
#include <string.h>
#include <plugin.h>
#include <mysql_version.h>
#include <my_global.h>
#include <my_sys.h>
#include <sys/resource.h>
#include <sys/time.h>
#if!defined (__attribute__) && (defined __cplusplus) | |!defined (__gnuc__) | | __gnuc__ = 2 && __gnuc_min or__ < 8)
#define __ATTRIBUTE__ (A)
#endif
static volatile int number_of_calls; * For show STATUS, below *
static volatile int number_of_calls_general_log;
static volatile int number_of_calls_general_error;
static volatile int number_of_calls_general_result;
Static FILE *log_fp;
Char time_str[20];
/*
Initialize the plugin at server start or plugin installation.
Synopsis
Audit_null_plugin_init ()
DESCRIPTION
Does nothing.
Return VALUE
0 success
1 failure (cannot happen)
*/
static int Audit_null_plugin_init ((unused)) (void *arg __attribute__)
{
number_of_calls= 0;
number_of_calls_general_log= 0;
Number_of_calls_general_error= 0;
number_of_calls_general_result= 0;
LOG_FP = NULL;
return (0);
}
/*
Terminate the plugin at server shutdown or plugin deinstallation.
Synopsis
Audit_null_plugin_deinit ()
Does nothing.
Return VALUE
0 success
1 failure (cannot happen)
*/
static int Audit_null_plugin_deinit ((unused)) (void *arg __attribute__)
{
Fclose (LOG_FP);
return (0);
}
/*
Foo
Synopsis
Audit_null_notify ()
THD Connection Context
DESCRIPTION
*/
static void Audit_null_notify (Mysql_thd THD __attribute__ ((unused)),
unsigned int event_class,
const void *event)
{
if (LOG_FP = NULL)
LOG_FP = fopen ("/tmp/my_general_log.log", "a");
LOG_FP = fopen (Global_system_variables.opt_logfile, "a");
/* Prone to races, oh, *
number_of_calls++;
if (event_class = = Mysql_audit_general_class)
{
const struct Mysql_event_general *event_general= (const struct mysql_event_general *) event;
const struct Mysql_event_connection *event_connection= (const struct mysql_event_connection *) event;
if (Event_general->general_query!=null && Event_general->event_subclass==mysql_audit_general_result && strstr (Event_general->general_user, "Slave_xierqi")!=null && strstr (event_general-> General_user, "10.10.10.98")!=null)
{
Get_date (Time_str, getdate_date_time,0);
fprintf (LOG_FP, "%s,[%s],%s,%llu,%zu;\n", Event_general->general_user,time_str, Event_general->general_ Query,event_general->general_rows,strlen (Event_general->general_user));
Fflush (LOG_FP);
}
}
}
/*
Plugin type-specific Descriptor
*/
static struct St_mysql_audit audit_null_descriptor=
{
Mysql_audit_interface_version,/* INTERFACE VERSION * *
NULL,/* RELEASE_THD function/*
Audit_null_notify,/* Notify function/*
{(unsigned long) Mysql_audit_general_classmask}/* Class Mask * *
};
/*
Plugin status variables for show status
*/
static struct St_mysql_show_var simple_status[]=
{
{"Audit_null_called", (char *) &number_of_calls, show_int},
{"Audit_null_general_log", (char *) &number_of_calls_general_log, show_int},
{"Audit_null_general_error", (char *) &number_of_calls_general_error,
Show_int},
{"Audit_null_general_result", (char *) &number_of_calls_general_result,
Show_int},
{0, 0, 0}
};
/*
Plugin Library Descriptor
*/
Mysql_declare_plugin (Audit_null)
{
Mysql_audit_plugin,/* Type * *
&audit_null_descriptor, * Descriptor * *
"Null_audit",/* Name * *
Oracle Corp., * Author * *
"Simple NULL Audit",/* Description * *
PLUGIN_LICENSE_GPL,
Audit_null_plugin_init,/* init function (when loaded) * *
Audit_null_plugin_deinit,/* Deinit function (when unloaded) * *
0X0002,/* version *
Simple_status,/* Status variables * *
NULL,/* System Variables * *
Null
0,
}
Mysql_declare_plugin_end;
Work path
[Root@os3 audit_null]# pwd
/tools/mysql-5.5.31patch/plugin/audit_null
Compiling statements
Gcc-g-wall-i/usr/local/mysql/include-dmysql_dynamic_plugin-c-fpic-o AUDIT_NULL.O audit_null.c
Gcc-shared-fpic-o adt_null.so AUDIT_NULL.O
Mv-f adt_null.so/usr/local/mysql/lib/plugin/
mysql> Install plugin null_audit soname ' adt_null.so '; Loading Plug-ins
mysql> Uninstall plugin Null_audit; Download Plugin
Audit file path Audit User Audit IP These need to add global variables, temporarily unresolved, welcome to correct.