mirror of
https://github.com/rsyslog/rsyslog.git
synced 2025-12-17 07:00:42 +01:00
It is useful to be able to parse arbitrary JSON strings without the need
of an external message modification module. For example, together with
https://github.com/rsyslog/rsyslog/issues/1977
this can be used to parse out specific fields from Amazon AWS
configuration info. There are also other ample uses for such functionality.
closes https://github.com/rsyslog/rsyslog/issues/1979
33 lines
901 B
Bash
Executable File
33 lines
901 B
Bash
Executable File
#!/bin/bash
|
|
# Added 2017-12-09 by Rainer Gerhards, released under ASL 2.0
|
|
. $srcdir/diag.sh init
|
|
. $srcdir/diag.sh generate-conf
|
|
. $srcdir/diag.sh add-conf '
|
|
module(load="../plugins/imtcp/.libs/imtcp")
|
|
input(type="imtcp" port="13514")
|
|
template(name="outfmt" type="string" string="%$!%\n")
|
|
|
|
local4.* {
|
|
set $.ret = parse_json("{ \"c1\":\"data\" }", "\$!parsed");
|
|
action(type="omfile" file="rsyslog.out.log" template="outfmt")
|
|
}
|
|
'
|
|
|
|
. $srcdir/diag.sh startup
|
|
. $srcdir/diag.sh tcpflood -m1
|
|
. $srcdir/diag.sh shutdown-when-empty
|
|
. $srcdir/diag.sh wait-shutdown
|
|
|
|
# Our fixed and calculated expected results
|
|
EXPECTED='{ "parsed": { "c1": "data" } }'
|
|
echo $EXPECTED | cmp - rsyslog.out.log
|
|
if [[ $? -ne 0 ]]; then
|
|
printf "Invalid function output detected!\n"
|
|
printf "expected:\n$EXPECTED\n"
|
|
printf "rsyslog.out is:\n"
|
|
cat rsyslog.out.log
|
|
. $srcdir/diag.sh error-exit 1
|
|
fi;
|
|
|
|
. $srcdir/diag.sh exit
|