mirror of
https://github.com/rsyslog/rsyslog.git
synced 2025-12-13 03:40:41 +01:00
Subtree templates copied data into the worker buffer but left lenStr at zero. Output modules that respect lenStr (omfwd, omfile, others) therefore emitted empty payloads even though the buffer held valid JSON. Set lenStr to the subtree length immediately after the memcpy. This aligns the subtree branch with the existing regular/jsonftree/strgen paths and restores correct forwarding behaviour for all modules. Add regression coverage: * retain omfwd-subtree-tpl.sh to prove network forwarding now delivers the subtree payload * add omfile-subtree-jsonf.sh to exercise subtree data consumed via exec_template() and rendered through an option.jsonf list template Before: subtree templates built the JSON text but omfwd saw lenStr=0 and sent empty frames or files. After: lenStr matches the copied bytes, so modules transmit the expected JSON content. Closes: https://github.com/rsyslog/rsyslog/issues/6206
47 lines
1.2 KiB
Bash
Executable File
47 lines
1.2 KiB
Bash
Executable File
#!/bin/bash
|
|
# Validate that subtree templates provide data to jsonf list templates
|
|
unset RSYSLOG_DYNNAME
|
|
. ${srcdir:=.}/diag.sh init
|
|
|
|
generate_conf
|
|
add_conf '
|
|
$MainMsgQueueTimeoutShutdown 10000
|
|
|
|
template(name="eventSubtree" type="subtree" subtree="$!event")
|
|
template(name="jsonfList" type="list" option.jsonf="on") {
|
|
property(outname="message" name="$.payload" format="jsonf")
|
|
}
|
|
|
|
if $msg contains "msgnum:" then {
|
|
set $!event!level = "error";
|
|
set $!event!code = 500;
|
|
set $.payload = exec_template("eventSubtree");
|
|
action(type="omfile" file="'$RSYSLOG_OUT_LOG'" template="jsonfList")
|
|
}
|
|
'
|
|
|
|
startup
|
|
injectmsg 0 1
|
|
shutdown_when_empty
|
|
wait_shutdown
|
|
|
|
python3 - "$RSYSLOG_OUT_LOG" <<'PY'
|
|
import json
|
|
import sys
|
|
|
|
with open(sys.argv[1], 'r', encoding='utf-8') as fh:
|
|
payload = json.load(fh)
|
|
|
|
expected_message = '{ "level": "error", "code": 500 }'
|
|
if payload.get("message") != expected_message:
|
|
print('invalid JSON generated')
|
|
print('################# actual JSON is:')
|
|
print(json.dumps(payload, indent=2, sort_keys=True))
|
|
print('################# expected JSON was:')
|
|
print(json.dumps({"message": expected_message}, indent=2, sort_keys=True))
|
|
sys.exit(1)
|
|
PY
|
|
|
|
exit_test
|
|
|