mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 22:58:20 +00:00

In the past, we used a default canonifier, which removes everything that looks like a timestamp from log files. The goal of this is to prevent logs from changing, e.g., due to local system times ending up in log files. This, however, also has the side-effect of removing information that is parsed from protocols which probably should be part of our tests. There is at least one test (1999 certificates) where the entire test output was essentially removed by the canonifier. GH-4521 was similarly masked by this. This commit changes the default canonifier, so that only the first timestamp in a line is removed. This should skip timestamps that are likely to change while keeping timestamps that are parsed from protocol information. A pass has been made over the tests, with some additional adjustments for cases which require the old canonifier. There are some cases in which we probably could go further and not remove timestamps at all - that, however, seems like a follow-up project.
49 lines
1.6 KiB
Text
49 lines
1.6 KiB
Text
# @TEST-EXEC: zeek -b -r ${TRACES}/rotation.trace %INPUT | grep -E "test|test2" | sort >out.tmp
|
|
# @TEST-EXEC: cat out.tmp pp.log | sort >out
|
|
# @TEST-EXEC: for i in `ls test*.log | sort`; do printf '> %s\n' $i; cat $i; done | sort | $SCRIPTS/diff-remove-timestamps | uniq >>out
|
|
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-timestamps btest-diff out
|
|
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-sort btest-diff .stderr
|
|
|
|
module Test;
|
|
|
|
export {
|
|
# Create a new ID for our log stream
|
|
redef enum Log::ID += { LOG };
|
|
|
|
# Define a record with all the columns the log file can have.
|
|
# (I'm using a subset of fields from ssh-ext for demonstration.)
|
|
type Log: record {
|
|
t: time;
|
|
id: conn_id; # Will be rolled out into individual columns.
|
|
} &log;
|
|
}
|
|
|
|
function my_rotation_format_func(ri: Log::RotationFmtInfo): Log::RotationPath
|
|
{
|
|
local open_str = strftime(Log::default_rotation_date_format, ri$open);
|
|
local close_str = strftime(Log::default_rotation_date_format, ri$close);
|
|
local base = fmt("%s__%s__%s__", ri$path, open_str, close_str);
|
|
local rval = Log::RotationPath($file_basename=base);
|
|
return rval;
|
|
}
|
|
|
|
redef Log::default_rotation_interval = 1hr;
|
|
redef Log::default_rotation_postprocessor_cmd = "echo 1st >>pp.log";
|
|
redef Log::rotation_format_func = my_rotation_format_func;
|
|
|
|
function custom_rotate(info: Log::RotationInfo) : bool
|
|
{
|
|
print "custom rotate", info;
|
|
return T;
|
|
}
|
|
|
|
event zeek_init()
|
|
{
|
|
Log::create_stream(Test::LOG, [$columns=Log]);
|
|
Log::add_filter(Test::LOG, [$name="2nd", $path="test2", $interv=30mins, $postprocessor=custom_rotate]);
|
|
}
|
|
|
|
event new_connection(c: connection)
|
|
{
|
|
Log::write(Test::LOG, [$t=network_time(), $id=c$id]);
|
|
}
|