rsyslog/tests/preservefqdn-localhostname-internal.sh
Rainer Gerhards 979c988dc9
tests: cover localHostname for internal messages
Why: prevent regressions around preserveFQDN/localHostname by
asserting internal rsyslogd messages honor the configured FQDN.

Impact: adds one test; no runtime behavior changes.

Before/After: before no explicit coverage; after internal hostname
is asserted as the configured FQDN.

Technical Overview:
- Add a testbench script that sets preserveFQDN and localHostname.
- Capture internal rsyslogd messages via syslogtag and write %hostname%.
- Validate every emitted hostname equals host.example.com.
- Register the test in TESTS_DEFAULT.

Closes https://github.com/rsyslog/rsyslog/issues/195

With the help of AI-Agents: Codex
2026-02-04 10:14:57 +01:00

30 lines
707 B
Bash
Executable File

#!/bin/bash
# Verify localHostname is applied to internal rsyslogd messages (hostname property).
. ${srcdir:=.}/diag.sh init
generate_conf
add_conf '
# Make sure local hostname is a FQDN and preserved.
global(preserveFQDN="on" localHostname="host.example.com")
template(name="outfmt" type="string" string="%hostname%\n")
if ($syslogtag contains "rsyslogd") then {
action(type="omfile" file="'$RSYSLOG_OUT_LOG'" template="outfmt")
stop
}'
startup
./msleep 100
shutdown_when_empty
wait_shutdown
line_count=$(wc -l < "$RSYSLOG_OUT_LOG")
if [ "$line_count" -eq 0 ]; then
printf 'expected hostname output, got empty log\n'
error_exit 1
fi
content_count_check "host.example.com" "$line_count"
exit_test