anomaly/eve: convert to jsonbuilder

pull/5012/head
Jason Ish 5 years ago committed by Victor Julien
parent 037c449b85
commit 7803a9ac40

@ -105,44 +105,39 @@ static int AnomalyDecodeEventJson(ThreadVars *tv, JsonAnomalyLogThread *aft,
MemBufferReset(aft->json_buffer); MemBufferReset(aft->json_buffer);
json_t *js = CreateJSONHeader(p, LOG_DIR_PACKET, ANOMALY_EVENT_TYPE, NULL); JsonBuilder *js = CreateEveHeader(p, LOG_DIR_PACKET, ANOMALY_EVENT_TYPE, NULL);
if (unlikely(js == NULL)) { if (unlikely(js == NULL)) {
return TM_ECODE_OK; return TM_ECODE_OK;
} }
json_t *ajs = json_object(); jb_open_object(js, ANOMALY_EVENT_TYPE);
if (unlikely(ajs == NULL)) {
json_decref(js);
return TM_ECODE_OK;
}
if (!is_ip_pkt) { if (!is_ip_pkt) {
json_object_set_new(js, "timestamp", json_string(timebuf)); jb_set_string(js, "timestamp", timebuf);
} else { } else {
JsonAddCommonOptions(&aft->json_output_ctx->cfg, p, p->flow, js); EveAddCommonOptions(&aft->json_output_ctx->cfg, p, p->flow, js);
}
if (aft->json_output_ctx->flags & LOG_JSON_PACKETHDR) {
JsonPacket(p, js, GET_PKT_LEN(p) < 32 ? GET_PKT_LEN(p) : 32);
} }
if (event_code < DECODE_EVENT_MAX) { if (event_code < DECODE_EVENT_MAX) {
const char *event = DEvents[event_code].event_name; const char *event = DEvents[event_code].event_name;
json_object_set_new(ajs, "type", jb_set_string(js, "type",
EVENT_IS_DECODER_PACKET_ERROR(event_code) ? EVENT_IS_DECODER_PACKET_ERROR(event_code) ?
json_string("decode") : json_string("stream")); "decode" : "stream");
json_object_set_new(ajs, "event", json_string(event)); jb_set_string(js, "event", event);
} else { } else {
json_object_set_new(ajs, "type", json_string("unknown")); jb_set_string(js, "type", "unknown");
json_object_set_new(ajs, "code", json_integer(event_code)); jb_set_uint(js, "code", event_code);
} }
/* anomaly */ /* Close anomaly object. */
json_object_set_new(js, ANOMALY_EVENT_TYPE, ajs); jb_close(js);
OutputJSONBuffer(js, aft->file_ctx, &aft->json_buffer);
json_object_clear(js); if (aft->json_output_ctx->flags & LOG_JSON_PACKETHDR) {
json_decref(js); EvePacket(p, js, GET_PKT_LEN(p) < 32 ? GET_PKT_LEN(p) : 32);
}
OutputJsonBuilderBuffer(js, aft->file_ctx, &aft->json_buffer);
jb_free(js);
} }
return TM_ECODE_OK; return TM_ECODE_OK;
@ -162,26 +157,22 @@ static int AnomalyAppLayerDecoderEventJson(JsonAnomalyLogThread *aft,
for (int i = decoder_events->event_last_logged; i < decoder_events->cnt; i++) { for (int i = decoder_events->event_last_logged; i < decoder_events->cnt; i++) {
MemBufferReset(aft->json_buffer); MemBufferReset(aft->json_buffer);
json_t *js; JsonBuilder *js;
if (tx_id != TX_ID_UNUSED) { if (tx_id != TX_ID_UNUSED) {
js = CreateJSONHeaderWithTxId(p, LOG_DIR_PACKET, js = CreateEveHeaderWithTxId(p, LOG_DIR_PACKET,
ANOMALY_EVENT_TYPE, tx_id); ANOMALY_EVENT_TYPE, NULL, tx_id);
} else { } else {
js = CreateJSONHeader(p, LOG_DIR_PACKET, ANOMALY_EVENT_TYPE, NULL); js = CreateEveHeader(p, LOG_DIR_PACKET, ANOMALY_EVENT_TYPE, NULL);
} }
if (unlikely(js == NULL)) { if (unlikely(js == NULL)) {
return TM_ECODE_OK; return TM_ECODE_OK;
} }
json_t *ajs = json_object(); EveAddCommonOptions(&aft->json_output_ctx->cfg, p, p->flow, js);
if (unlikely(ajs == NULL)) {
json_decref(js);
return TM_ECODE_OK;
}
JsonAddCommonOptions(&aft->json_output_ctx->cfg, p, p->flow, js); jb_open_object(js, ANOMALY_EVENT_TYPE);
json_object_set_new(js, "app_proto", json_string(alprotoname)); jb_set_string(js, "app_proto", alprotoname);
const char *event_name = NULL; const char *event_name = NULL;
uint8_t event_code = decoder_events->events[i]; uint8_t event_code = decoder_events->events[i];
@ -194,21 +185,19 @@ static int AnomalyAppLayerDecoderEventJson(JsonAnomalyLogThread *aft,
event_code, &event_name, &event_type); event_code, &event_name, &event_type);
} }
if (r == 0) { if (r == 0) {
json_object_set_new(ajs, "type", json_string("applayer")); jb_set_string(js, "type", "applayer");
json_object_set_new(ajs, "event", json_string(event_name)); jb_set_string(js, "event", event_name);
} else { } else {
json_object_set_new(ajs, "type", json_string("unknown")); jb_set_string(js, "type", "unknown");
json_object_set_new(ajs, "code", json_integer(event_code)); jb_set_uint(js, "code", event_code);
} }
json_object_set_new(ajs, "layer", json_string(layer)); jb_set_string(js, "layer", layer);
/* anomaly */ /* anomaly */
json_object_set_new(js, ANOMALY_EVENT_TYPE, ajs); jb_close(js);
OutputJSONBuffer(js, aft->file_ctx, &aft->json_buffer); OutputJsonBuilderBuffer(js, aft->file_ctx, &aft->json_buffer);
jb_free(js);
json_object_clear(js);
json_decref(js);
/* Current implementation assumes a single owner for this value */ /* Current implementation assumes a single owner for this value */
decoder_events->event_last_logged++; decoder_events->event_last_logged++;

Loading…
Cancel
Save