Skip to content

Commit 495327e

Browse files
committed
example of using Lua to create a 2 events from one
1 parent 1874ae4 commit 495327e

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
local function printDetails(record, indent)
2+
-- this function can be used recursively so we can count nested elements
3+
local counter = 0
4+
for key, value in pairs(record) do
5+
local elementType = type(value)
6+
if (elementType == "table") then
7+
print(string.format("table %s { %s = ", indent, key))
8+
printDetails(value, indent .. " ")
9+
print("}")
10+
else
11+
print(string.format("%s %s = %s --> %s", indent, key, tostring(value), elementType))
12+
end
13+
end
14+
end
15+
16+
-- perform a deep copy if the received parameter is a table
17+
function copy(obj)
18+
if type(obj) ~= 'table' then return obj end
19+
local res = {}
20+
for k, v in pairs(obj) do res[copy(k)] = copy(v) end
21+
return res
22+
end
23+
24+
function cb_advanced(tag, timestamp, record)
25+
local code = 1
26+
print("Lua script - ", tag, " ", timestamp, " record is a", type(record))
27+
-- printDetails(record, "")
28+
record1 = copy(record)
29+
record2 = copy(record)
30+
record2["BLAHH"] = "piiiinnnnnnnggggggggg"
31+
record1["remoteuser"] = "another user"
32+
newRecord = { record1, record2 }
33+
return code, timestamp, newRecord
34+
end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[SERVICE]
2+
flush 1
3+
4+
[INPUT]
5+
name dummy
6+
dummy { "time": "12/May/2023:08:05:52 +0000", "remote_ip": "10.4.72.163", "remoteuser": "-", "request": { "verb": "GET", "path": " /downloads/product_2", "protocol": "HTTP", "version": "1.1" }, "response": 304}
7+
samples 1
8+
tag dummy1
9+
10+
[FILTER]
11+
name lua
12+
match *
13+
script ./advanced.lua
14+
call cb_advanced
15+
protected_mode true
16+
17+
[OUTPUT]
18+
name stdout
19+
match *

0 commit comments

Comments
 (0)