rsyslog/tests/omsendertrack-basic.sh
Rainer Gerhards 4c086ed78c
omsendertrack: stop towards full completion of module.
Work towards full completion of the module’s interface as it exits PoC.
The new name senderid (formerly: template) matches intent (identify a
sender, not an output format) and avoids confusion.  Also make state
persistence safer via atomic writes.

Merged a bit pre-completion in order to get a static analyzer fix
into the main code base. Some additional cleanup PR will follow.
State is much cleaner now than in PoC.

Impact: Configs must use senderid=; statefile is now required. Tests
and docs updated.

Before/After: action(... template="name") -> action(... senderid="name").

Technical details:
- Replace the config parameter and instance field; drop legacy template
  parsing in parseSelectorAct. The module now reads only senderid=.
- Enforce required statefile (descriptor + runtime) and cache a temp
  path "<statefile>.tmp" to ensure rename() is atomic. Provide a
  one-time fallback build if the cache is missing (e.g., reload flow).
- Add built-in template "StdOmSenderTrack-senderid" yielding
  "%fromhost-ip%" and use it as the default senderid template.
- Improve memory ownership (free cached temp path/default template) and
  keep existing locking/queue semantics unchanged.
- Update tests to use senderid= and prune PoC doc note accordingly.

see also: https://github.com/rsyslog/rsyslog/issues/5599
2025-08-25 15:51:58 +02:00

34 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
# addd 2016-05-13 by RGerhards, released under ASL 2.0
. ${srcdir:=.}/diag.sh init
export NUMMESSAGES=10 # MUST be an even number!
export QUEUE_EMPTY_CHECK_FUNC=wait_file_lines
generate_conf
add_conf '
module(load="../plugins/omsendertrack/.libs/omsendertrack")
module(load="../plugins/imtcp/.libs/imtcp")
input(type="imtcp" port="0" listenPortFileName="'$RSYSLOG_DYNNAME'.tcpflood_port")
template(name="hostname" type="string" string="%hostname%")
action(type="omsendertrack" senderid="hostname" statefile="'$RSYSLOG_DYNNAME'.sendertrack")
# The following is just to find a terminating condition for message injection
template(name="outfmt" type="string" string="%msg:F,58:2%\n")
:msg, contains, "msgnum:" action(type="omfile" template="outfmt"
file="'$RSYSLOG_OUT_LOG'")
'
startup
tcpflood -h sender1.example.net -m $(( NUMMESSAGES / 2 - 1 ))
tcpflood -h sender2.example.net -m 1 -i $(( NUMMESSAGES / 2 - 1 )) # this sender must have firstseen <> lastseen
sleep 2
tcpflood -h sender2.example.net -m $(( NUMMESSAGES / 2 )) -i $(( NUMMESSAGES / 2 ))
./msleep 20
shutdown_when_empty
sleep 1
echo
cat ${RSYSLOG_DYNNAME}.sendertrack
echo
wait_shutdown
seq_check
exit_test