From a86dd8755140d39a3a6184f4a88d088be696de84 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Sat, 1 Jun 2024 13:04:45 +0200 Subject: [PATCH] tests: add lua stats test --- tests/lua-output-stats/README.md | 3 +++ tests/lua-output-stats/suricata.yaml | 9 +++++++++ tests/lua-output-stats/test.lua | 29 +++++++++++++++++++++++++++ tests/lua-output-stats/test.pcap | Bin 0 -> 1181 bytes tests/lua-output-stats/test.yaml | 8 ++++++++ 5 files changed, 49 insertions(+) create mode 100644 tests/lua-output-stats/README.md create mode 100644 tests/lua-output-stats/suricata.yaml create mode 100644 tests/lua-output-stats/test.lua create mode 100644 tests/lua-output-stats/test.pcap create mode 100644 tests/lua-output-stats/test.yaml diff --git a/tests/lua-output-stats/README.md b/tests/lua-output-stats/README.md new file mode 100644 index 000000000..bdafb8ca6 --- /dev/null +++ b/tests/lua-output-stats/README.md @@ -0,0 +1,3 @@ +Tests the output of stats being logged by Lua. + +PCAPs created by Jason Ish. diff --git a/tests/lua-output-stats/suricata.yaml b/tests/lua-output-stats/suricata.yaml new file mode 100644 index 000000000..5cd3ea744 --- /dev/null +++ b/tests/lua-output-stats/suricata.yaml @@ -0,0 +1,9 @@ +%YAML 1.1 +--- + +outputs: + - lua: + enabled: yes + scripts-dir: . + scripts: + - test.lua diff --git a/tests/lua-output-stats/test.lua b/tests/lua-output-stats/test.lua new file mode 100644 index 000000000..d3c0f6dcd --- /dev/null +++ b/tests/lua-output-stats/test.lua @@ -0,0 +1,29 @@ +filename = "lua-stats.log" + +function init (args) + local needs = {} + needs["type"] = "stats" + return needs +end + +function setup (args) + file = assert(io.open(SCLogPath() .. "/" .. filename, "w")) +end + +function log(args) + for n, v in ipairs(args) do + --print(n .. " - " .. v["name"] .. " == " .. v["value"]); + if (v["name"] == "decoder.pkts") then + msg = string.format("packets %u", v["value"]); + write(msg) + end + end +end + +function deinit(args) + file:close(file) +end + +function write(msg) + file:write(msg .. "\n") +end diff --git a/tests/lua-output-stats/test.pcap b/tests/lua-output-stats/test.pcap new file mode 100644 index 0000000000000000000000000000000000000000..20db7a12e8f6c0ab90ed3166446cc09bc69f8845 GIT binary patch literal 1181 zc-p&ic+)~A1{MYcU}0bclCFlsWL^u=;!t_JF7gqX#doRgWFSE8Go#-37?Uyzhv!JM3*3zBAZ z16mL&%F2)kR0hHjqaoISEeMX22U&2;A7nVl5(ZPC753-qXRdB+0GU9*f&)BIMfwaZ zCZPqQAPeKR@G$rSg?zF3$bOyz$ilWHn2!!A0)3<{mci?f@DXcLPJVJWhGp(R!|Qz+ z8A5?dLa`a{KJPFC(D0+%VTLzt0vc{CR6GS0sRnUdX(269Ar#*d;knCRao z2p!Oeh9U<8i>{TMBFGJ*?d%LuK%ppXZt#gy1iK*w;Rc{rEwpc}dyR-TY#xQh7vp9I zmW<|8=^j9vG=6d7Nr6k&fNZM21PjuKN{|$28A((M1X(ceHz&Rns08+k55g-zE9@2H zEh9-wfx3_snEHny;@MY(^EVZZ@9NVmU#Xun* iAV0G>Gd)i?y{PzrVFbgU2nGgr4zM;(D`5BrHUI#CKoyDr literal 0 Hc-jL100001 diff --git a/tests/lua-output-stats/test.yaml b/tests/lua-output-stats/test.yaml new file mode 100644 index 000000000..0513752f7 --- /dev/null +++ b/tests/lua-output-stats/test.yaml @@ -0,0 +1,8 @@ +requires: + features: + - HAVE_LUA + +checks: + - shell: + args: grep 'packets 10' lua-stats.log | wc -l + expect: 1 -- 2.47.2