{
char *js_s = NULL;
-#ifdef HAVE_LIBHIREDIS
- if (file_ctx->type == LOGFILE_TYPE_REDIS) {
+ if (file_ctx->sensor_name) {
json_object_set_new(js, "host",
- json_string(file_ctx->redis_setup.sensor_name));
+ json_string(file_ctx->sensor_name));
}
-#endif
js_s = json_dumps(js,
JSON_PRESERVE_ORDER|JSON_COMPACT|JSON_ENSURE_ASCII|
OutputCtx *OutputJsonInitCtx(ConfNode *conf)
{
OutputJsonCtx *json_ctx = SCCalloc(1, sizeof(OutputJsonCtx));;
+
+ const char *sensor_name = ConfNodeLookupChildValue(conf, "sensor-name");
+
if (unlikely(json_ctx == NULL)) {
SCLogDebug("AlertJsonInitCtx: Could not create new LogFileCtx");
return NULL;
return NULL;
}
+ if (sensor_name) {
+ json_ctx->file_ctx->sensor_name = SCStrdup(sensor_name);
+ if (json_ctx->file_ctx->sensor_name == NULL) {
+ LogFileFreeCtx(json_ctx->file_ctx);
+ SCFree(json_ctx);
+ return NULL;
+ }
+ } else {
+ json_ctx->file_ctx->sensor_name = NULL;
+ }
+
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) {
LogFileFreeCtx(json_ctx->file_ctx);
#ifdef HAVE_LIBHIREDIS
else if (json_ctx->json_out == LOGFILE_TYPE_REDIS) {
ConfNode *redis_node = ConfNodeLookupChild(conf, "redis");
- const char *sensor_name = ConfNodeLookupChildValue(conf, "sensor-name");
- if (!sensor_name) {
+ if (!json_ctx->file_ctx->sensor_name) {
char hostname[1024];
gethostname(hostname, 1023);
- sensor_name = hostname;
+ json_ctx->file_ctx->sensor_name = SCStrdup(hostname);
}
- json_ctx->file_ctx->redis_setup.sensor_name = SCStrdup(sensor_name);
- if (json_ctx->file_ctx->redis_setup.sensor_name == NULL) {
+ if (json_ctx->file_ctx->sensor_name == NULL) {
LogFileFreeCtx(json_ctx->file_ctx);
SCFree(json_ctx);
SCFree(output_ctx);
SCFree(lf_ctx->redis_setup.command);
if (lf_ctx->redis_setup.key)
SCFree(lf_ctx->redis_setup.key);
- if (lf_ctx->redis_setup.sensor_name)
- SCFree(lf_ctx->redis_setup.sensor_name);
}
#endif
if(lf_ctx->filename != NULL)
SCFree(lf_ctx->filename);
+ if (lf_ctx->sensor_name)
+ SCFree(lf_ctx->sensor_name);
+
OutputUnregisterFileRotationFlag(&lf_ctx->rotation_flag);
SCFree(lf_ctx);