Skip to content

Commit

Permalink
example of using Lua to create a 2 events from one
Browse files Browse the repository at this point in the history
  • Loading branch information
mp3monster committed Sep 20, 2024
1 parent 1874ae4 commit 495327e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
34 changes: 34 additions & 0 deletions extras/fluentbit/lua-multi-event/advanced.lua
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
19 changes: 19 additions & 0 deletions extras/fluentbit/lua-multi-event/lua-advanced.conf
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 *

0 comments on commit 495327e

Please sign in to comment.