rsyslog/tests/yaml-error.sh
Rainer Gerhards 1cc162b2e1 feat: add YAML as an alternative configuration format
rsyslog now accepts .yaml/.yml files as configuration files
in addition to RainerScript (.conf). The format is triggered
automatically based on file extension, both for the main config
file (-f flag) and for include() directives.

Architecture:
- New runtime/yamlconf.c (libyaml event-based parser) builds the
  same cnfobj+nvlst structures that the bison parser produces and
  calls cnfDoObj() for each block.
- Ruleset script: keys are synthesised into a complete RainerScript
  ruleset(name=...) { ... } block and pushed onto the flex buffer
  stack so the existing lex/bison pipeline handles all filter
  expressions and statements unchanged.
- routing in rsconf.c::load() and cnfDoInclude() detects .yaml/.yml
  by extension and delegates to yamlconf_load().
- cnfHasPendingBuffers() (new) lets rsconf.c flush queued script
  buffers after YAML-as-main-config loading.
- Guarded by #ifdef HAVE_LIBYAML throughout; graceful error when
  libyaml is absent.

Schema (top-level YAML keys):
  global, modules, inputs, templates, rulesets, mainqueue,
  include, parser, lookup_table, dyn_stats, ratelimit, timezone

Parameter names are identical to RainerScript; all type coercion
and validation is reused via nvlstGetParams() unchanged.

Tests: yaml-basic, yaml-include, yaml-ruleset-script, yaml-error
Documentation: doc/source/configuration/yaml_config.rst

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-26 09:19:48 +01:00

33 lines
917 B
Bash
Executable File

#!/bin/bash
# Tests that an invalid YAML config file produces a clean error message and
# that rsyslog exits with a non-zero status (does not crash or hang).
#
# Added 2025 by contributors, released under ASL 2.0
. ${srcdir:=.}/diag.sh init
generate_conf
add_conf '
include(file="'${RSYSLOG_DYNNAME}_bad'.yaml" optional="off")
'
# Write deliberately malformed YAML
cat > "${RSYSLOG_DYNNAME}_bad.yaml" << 'BADEOF'
global:
workdirectory: "/tmp"
modules:
- load: [unclosed array
param: value
BADEOF
# Use config-check mode (-N1) which exits non-zero on any config error
../tools/rsyslogd -C -N1 \
-M"${RSYSLOG_MODDIR}" \
-f"${TESTCONF_NM}.conf" \
> "${RSYSLOG_DYNNAME}.error.log" 2>&1
rc=$?
if [ $rc -eq 0 ]; then
echo "FAIL: rsyslogd should have reported a config error for invalid YAML"
error_exit 1
fi
echo "PASS: rsyslogd correctly reported error (exit $rc) for invalid YAML"
exit_test