if (unlikely(js == NULL))
return TM_ECODE_OK;
- if (json_output_ctx->cfg.include_metadata) {
- JsonAddMetadata(p, p->flow, js);
- }
+ JsonAddCommonOptions(&json_output_ctx->cfg, p, p->flow, js);
for (i = 0; i < p->alerts.cnt; i++) {
const PacketAlert *pa = &p->alerts.alerts[i];
if (unlikely(js == NULL)) {
return TM_ECODE_OK;
}
- if (thread->dnp3log_ctx->cfg.include_metadata) {
- JsonAddMetadata(p, f, js);
- }
+
+ JsonAddCommonOptions(&thread->dnp3log_ctx->cfg, p, f, js);
+
json_t *dnp3js = JsonDNP3LogRequest(tx);
if (dnp3js != NULL) {
json_object_set_new(js, "dnp3", dnp3js);
if (unlikely(js == NULL)) {
return TM_ECODE_OK;
}
- if (thread->dnp3log_ctx->cfg.include_metadata) {
- JsonAddMetadata(p, f, js);
- }
+
+ JsonAddCommonOptions(&thread->dnp3log_ctx->cfg, p, f, js);
+
json_t *dnp3js = JsonDNP3LogResponse(tx);
if (dnp3js != NULL) {
json_object_set_new(js, "dnp3", dnp3js);
if (unlikely(js == NULL)) {
return TM_ECODE_OK;
}
- if (dnslog_ctx->cfg.include_metadata) {
- JsonAddMetadata(p, f, js);
- }
+ JsonAddCommonOptions(&dnslog_ctx->cfg, p, f, js);
+
json_t *dns = rs_dns_log_json_query(txptr, i, td->dnslog_ctx->flags);
if (unlikely(dns == NULL)) {
json_decref(js);
js = CreateJSONHeader(p, LOG_DIR_PACKET, "dns");
if (unlikely(js == NULL))
return TM_ECODE_OK;
- if (dnslog_ctx->include_metadata) {
- JsonAddMetadata(p, f, js);
- }
+
+ JsonAddCommonOptions(&dnslog_ctx->cfg, p, f, js);
LogQuery(td, js, tx, tx_id, query);
if (unlikely(js == NULL))
return TM_ECODE_OK;
- if (dnslog_ctx->cfg.include_metadata) {
- JsonAddMetadata(p, f, js);
- }
+ JsonAddCommonOptions(&dnslog_ctx->cfg, p, f, js);
#if HAVE_RUST
if (td->dnslog_ctx->version == DNS_VERSION_2) {
if (unlikely(js == NULL))
return TM_ECODE_OK;
- if (drop_ctx->cfg.include_metadata) {
- JsonAddMetadata(p, p->flow, js);
- }
+ JsonAddCommonOptions(&drop_ctx->cfg, p, p->flow, js);
json_t *djs = json_object();
if (unlikely(djs == NULL)) {
json_object_set_new(js, "flow", hjs);
- if (flow_ctx->cfg.include_metadata) {
- JsonAddMetadata(NULL, f, js);
- }
+ JsonAddCommonOptions(&flow_ctx->cfg, NULL, f, js);
/* TCP */
if (f->proto == IPPROTO_TCP) {
if (unlikely(js == NULL))
return TM_ECODE_OK;
- if (jhl->httplog_ctx->cfg.include_metadata) {
- JsonAddMetadata(p, f, js);
- }
+ JsonAddCommonOptions(&jhl->httplog_ctx->cfg, p, f, js);
SCLogDebug("got a HTTP request and now logging !!");
return TM_ECODE_FAILED;
}
- if (thread->ikev2log_ctx->cfg.include_metadata) {
- JsonAddMetadata(p, f, js);
- }
+ JsonAddCommonOptions(&thread->ikev2log_ctx->cfg, p, f, js);
ikev2js = rs_ikev2_log_json_response(state, ikev2tx);
if (unlikely(ikev2js == NULL)) {
return TM_ECODE_FAILED;
}
- if (thread->krb5log_ctx->cfg.include_metadata) {
- JsonAddMetadata(p, f, js);
- }
+ JsonAddCommonOptions(&thread->krb5log_ctx->cfg, p, f, js);
krb5js = rs_krb5_log_json_response(state, krb5tx);
if (unlikely(krb5js == NULL)) {
typedef struct MetadataJsonOutputCtx_ {
LogFileCtx* file_ctx;
+ OutputJsonCommonSettings cfg;
} MetadataJsonOutputCtx;
typedef struct JsonMetadataLogThread_ {
if (unlikely(js == NULL))
return TM_ECODE_OK;
- JsonAddMetadata(p, p->flow, js);
+ JsonAddCommonOptions(&aft->json_output_ctx->cfg, p, p->flow, js);
OutputJSONBuffer(js, aft->file_ctx, &aft->json_buffer);
json_object_del(js, "metadata");
json_object_clear(js);
memset(json_output_ctx, 0, sizeof(MetadataJsonOutputCtx));
json_output_ctx->file_ctx = logfile_ctx;
+ json_output_ctx->cfg.include_metadata = true;
output_ctx->data = json_output_ctx;
output_ctx->DeInit = JsonMetadataLogDeInitCtx;
memset(json_output_ctx, 0, sizeof(MetadataJsonOutputCtx));
json_output_ctx->file_ctx = ajt->file_ctx;
+ json_output_ctx->cfg = ajt->cfg;
+ /* override config setting as this logger is about metadata */
+ json_output_ctx->cfg.include_metadata = true;
output_ctx->data = json_output_ctx;
output_ctx->DeInit = JsonMetadataLogDeInitCtxSub;
if (unlikely(js == NULL))
return TM_ECODE_OK;
JsonNetFlowLogJSONToServer(jhl, js, f);
- if (netflow_ctx->cfg.include_metadata) {
- JsonAddMetadata(NULL, f, js);
- }
+ JsonAddCommonOptions(&netflow_ctx->cfg, NULL, f, js);
OutputJSONBuffer(js, jhl->flowlog_ctx->file_ctx, &jhl->buffer);
json_object_del(js, "netflow");
json_object_clear(js);
if (unlikely(js == NULL))
return TM_ECODE_OK;
JsonNetFlowLogJSONToClient(jhl, js, f);
- if (netflow_ctx->cfg.include_metadata) {
- JsonAddMetadata(NULL, f, js);
- }
+ JsonAddCommonOptions(&netflow_ctx->cfg, NULL, f, js);
OutputJSONBuffer(js, jhl->flowlog_ctx->file_ctx, &jhl->buffer);
json_object_del(js, "netflow");
json_object_clear(js);
return TM_ECODE_FAILED;
}
- if (thread->ctx->cfg.include_metadata) {
- JsonAddMetadata(p, f, js);
- }
+ JsonAddCommonOptions(&thread->ctx->cfg, p, f, js);
json_t *rpcjs = rs_rpc_log_json_response(tx);
if (unlikely(rpcjs == NULL)) {
/* reset */
MemBufferReset(jhl->buffer);
- if (jhl->emaillog_ctx->cfg.include_metadata) {
- JsonAddMetadata(p, f, js);
- }
+ JsonAddCommonOptions(&jhl->emaillog_ctx->cfg, p, f, js);
json_t *sjs = JsonSmtpDataLogger(f, state, tx, tx_id);
if (sjs) {
if (unlikely(js == NULL))
return 0;
- if (ssh_ctx->cfg.include_metadata) {
- JsonAddMetadata(p, f, js);
- }
+ JsonAddCommonOptions(&ssh_ctx->cfg, p, f, js);
json_t *tjs = json_object();
if (tjs == NULL) {
return 0;
}
- if (tls_ctx->cfg.include_metadata) {
- JsonAddMetadata(p, f, js);
- }
+ JsonAddCommonOptions(&tls_ctx->cfg, p, f, js);
json_t *tjs = json_object();
if (tjs == NULL) {
/**
* \brief Add top-level metadata to the eve json object.
*/
-void JsonAddMetadata(const Packet *p, const Flow *f, json_t *js)
+static void JsonAddMetadata(const Packet *p, const Flow *f, json_t *js)
{
if ((p && p->pktvar) || (f && f->flowvar)) {
json_t *js_vars = json_object();
}
}
+void JsonAddCommonOptions(const OutputJsonCommonSettings *cfg,
+ const Packet *p, const Flow *f, json_t *js)
+{
+ if (cfg->include_metadata) {
+ JsonAddMetadata(p, f, js);
+ }
+}
+
/** \brief jsonify tcp flags field
* Only add 'true' fields in an attempt to keep things reasonably compact.
*/
int OutputJSONMemBufferCallback(const char *str, size_t size, void *data);
-void JsonAddMetadata(const Packet *p, const Flow *f, json_t *js);
void CreateJSONFlowId(json_t *js, const Flow *f);
void JsonTcpFlags(uint8_t flags, json_t *js);
void JsonFiveTuple(const Packet *, enum OutputJsonLogDirection, json_t *);
json_t *SCJsonString(const char *val);
void SCJsonDecref(json_t *js);
+void JsonAddCommonOptions(const OutputJsonCommonSettings *cfg,
+ const Packet *p, const Flow *f, json_t *js);
+
#endif /* HAVE_LIBJANSSON */
#endif /* __OUTPUT_JSON_H__ */