Skip to content

Commit

Permalink
lib/filterx: add e2e test for proper LogMsg -> FilterX changes sync
Browse files Browse the repository at this point in the history
Signed-off-by: Szilard Parrag <[email protected]>
  • Loading branch information
OverOrion committed Oct 16, 2024
1 parent 5f2b884 commit 9c12db1
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions tests/light/functional_tests/filterx/test_filterx.py
Original file line number Diff line number Diff line change
Expand Up @@ -2395,3 +2395,57 @@ def test_parse_leef(config, syslog_ng):
r"""}""" + "\n"
)
assert file_true.read_log() == exp


def test_proper_generation_counter(config, syslog_ng):
file_true = config.create_file_destination(file_name="dest-true.log", template="'$MSG\n'")
file_false = config.create_file_destination(file_name="dest-false.log", template="'$MSG\n'")

raw_conf = f"""
@version: {config.get_version()}
options {{ stats(level(1)); }};
source genmsg {{
example-msg-generator(num(1) template("dummy message") values("bar" => "bar_value"));
}};
destination dest_true {{
{render_statement(file_true)};
}};
destination dest_false {{
{render_statement(file_false)};
}};
log {{
source(genmsg);
if {{
filterx {{
$foo = "foovalue"; # Could have come from the log message as well, doesn't matter
$ISODATE; # Special case for macro resolution
unset($bar); # Must come from the log message
baz = $MSG;
}};
rewrite {{ set("almafa", value("foo")); }};
parser {{ date-parser(format("%Y") template("2000")); }};
rewrite {{ set("kortefa", value("bar")); }};
rewrite {{ set("kortefa", value("baz")); }};
filterx {{
$MSG = {{"from_nvtable": $foo, "from_a_macro": $ISODATE, "unset_then_set": $bar ?? "not found"}};
}};
destination(dest_true);
}} else {{
destination(dest_false);
}};
}};
"""
config.set_raw_config(raw_conf)

syslog_ng.start(config)

assert "processed" in file_true.get_stats()
assert file_true.get_stats()["processed"] == 1
assert file_true.read_log() == '{"from_nvtable":"almafa","from_a_macro":"2000-01-01T00:00:00+01:00","unset_then_set":"kortefa"}\n'

0 comments on commit 9c12db1

Please sign in to comment.