提交 97b8f485 编写于 作者: D dmchen

add sql

上级 9f9aad0c
......@@ -769,6 +769,8 @@ typedef struct {
char* pAst2;
int64_t deleteMark1;
int64_t deleteMark2;
int32_t sqlLen;
char* sql;
} SMCreateStbReq;
int32_t tSerializeSMCreateStbReq(void* buf, int32_t bufLen, SMCreateStbReq* pReq);
......@@ -789,6 +791,8 @@ typedef struct {
int8_t source; // 1-taosX or 0-taosClient
int8_t reserved[6];
tb_uid_t suid;
int32_t sqlLen;
char* sql;
} SMDropStbReq;
int32_t tSerializeSMDropStbReq(void* buf, int32_t bufLen, SMDropStbReq* pReq);
......@@ -802,6 +806,8 @@ typedef struct {
int32_t ttl;
int32_t commentLen;
char* comment;
int32_t sqlLen;
char* sql;
} SMAlterStbReq;
int32_t tSerializeSMAlterStbReq(void* buf, int32_t bufLen, SMAlterStbReq* pReq);
......@@ -871,6 +877,8 @@ int32_t tDeserializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pR
typedef struct {
char user[TSDB_USER_LEN];
int32_t sqlLen;
char *sql;
} SDropUserReq, SDropAcctReq;
int32_t tSerializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq);
......@@ -883,6 +891,8 @@ typedef struct {
int8_t enable;
char user[TSDB_USER_LEN];
char pass[TSDB_USET_PASSWORD_LEN];
int32_t sqlLen;
char* sql;
} SCreateUserReq;
int32_t tSerializeSCreateUserReq(void* buf, int32_t bufLen, SCreateUserReq* pReq);
......@@ -899,6 +909,8 @@ typedef struct {
char tabName[TSDB_TABLE_NAME_LEN];
char* tagCond;
int32_t tagCondLen;
int32_t sqlLen;
char* sql;
} SAlterUserReq;
int32_t tSerializeSAlterUserReq(void* buf, int32_t bufLen, SAlterUserReq* pReq);
......@@ -1061,6 +1073,8 @@ typedef struct {
int16_t hashPrefix;
int16_t hashSuffix;
int32_t tsdbPageSize;
int32_t sqlLen;
char* sql;
} SCreateDbReq;
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
......@@ -1086,6 +1100,8 @@ typedef struct {
int32_t minRows;
int32_t walRetentionPeriod;
int32_t walRetentionSize;
int32_t sqlLen;
char* sql;
} SAlterDbReq;
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
......@@ -1094,6 +1110,8 @@ int32_t tDeserializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);
typedef struct {
char db[TSDB_DB_FNAME_LEN];
int8_t ignoreNotExists;
int32_t sqlLen;
char* sql;
} SDropDbReq;
int32_t tSerializeSDropDbReq(void* buf, int32_t bufLen, SDropDbReq* pReq);
......@@ -1850,6 +1868,8 @@ void tFreeSExplainRsp(SExplainRsp* pRsp);
typedef struct {
char fqdn[TSDB_FQDN_LEN]; // end point, hostname:port
int32_t port;
int32_t sqlLen;
char* sql;
} SCreateDnodeReq;
int32_t tSerializeSCreateDnodeReq(void* buf, int32_t bufLen, SCreateDnodeReq* pReq);
......@@ -1861,6 +1881,8 @@ typedef struct {
int32_t port;
int8_t force;
int8_t unsafe;
int32_t sqlLen;
char* sql;
} SDropDnodeReq;
int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq);
......@@ -1885,6 +1907,8 @@ typedef struct {
int32_t dnodeId;
char config[TSDB_DNODE_CONFIG_LEN];
char value[TSDB_DNODE_VALUE_LEN];
int32_t sqlLen;
char* sql;
} SMCfgDnodeReq;
int32_t tSerializeSMCfgDnodeReq(void* buf, int32_t bufLen, SMCfgDnodeReq* pReq);
......@@ -1900,6 +1924,8 @@ int32_t tDeserializeSDCfgDnodeReq(void* buf, int32_t bufLen, SDCfgDnodeReq* pReq
typedef struct {
int32_t dnodeId;
int32_t sqlLen;
char *sql;
} SMCreateMnodeReq, SMDropMnodeReq, SDDropMnodeReq, SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq,
SMCreateSnodeReq, SMDropSnodeReq, SDCreateSnodeReq, SDDropSnodeReq;
......@@ -2208,6 +2234,7 @@ typedef struct {
int64_t deleteMark;
int8_t igUpdate;
int64_t lastTs;
int32_t sqlLen;
} SCMCreateStreamReq;
typedef struct {
......@@ -2244,6 +2271,7 @@ typedef struct {
char subDbName[TSDB_DB_FNAME_LEN];
char* ast;
char subStbName[TSDB_TABLE_FNAME_LEN];
int32_t sqlLen;
} SCMCreateTopicReq;
int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq);
......@@ -2428,6 +2456,8 @@ typedef struct {
typedef struct {
char name[TSDB_TOPIC_FNAME_LEN];
int8_t igNotExists;
int32_t sqlLen;
char* sql;
} SMDropTopicReq;
int32_t tSerializeSMDropTopicReq(void* buf, int32_t bufLen, SMDropTopicReq* pReq);
......@@ -3006,6 +3036,8 @@ typedef struct {
typedef struct {
char name[TSDB_STREAM_FNAME_LEN];
int8_t igNotExists;
int32_t sqlLen;
char* sql;
} SMDropStreamReq;
typedef struct {
......
......@@ -31,13 +31,12 @@ extern "C" {
typedef struct {
const char *server;
uint16_t port;
int32_t maxLogs;
bool comp;
} SAuditCfg;
int32_t auditInit(const SAuditCfg *pCfg);
void auditSend(SJson *pJson);
void auditRecord(SRpcMsg *pReq, char *oper, char *db, char *stable, char *detail);
void auditRecord(SRpcMsg *pReq, char *oper, char *db, char *stable, int32_t detailLen, char *detail);
#ifdef __cplusplus
}
......
......@@ -37,8 +37,9 @@
#define DM_INIT_AUDIT() \
do { \
auditCfg.port = tsAuditPort; \
auditCfg.server = tsAuditFqdn; \
auditCfg.port = tsMonitorPort; \
auditCfg.server = tsMonitorFqdn; \
auditCfg.comp = tsMonitorComp; \
if (auditInit(&auditCfg) != 0) { \
return -1; \
} \
......
......@@ -736,13 +736,7 @@ static int32_t mndProcessCreateDbReq(SRpcMsg *pReq) {
code = mndCreateDb(pMnode, pReq, &createReq, pUser);
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
char detail[1000] = {0};
sprintf(detail, "dbname:%s, buffer:%d, cacheLast:%d, cacheLastSize:%d, compression:%d, "
"daysPerFile:%d, daysToKeep0:%d, daysToKeep1:%d, daysToKeep2:%d",
createReq.db, createReq.buffer, createReq.cacheLast, createReq.cacheLastSize, createReq.compression,
createReq.daysPerFile, createReq.daysToKeep0, createReq.daysToKeep1, createReq.daysToKeep2);
auditRecord(pReq, "createDB", createReq.db, "", detail);
auditRecord(pReq, "createDB", createReq.db, "", createReq.sqlLen, createReq.sql);
_OVER:
if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
......@@ -986,13 +980,7 @@ static int32_t mndProcessAlterDbReq(SRpcMsg *pReq) {
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
}
char detail[1000] = {0};
sprintf(detail, "dbname:%s, buffer:%d, cacheLast:%d, cacheLastSize:%d, "
"daysPerFile:%d, daysToKeep0:%d, daysToKeep1:%d, daysToKeep2:%d",
alterReq.db, alterReq.buffer, alterReq.cacheLast, alterReq.cacheLastSize,
alterReq.daysPerFile, alterReq.daysToKeep0, alterReq.daysToKeep1, alterReq.daysToKeep2);
auditRecord(pReq, "alterDB", alterReq.db, "", detail);
auditRecord(pReq, "alterDB", alterReq.db, "", alterReq.sqlLen, alterReq.sql);
_OVER:
if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
......@@ -1283,10 +1271,7 @@ static int32_t mndProcessDropDbReq(SRpcMsg *pReq) {
code = TSDB_CODE_ACTION_IN_PROGRESS;
}
char detail[1000] = {0};
sprintf(detail, "dbname:%s, ignoreNotExists:%d", dropReq.db, dropReq.ignoreNotExists);
auditRecord(pReq, "dropDB", dropReq.db, "", detail);
auditRecord(pReq, "dropDB", dropReq.db, "", dropReq.sqlLen, dropReq.sql);
_OVER:
if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) {
......
......@@ -913,7 +913,7 @@ static int32_t mndProcessCreateDnodeReq(SRpcMsg *pReq) {
sprintf(detail, "%s:%d",
createReq.fqdn, createReq.port);
auditRecord(pReq, "createDnode", detail, "", "");
auditRecord(pReq, "createDnode", detail, "", createReq.sqlLen, createReq.sql);
_OVER:
if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
......@@ -1062,18 +1062,13 @@ static int32_t mndProcessDropDnodeReq(SRpcMsg *pReq) {
code = mndDropDnode(pMnode, pReq, pDnode, pMObj, pQObj, pSObj, numOfVnodes, force, dropReq.unsafe);
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
char detail[1000] = {0};
char obj1[150] = {0};
sprintf(obj1, "%s:%d", dropReq.fqdn, dropReq.port);
char obj2[10] = {0};
sprintf(obj2, "%d", dropReq.dnodeId);
sprintf(detail, "dnodeId:%d, force:%d, unsafe:%d",
dropReq.dnodeId, dropReq.force, dropReq.unsafe);
auditRecord(pReq, "dropDnode", obj1, obj2, detail);
auditRecord(pReq, "dropDnode", obj1, obj2, dropReq.sqlLen, dropReq.sql);
_OVER:
if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
......@@ -1208,6 +1203,11 @@ static int32_t mndProcessConfigDnodeReq(SRpcMsg *pReq) {
}
}
char detail[50] = {0};
sprintf(detail, "%d", cfgReq.dnodeId);
auditRecord(pReq, "alterDnode", detail, "", cfgReq.sqlLen, cfgReq.sql);
int32_t code = -1;
SSdb *pSdb = pMnode->pSdb;
void *pIter = NULL;
......
......@@ -660,7 +660,7 @@ static int32_t mndProcessCreateMnodeReq(SRpcMsg *pReq) {
sprintf(detail, "dnodeId:%d", createReq.dnodeId);
auditRecord(pReq, "createMnode", obj, detail, "");
auditRecord(pReq, "createMnode", obj, detail, createReq.sqlLen, createReq.sql);
_OVER:
if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
......@@ -798,14 +798,10 @@ static int32_t mndProcessDropMnodeReq(SRpcMsg *pReq) {
code = mndDropMnode(pMnode, pReq, pObj);
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
char detail[1000] = {0};
char obj[20] = {0};
sprintf(obj, "%d", dropReq.dnodeId);
sprintf(detail, "dnodeId:%d", dropReq.dnodeId);
auditRecord(pReq, "dropMnode", obj, detail, "");
auditRecord(pReq, "dropMnode", obj, "", dropReq.sqlLen, dropReq.sql);
_OVER:
if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
......
......@@ -317,7 +317,7 @@ _CONNECT:
sprintf(detail, "user:%s, from:%s, connType%d",
connReq.user, obj, connReq.connType);
auditRecord(pReq, "login", connReq.app, obj, detail);
auditRecord(pReq, "login", connReq.app, obj, strlen(detail), detail);
_OVER:
......
......@@ -20,6 +20,7 @@
#include "mndShow.h"
#include "mndTrans.h"
#include "mndUser.h"
#include "audit.h"
#define QNODE_VER_NUMBER 1
#define QNODE_RESERVE_SIZE 64
......@@ -306,6 +307,10 @@ static int32_t mndProcessCreateQnodeReq(SRpcMsg *pReq) {
code = mndCreateQnode(pMnode, pReq, pDnode, &createReq);
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
char obj[33] = {0};
sprintf(obj, "%d", createReq.dnodeId);
auditRecord(pReq, "createQnode", obj, "", createReq.sqlLen, createReq.sql);
_OVER:
if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
mError("qnode:%d, failed to create since %s", createReq.dnodeId, terrstr());
......@@ -415,6 +420,11 @@ static int32_t mndProcessDropQnodeReq(SRpcMsg *pReq) {
code = mndDropQnode(pMnode, pReq, pObj);
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
char obj[33] = {0};
sprintf(obj, "%d", dropReq.dnodeId);
auditRecord(pReq, "createQnode", obj, "", dropReq.sqlLen, dropReq.sql);
_OVER:
if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
mError("qnode:%d, failed to drop since %s", dropReq.dnodeId, terrstr());
......
......@@ -1134,11 +1134,7 @@ static int32_t mndProcessCreateStbReq(SRpcMsg *pReq) {
}
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
char detail[1000] = {0};
sprintf(detail, "dbname:%s, stable:%s, igExists:%d, ttl:%d",
pDb->name, createReq.name, createReq.igExists, createReq.ttl);
auditRecord(pReq, "createStb", pDb->name, createReq.name, detail);
auditRecord(pReq, "createStb", pDb->name, createReq.name, createReq.sqlLen, createReq.sql);
_OVER:
if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
......@@ -2208,11 +2204,7 @@ static int32_t mndProcessAlterStbReq(SRpcMsg *pReq) {
code = mndAlterStb(pMnode, pReq, &alterReq, pDb, pStb);
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
char detail[1000] = {0};
sprintf(detail, "dbname:%s, stable:%s, alterType:%d, ttl:%d",
pDb->name, alterReq.name, alterReq.alterType, alterReq.ttl);
auditRecord(pReq, "alterStb", pDb->name, alterReq.name, detail);
auditRecord(pReq, "alterStb", pDb->name, alterReq.name, alterReq.sqlLen, alterReq.sql);
_OVER:
if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
......@@ -2474,11 +2466,7 @@ static int32_t mndProcessDropStbReq(SRpcMsg *pReq) {
code = mndDropStb(pMnode, pReq, pDb, pStb);
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
char detail[1000] = {0};
sprintf(detail, "dbname:%s, stable:%s, igNotExists:%d",
pDb->name, dropReq.name, dropReq.igNotExists);
auditRecord(pReq, "dropStb", pDb->name, dropReq.name, detail);
auditRecord(pReq, "dropStb", pDb->name, dropReq.name, dropReq.sqlLen, dropReq.sql);
_OVER:
if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
......
......@@ -829,11 +829,7 @@ static int32_t mndProcessCreateStreamReq(SRpcMsg *pReq) {
code = TSDB_CODE_ACTION_IN_PROGRESS;
char detail[1000] = {0};
sprintf(detail, "name:%s, igExists:%d",
createStreamReq.name, createStreamReq.igExists);
auditRecord(pReq, "createStream", createStreamReq.name, "", detail);
auditRecord(pReq, "createStream", createStreamReq.name, "", createStreamReq.sqlLen, createStreamReq.sql);
_OVER:
if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
......@@ -1080,11 +1076,7 @@ static int32_t mndProcessDropStreamReq(SRpcMsg *pReq) {
return -1;
}
char detail[1000] = {0};
sprintf(detail, "name:%s, igNotExists:%d",
dropReq.name, dropReq.igNotExists);
auditRecord(pReq, "dropStream", dropReq.name, "", detail);
auditRecord(pReq, "dropStream", dropReq.name, "", dropReq.sqlLen, dropReq.sql);
sdbRelease(pMnode->pSdb, pStream);
mndTransDrop(pTrans);
......
......@@ -622,11 +622,8 @@ static int32_t mndProcessCreateTopicReq(SRpcMsg *pReq) {
code = TSDB_CODE_ACTION_IN_PROGRESS;
}
char detail[1000] = {0};
sprintf(detail, "subDbName:%s, subStbName:%s",
createTopicReq.subDbName, createTopicReq.subStbName);
auditRecord(pReq, "crateTopic", createTopicReq.name, createTopicReq.subDbName, detail);
auditRecord(pReq, "crateTopic", createTopicReq.name, createTopicReq.subDbName,
createTopicReq.sqlLen, createTopicReq.sql);
_OVER:
if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
......@@ -819,11 +816,7 @@ static int32_t mndProcessDropTopicReq(SRpcMsg *pReq) {
return -1;
}
char detail[1000] = {0};
sprintf(detail, "name:%s, igNotExists:%d",
dropReq.name, dropReq.igNotExists);
auditRecord(pReq, "dropTopic", dropReq.name, "", detail);
auditRecord(pReq, "dropTopic", dropReq.name, "", dropReq.sqlLen, dropReq.sql);
return TSDB_CODE_ACTION_IN_PROGRESS;
}
......
......@@ -656,11 +656,7 @@ static int32_t mndProcessCreateUserReq(SRpcMsg *pReq) {
code = mndCreateUser(pMnode, pOperUser->acct, &createReq, pReq);
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
char detail[1000] = {0};
sprintf(detail, "user:%s, createType:%d",
createReq.user, createReq.createType);
auditRecord(pReq, "createUser", createReq.user, "", detail);
auditRecord(pReq, "createUser", createReq.user, "", createReq.sqlLen, createReq.sql);
_OVER:
if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
......@@ -977,11 +973,26 @@ static int32_t mndProcessAlterUserReq(SRpcMsg *pReq) {
code = mndAlterUser(pMnode, pUser, &newUser, pReq);
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
char detail[1000] = {0};
sprintf(detail, "user:%s, objname:%s, alterType:%d",
alterReq.user, alterReq.objname, alterReq.alterType);
auditRecord(pReq, "alterUser", alterReq.user, alterReq.objname, detail);
if(alterReq.alterType == TSDB_ALTER_USER_PASSWD){
auditRecord(pReq, "changePassword", alterReq.user, alterReq.objname, 0, "");
}
else if(alterReq.alterType == TSDB_ALTER_USER_SUPERUSER ||
alterReq.alterType == TSDB_ALTER_USER_ENABLE ||
alterReq.alterType == TSDB_ALTER_USER_SYSINFO){
auditRecord(pReq, "alterUser", alterReq.user, alterReq.objname, alterReq.sqlLen, alterReq.sql);
}
else if(alterReq.alterType == TSDB_ALTER_USER_ADD_READ_DB||
alterReq.alterType == TSDB_ALTER_USER_ADD_WRITE_DB||
alterReq.alterType == TSDB_ALTER_USER_ADD_ALL_DB||
alterReq.alterType == TSDB_ALTER_USER_ADD_SUBSCRIBE_TOPIC||
alterReq.alterType == TSDB_ALTER_USER_ADD_READ_TABLE||
alterReq.alterType == TSDB_ALTER_USER_ADD_WRITE_TABLE||
alterReq.alterType == TSDB_ALTER_USER_ADD_ALL_TABLE){
auditRecord(pReq, "GrantPrivileges", alterReq.user, alterReq.objname, alterReq.sqlLen, alterReq.sql);
}
else{
auditRecord(pReq, "RevokePrivileges", alterReq.user, alterReq.objname, alterReq.sqlLen, alterReq.sql);
}
_OVER:
if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
......@@ -1052,7 +1063,7 @@ static int32_t mndProcessDropUserReq(SRpcMsg *pReq) {
code = mndDropUser(pMnode, pReq, pUser);
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
auditRecord(pReq, "dropUser", dropReq.user, "", "");
auditRecord(pReq, "dropUser", dropReq.user, "", dropReq.sqlLen, dropReq.sql);
_OVER:
if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
......
......@@ -860,7 +860,7 @@ static int32_t vnodeProcessCreateTbReq(SVnode *pVnode, int64_t ver, void *pReq,
taosArrayPush(rsp.pArray, &cRsp);
auditRecord(pReq, "createTable", pVnode->config.dbname, pCreateReq->name, "detail");
auditRecord(pReq, "createTable", pVnode->config.dbname, pCreateReq->name, pCreateReq->sqlLen, pCreateReq->sql);
}
vDebug("vgId:%d, add %d new created tables into query table list", TD_VID(pVnode), (int32_t)taosArrayGetSize(tbUids));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册