diff --git a/source/libs/audit/CMakeLists.txt b/source/libs/audit/CMakeLists.txt index 8d561bb98eb47c334fe06f5a50a3a992b5c34648..22ec05220e8992620ee7c39aff5346227daeb6bf 100644 --- a/source/libs/audit/CMakeLists.txt +++ b/source/libs/audit/CMakeLists.txt @@ -1,4 +1,8 @@ aux_source_directory(src AUDIT_SRC) +IF (TD_ENTERPRISE) + LIST(APPEND AUDIT_SRC ${TD_ENTERPRISE_DIR}/src/plugins/audit/src/audit.c) +ENDIF () + add_library(audit STATIC ${AUDIT_SRC}) target_include_directories( audit diff --git a/source/libs/audit/src/auditMain.c b/source/libs/audit/src/auditMain.c index 976bab7626a70595c69ad7cc4eedebf0487381d2..1f92cebc9816c62d4306b0432784de567a158f16 100644 --- a/source/libs/audit/src/auditMain.c +++ b/source/libs/audit/src/auditMain.c @@ -21,46 +21,22 @@ #include "tjson.h" #include "tglobal.h" -static SAudit tsAudit = {0}; -static char* tsAuditUri = "/audit"; +SAudit tsAudit = {0}; +char* tsAuditUri = "/audit"; int32_t auditInit(const SAuditCfg *pCfg) { tsAudit.cfg = *pCfg; return 0; } -void auditRecord(SRpcMsg *pReq, char *oper, char *db, char *stable, char *detail) { - char *user = pReq->info.conn.user; - - if (!tsEnableAudit || tsAuditFqdn[0] == 0 || tsAuditPort == 0) return; - SJson *pJson = tjsonCreateObject(); - if (pJson == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return; - } - - char buf[40] = {0}; - int64_t curTime = taosGetTimestampMs(); - taosFormatUtcTime(buf, sizeof(buf), curTime, TSDB_TIME_PRECISION_MILLI); +extern void auditRecordImp(SRpcMsg *pReq, char *oper, char *db, char *stable, char *detail); - tjsonAddStringToObject(pJson, "ts", buf); - tjsonAddStringToObject(pJson, "user", user); - tjsonAddStringToObject(pJson, "operation", oper); - tjsonAddStringToObject(pJson, "target1", db); - tjsonAddStringToObject(pJson, "target2", stable); - tjsonAddStringToObject(pJson, "detail", detail); - - auditSend(pJson); +void auditRecord(SRpcMsg *pReq, char *oper, char *db, char *stable, char *detail) { + auditRecordImp(pReq, oper, db, stable, detail); } -void auditSend(SJson *pJson) { - char *pCont = tjsonToString(pJson); - uDebug("audit record cont:%s\n", pCont); - if (pCont != NULL) { - EHttpCompFlag flag = tsAudit.cfg.comp ? HTTP_GZIP : HTTP_FLAT; - if (taosSendHttpReport(tsAudit.cfg.server, tsAuditUri, tsAudit.cfg.port, pCont, strlen(pCont), flag) != 0) { - uError("failed to send audit msg"); - } - taosMemoryFree(pCont); - } +#ifndef TD_ENTERPRISE +void auditRecordImp(SRpcMsg *pReq, char *oper, char *db, char *stable, char *detail) { } +#endif +