Skip to content

Commit

Permalink
output: generic simple tx json logger
Browse files Browse the repository at this point in the history
Ticket: 3827
  • Loading branch information
catenacyber committed Nov 23, 2023
1 parent 569d615 commit 1b140eb
Show file tree
Hide file tree
Showing 31 changed files with 206 additions and 1,898 deletions.
34 changes: 12 additions & 22 deletions scripts/setup-app-layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,43 +200,34 @@ def logger_patch_output_c(proto):
output = io.StringIO()
inlines = open(filename).readlines()
for i, line in enumerate(inlines):
if line.find("ALPROTO_TEMPLATE") > -1:
new_line = line.replace("TEMPLATE", proto.upper()).replace(
"template", proto.lower())
output.write(new_line)
if line.find("output-json-template.h") > -1:
output.write(line.replace("template", proto.lower()))
if line.find("/* Template JSON logger.") > -1:
output.write(inlines[i].replace("Template", proto))
output.write(inlines[i+1].replace("Template", proto))
output.write(inlines[i+2].replace("TEMPLATE", proto.upper()).replace(
"template", proto.lower()).replace("Template", proto))
output.write(inlines[i+3])
if line.find("rs_template_logger_log") > -1:
output.write(inlines[i].replace("TEMPLATE", proto.upper()).replace(
"template", proto.lower()))
if line.find("OutputTemplateLogInitSub(") > -1:
output.write(inlines[i].replace("Template", proto))
output.write(inlines[i+1])
output.write(inlines[i+2].replace("TEMPLATE", proto.upper()))
output.write(inlines[i+3])
output.write(inlines[i+4])
output.write(line)
open(filename, "w").write(output.getvalue())

def logger_copy_templates(proto):
lower = proto.lower()

pairs = (
("src/output-json-template.h",
"src/output-json-%s.h" % (lower)),
("src/output-json-template.c",
"src/output-json-%s.c" % (lower)),
("rust/src/applayertemplate/logger.rs",
"rust/src/applayer%s/logger.rs" % (lower)),
)

common_copy_templates(proto, pairs)

def logger_patch_makefile_am(protoname):
filename = "src/Makefile.am"
print("Patching %s." % (filename))
output = io.StringIO()
with open(filename) as infile:
for line in infile:
if line.lstrip().startswith("output-json-template."):
output.write(line.replace("template", protoname.lower()))
output.write(line)
open(filename, "w").write(output.getvalue())


def detect_copy_templates(proto, buffername):
lower = proto.lower()
Expand Down Expand Up @@ -398,7 +389,6 @@ def main():
raise SetupError("no app-layer parser exists for %s" % (proto))
logger_copy_templates(proto)
patch_rust_applayer_mod_rs(proto)
logger_patch_makefile_am(proto)
logger_patch_output_c(proto)
logger_patch_suricata_yaml_in(proto)

Expand Down
24 changes: 0 additions & 24 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,6 @@ noinst_HEADERS = \
output.h \
output-json-alert.h \
output-json-anomaly.h \
output-json-bittorrent-dht.h \
output-json-dcerpc.h \
output-json-dhcp.h \
output-json-dnp3.h \
Expand All @@ -410,27 +409,16 @@ noinst_HEADERS = \
output-json-frame.h \
output-json-ftp.h \
output-json.h \
output-json-http2.h \
output-json-http.h \
output-json-ike.h \
output-json-krb5.h \
output-json-metadata.h \
output-json-modbus.h \
output-json-quic.h \
output-json-mqtt.h \
output-json-netflow.h \
output-json-nfs.h \
output-json-pgsql.h \
output-json-rdp.h \
output-json-rfb.h \
output-json-sip.h \
output-json-smb.h \
output-json-smtp.h \
output-json-snmp.h \
output-json-ssh.h \
output-json-stats.h \
output-json-template.h \
output-json-tftp.h \
output-json-tls.h \
output-eve-syslog.h \
output-lua.h \
Expand Down Expand Up @@ -1009,7 +997,6 @@ libsuricata_c_a_SOURCES = \
output-flow.c \
output-json-alert.c \
output-json-anomaly.c \
output-json-bittorrent-dht.c \
output-json.c \
output-json-common.c \
output-json-dcerpc.c \
Expand All @@ -1023,27 +1010,16 @@ libsuricata_c_a_SOURCES = \
output-json-flow.c \
output-json-frame.c \
output-json-ftp.c \
output-json-http2.c \
output-json-http.c \
output-json-ike.c \
output-json-krb5.c \
output-json-metadata.c \
output-json-modbus.c \
output-json-quic.c \
output-json-mqtt.c \
output-json-netflow.c \
output-json-nfs.c \
output-json-pgsql.c \
output-json-rdp.c \
output-json-rfb.c \
output-json-sip.c \
output-json-smb.c \
output-json-smtp.c \
output-json-snmp.c \
output-json-ssh.c \
output-json-stats.c \
output-json-template.c \
output-json-tftp.c \
output-json-tls.c \
output-eve-syslog.c \
output-eve-null.c \
Expand Down
5 changes: 0 additions & 5 deletions src/output-json-alert.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,15 @@
#include "output-json-dns.h"
#include "output-json-http.h"
#include "output-json-tls.h"
#include "output-json-ssh.h"
#include "rust.h"
#include "output-json-smtp.h"
#include "output-json-email-common.h"
#include "output-json-nfs.h"
#include "output-json-smb.h"
#include "output-json-flow.h"
#include "output-json-sip.h"
#include "output-json-rfb.h"
#include "output-json-mqtt.h"
#include "output-json-ike.h"
#include "output-json-modbus.h"
#include "output-json-frame.h"
#include "output-json-quic.h"

#include "util-byte.h"
#include "util-privs.h"
Expand Down
163 changes: 0 additions & 163 deletions src/output-json-bittorrent-dht.c

This file was deleted.

27 changes: 0 additions & 27 deletions src/output-json-bittorrent-dht.h

This file was deleted.

1 change: 0 additions & 1 deletion src/output-json-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
#include "output-json-email-common.h"
#include "output-json-nfs.h"
#include "output-json-smb.h"
#include "output-json-http2.h"

#include "app-layer-htp.h"
#include "app-layer-htp-xff.h"
Expand Down
Loading

0 comments on commit 1b140eb

Please sign in to comment.