Writes audit log in parallel mode

First version still missing the index among other things
This commit is contained in:
Felipe Zimmerle
2015-07-10 15:23:15 -03:00
parent 693238b235
commit c9620ac50f
13 changed files with 164 additions and 30 deletions

View File

@@ -15,9 +15,83 @@
#include "src/audit_log_writer_parallel.h"
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <fstream>
#include "src/audit_log.h"
#include "modsecurity/assay.h"
#include "src/utils.h"
namespace ModSecurity {
inline std::string AuditLogWriterParallel::logFilePath(time_t *t,
int part) {
struct tm timeinfo;
char tstr[300];
size_t len;
std::string name("");
localtime_r(t, &timeinfo);
if (part & YearMonthDayDirectory) {
memset(tstr, '\0', 300);
strftime(tstr, 299, "/%Y%m%d", &timeinfo);
name = tstr;
}
if (part & YearMonthDayAndTimeDirectory) {
memset(tstr, '\0', 300);
strftime(tstr, 299, "/%Y%m%d-%H%M", &timeinfo);
name = name + tstr;
}
if (part & YearMonthDayAndTimeFileName) {
memset(tstr, '\0', 300);
strftime(tstr, 299, "/%Y%m%d-%H%M%S", &timeinfo);
name = name + tstr;
}
return name;
}
bool AuditLogWriterParallel::init() {
/** TODO:: Check if the directory exists. */
/** TODO:: Checking if we have permission to write in the target dir */
return true;
}
bool AuditLogWriterParallel::close() {
return true;
}
bool AuditLogWriterParallel::write(Assay *assay) {
std::string log = assay->to_json(0);
std::string fileName = logFilePath(&assay->timeStamp,
YearMonthDayDirectory | YearMonthDayAndTimeDirectory
| YearMonthDayAndTimeFileName);
fileName = fileName + "-" + assay->id;
std::string logPath = m_audit->m_storage_dir;
createDir((logPath +
logFilePath(&assay->timeStamp, YearMonthDayDirectory)).c_str());
createDir((logPath +
logFilePath(&assay->timeStamp, YearMonthDayDirectory
| YearMonthDayAndTimeDirectory)).c_str());
std::ofstream f;
f.open(logPath + fileName, std::fstream::out | std::fstream::app);
f << log;
f.close();
return true;
}
} // namespace ModSecurity