@ -339,12 +339,10 @@ int OutputJSONBuffer(json_t *js, LogFileCtx *file_ctx, MemBuffer *buffer)
{
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 |
@ -416,6 +414,9 @@ void OutputJsonExitPrintStats(ThreadVars *tv, void *data)
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 ;
@ -428,6 +429,17 @@ OutputCtx *OutputJsonInitCtx(ConfNode *conf)
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 ) ;
@ -539,14 +551,12 @@ OutputCtx *OutputJsonInitCtx(ConfNode *conf)
# 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 ) ;