-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
example of using Lua to create a 2 events from one
- Loading branch information
1 parent
1874ae4
commit 495327e
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
local function printDetails(record, indent) | ||
-- this function can be used recursively so we can count nested elements | ||
local counter = 0 | ||
for key, value in pairs(record) do | ||
local elementType = type(value) | ||
if (elementType == "table") then | ||
print(string.format("table %s { %s = ", indent, key)) | ||
printDetails(value, indent .. " ") | ||
print("}") | ||
else | ||
print(string.format("%s %s = %s --> %s", indent, key, tostring(value), elementType)) | ||
end | ||
end | ||
end | ||
|
||
-- perform a deep copy if the received parameter is a table | ||
function copy(obj) | ||
if type(obj) ~= 'table' then return obj end | ||
local res = {} | ||
for k, v in pairs(obj) do res[copy(k)] = copy(v) end | ||
return res | ||
end | ||
|
||
function cb_advanced(tag, timestamp, record) | ||
local code = 1 | ||
print("Lua script - ", tag, " ", timestamp, " record is a", type(record)) | ||
-- printDetails(record, "") | ||
record1 = copy(record) | ||
record2 = copy(record) | ||
record2["BLAHH"] = "piiiinnnnnnnggggggggg" | ||
record1["remoteuser"] = "another user" | ||
newRecord = { record1, record2 } | ||
return code, timestamp, newRecord | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[SERVICE] | ||
flush 1 | ||
|
||
[INPUT] | ||
name dummy | ||
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} | ||
samples 1 | ||
tag dummy1 | ||
|
||
[FILTER] | ||
name lua | ||
match * | ||
script ./advanced.lua | ||
call cb_advanced | ||
protected_mode true | ||
|
||
[OUTPUT] | ||
name stdout | ||
match * |