From: Mats Klepsland Date: Thu, 19 Jan 2017 06:15:00 +0000 (+0100) Subject: output-json: make JSON flags in eve-log user configurable X-Git-Tag: suricata-4.0.0-beta1~303 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=65317ba865bc498ca01c8a146d89b4504c75663d;p=thirdparty%2Fsuricata.git output-json: make JSON flags in eve-log user configurable --- diff --git a/src/output-json.c b/src/output-json.c index 95f9b0167d..7b655f64ca 100644 --- a/src/output-json.c +++ b/src/output-json.c @@ -481,8 +481,7 @@ int OutputJSONBuffer(json_t *js, LogFileCtx *file_ctx, MemBuffer **buffer) }; int r = json_dump_callback(js, OutputJSONMemBufferCallback, &wrapper, - JSON_PRESERVE_ORDER|JSON_COMPACT|JSON_ENSURE_ASCII| - JSON_ESCAPE_SLASH); + file_ctx->json_flags); if (r != 0) return TM_ECODE_OK; diff --git a/src/util-logopenfile.c b/src/util-logopenfile.c index 636aaab83f..da644f7912 100644 --- a/src/util-logopenfile.c +++ b/src/util-logopenfile.c @@ -256,6 +256,35 @@ SCConfLogOpenGeneric(ConfNode *conf, if (append == NULL) append = DEFAULT_LOG_MODE_APPEND; + /* JSON flags */ +#ifdef HAVE_LIBJANSSON + log_ctx->json_flags = JSON_PRESERVE_ORDER|JSON_COMPACT| + JSON_ENSURE_ASCII|JSON_ESCAPE_SLASH; + + ConfNode *json_flags = ConfNodeLookupChild(conf, "json"); + + if (json_flags != 0) { + const char *preserve_order = ConfNodeLookupChildValue(json_flags, + "preserve-order"); + if (preserve_order != NULL && ConfValIsFalse(preserve_order)) + log_ctx->json_flags &= ~(JSON_PRESERVE_ORDER); + + const char *compact = ConfNodeLookupChildValue(json_flags, "compact"); + if (compact != NULL && ConfValIsFalse(compact)) + log_ctx->json_flags &= ~(JSON_COMPACT); + + const char *ensure_ascii = ConfNodeLookupChildValue(json_flags, + "ensure-ascii"); + if (ensure_ascii != NULL && ConfValIsFalse(ensure_ascii)) + log_ctx->json_flags &= ~(JSON_ENSURE_ASCII); + + const char *escape_slash = ConfNodeLookupChildValue(json_flags, + "escape-slash"); + if (escape_slash != NULL && ConfValIsFalse(escape_slash)) + log_ctx->json_flags &= ~(JSON_ESCAPE_SLASH); + } +#endif /* HAVE_LIBJANSSON */ + // Now, what have we been asked to open? if (strcasecmp(filetype, "unix_stream") == 0) { /* Don't bail. May be able to connect later. */ diff --git a/src/util-logopenfile.h b/src/util-logopenfile.h index cccbba47d0..063e2bfb74 100644 --- a/src/util-logopenfile.h +++ b/src/util-logopenfile.h @@ -118,6 +118,9 @@ typedef struct LogFileCtx_ { * allow for rotataion. */ uint8_t is_regular; + /* JSON flags */ + size_t json_flags; /* passed to json_dump_callback() */ + /* Flag set when file rotation notification is received. */ int rotation_flag; } LogFileCtx;