|
|
|
@ -519,32 +519,18 @@ int LogFileFreeCtx(LogFileCtx *lf_ctx)
|
|
|
|
SCReturnInt(1);
|
|
|
|
SCReturnInt(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int LogFileWrite(LogFileCtx *file_ctx, MemBuffer *buffer, char *string, size_t string_len)
|
|
|
|
#ifdef HAVE_LIBHIREDIS
|
|
|
|
|
|
|
|
static int LogFileWriteRedis(LogFileCtx *file_ctx, char *string, size_t string_len)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
SCMutexLock(&file_ctx->fp_mutex);
|
|
|
|
|
|
|
|
if (file_ctx->type == LOGFILE_TYPE_SYSLOG) {
|
|
|
|
|
|
|
|
syslog(file_ctx->syslog_setup.alert_syslog_level, "%s", string);
|
|
|
|
|
|
|
|
} else if (file_ctx->type == LOGFILE_TYPE_FILE ||
|
|
|
|
|
|
|
|
file_ctx->type == LOGFILE_TYPE_UNIX_DGRAM ||
|
|
|
|
|
|
|
|
file_ctx->type == LOGFILE_TYPE_UNIX_STREAM)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
MemBufferWriteString(buffer, "%s\n", string);
|
|
|
|
|
|
|
|
file_ctx->Write((const char *)MEMBUFFER_BUFFER(buffer),
|
|
|
|
|
|
|
|
MEMBUFFER_OFFSET(buffer), file_ctx);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#if HAVE_LIBHIREDIS
|
|
|
|
|
|
|
|
else if (file_ctx->type == LOGFILE_TYPE_REDIS) {
|
|
|
|
|
|
|
|
if (file_ctx->redis == NULL) {
|
|
|
|
if (file_ctx->redis == NULL) {
|
|
|
|
/* FIXME temporisation */
|
|
|
|
|
|
|
|
SCConfLogReopenRedis(file_ctx);
|
|
|
|
SCConfLogReopenRedis(file_ctx);
|
|
|
|
if (file_ctx->redis == NULL) {
|
|
|
|
if (file_ctx->redis == NULL) {
|
|
|
|
SCMutexUnlock(&file_ctx->fp_mutex);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
SCLogInfo("Reconnected to redis server");
|
|
|
|
SCLogInfo("Reconnected to redis server");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* FIXME go async here ? */
|
|
|
|
/* TODO go async here ? */
|
|
|
|
if (file_ctx->redis_setup.batch_size) {
|
|
|
|
if (file_ctx->redis_setup.batch_size) {
|
|
|
|
redisAppendCommand(file_ctx->redis, "%s %s %s",
|
|
|
|
redisAppendCommand(file_ctx->redis, "%s %s %s",
|
|
|
|
file_ctx->redis_setup.command,
|
|
|
|
file_ctx->redis_setup.command,
|
|
|
|
@ -553,11 +539,10 @@ int LogFileWrite(LogFileCtx *file_ctx, MemBuffer *buffer, char *string, size_t s
|
|
|
|
if (SC_ATOMIC_CAS(&file_ctx->redis_setup.batch_count, file_ctx->redis_setup.batch_size, 0)) {
|
|
|
|
if (SC_ATOMIC_CAS(&file_ctx->redis_setup.batch_count, file_ctx->redis_setup.batch_size, 0)) {
|
|
|
|
redisReply *reply;
|
|
|
|
redisReply *reply;
|
|
|
|
int i;
|
|
|
|
int i;
|
|
|
|
for(i = 0; i <= file_ctx->redis_setup.batch_size; i++) {
|
|
|
|
for (i = 0; i <= file_ctx->redis_setup.batch_size; i++) {
|
|
|
|
if (redisGetReply(file_ctx->redis, (void **)&reply) == REDIS_OK) {
|
|
|
|
if (redisGetReply(file_ctx->redis, (void **)&reply) == REDIS_OK) {
|
|
|
|
freeReplyObject(reply);
|
|
|
|
freeReplyObject(reply);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
/* FIXME treat error */
|
|
|
|
|
|
|
|
if (file_ctx->redis->err) {
|
|
|
|
if (file_ctx->redis->err) {
|
|
|
|
SCLogInfo("Error when fetching reply: %s (%d)",
|
|
|
|
SCLogInfo("Error when fetching reply: %s (%d)",
|
|
|
|
file_ctx->redis->errstr,
|
|
|
|
file_ctx->redis->errstr,
|
|
|
|
@ -570,17 +555,17 @@ int LogFileWrite(LogFileCtx *file_ctx, MemBuffer *buffer, char *string, size_t s
|
|
|
|
SCConfLogReopenRedis(file_ctx);
|
|
|
|
SCConfLogReopenRedis(file_ctx);
|
|
|
|
if (file_ctx->redis) {
|
|
|
|
if (file_ctx->redis) {
|
|
|
|
SCLogInfo("Reconnected to redis server");
|
|
|
|
SCLogInfo("Reconnected to redis server");
|
|
|
|
SCMutexUnlock(&file_ctx->fp_mutex);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
SCLogInfo("Unable to reconnect to redis server");
|
|
|
|
SCLogInfo("Unable to reconnect to redis server");
|
|
|
|
SCMutexUnlock(&file_ctx->fp_mutex);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
SCLogInfo("Unsupported error code %d",
|
|
|
|
SCLogWarning(SC_ERR_INVALID_VALUE,
|
|
|
|
|
|
|
|
"Unsupported error code %d",
|
|
|
|
file_ctx->redis->err);
|
|
|
|
file_ctx->redis->err);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -595,7 +580,7 @@ int LogFileWrite(LogFileCtx *file_ctx, MemBuffer *buffer, char *string, size_t s
|
|
|
|
|
|
|
|
|
|
|
|
switch (reply->type) {
|
|
|
|
switch (reply->type) {
|
|
|
|
case REDIS_REPLY_ERROR:
|
|
|
|
case REDIS_REPLY_ERROR:
|
|
|
|
SCLogWarning(SC_WARN_NO_UNITTESTS, "Redis error: %s", reply->str);
|
|
|
|
SCLogWarning(SC_ERR_SOCKET, "Redis error: %s", reply->str);
|
|
|
|
SCConfLogReopenRedis(file_ctx);
|
|
|
|
SCConfLogReopenRedis(file_ctx);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case REDIS_REPLY_INTEGER:
|
|
|
|
case REDIS_REPLY_INTEGER:
|
|
|
|
@ -609,6 +594,26 @@ int LogFileWrite(LogFileCtx *file_ctx, MemBuffer *buffer, char *string, size_t s
|
|
|
|
}
|
|
|
|
}
|
|
|
|
freeReplyObject(reply);
|
|
|
|
freeReplyObject(reply);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int LogFileWrite(LogFileCtx *file_ctx, MemBuffer *buffer, char *string, size_t string_len)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
SCMutexLock(&file_ctx->fp_mutex);
|
|
|
|
|
|
|
|
if (file_ctx->type == LOGFILE_TYPE_SYSLOG) {
|
|
|
|
|
|
|
|
syslog(file_ctx->syslog_setup.alert_syslog_level, "%s", string);
|
|
|
|
|
|
|
|
} else if (file_ctx->type == LOGFILE_TYPE_FILE ||
|
|
|
|
|
|
|
|
file_ctx->type == LOGFILE_TYPE_UNIX_DGRAM ||
|
|
|
|
|
|
|
|
file_ctx->type == LOGFILE_TYPE_UNIX_STREAM)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
MemBufferWriteString(buffer, "%s\n", string);
|
|
|
|
|
|
|
|
file_ctx->Write((const char *)MEMBUFFER_BUFFER(buffer),
|
|
|
|
|
|
|
|
MEMBUFFER_OFFSET(buffer), file_ctx);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_LIBHIREDIS
|
|
|
|
|
|
|
|
else if (file_ctx->type == LOGFILE_TYPE_REDIS) {
|
|
|
|
|
|
|
|
LogFileWriteRedis(file_ctx, string, string_len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
SCMutexUnlock(&file_ctx->fp_mutex);
|
|
|
|
SCMutexUnlock(&file_ctx->fp_mutex);
|
|
|
|
|