Add an optional Log::RotationControl to Log::Filter records.

This allows for the RotationControl to be automatically added to the
Log::rotation_control table for the filter's (writer, path) when it is
added to a stream via Log::add_filter.  Log::remove_filter now also
removes any RotationControl's associated with the filter from the
Log::rotation_control table.
This commit is contained in:
Jon Siwek 2011-08-26 14:36:56 -05:00
parent 005b1505b8
commit 263ef2bfc9
7 changed files with 233 additions and 40 deletions

View file

@ -0,0 +1,30 @@
# @TEST-EXEC: bro -b %INPUT >out
# @TEST-EXEC: btest-diff out
module Test;
export {
redef enum Log::ID += { Test };
type Info: record {
t: time;
id: conn_id;
} &log;
}
function custom_rotate(info: Log::RotationInfo) : bool
{
print "custom rotate", info;
return T;
}
event bro_init()
{
Log::create_stream(Test, [$columns=Info]);
Log::add_filter(Test, [$name="2nd", $path="test2",
$rotation=[$interv=30mins, $postprocessor=custom_rotate]]);
print Log::rotation_control;
Log::remove_filter(Test, "2nd");
# The RotationControl should be removed now
print Log::rotation_control;
}

View file

@ -0,0 +1,39 @@
#
# @TEST-EXEC: bro -b -r %DIR/rotation.trace %INPUT 2>&1 | egrep "test|test2" | sort >out
# @TEST-EXEC: for i in `ls test*.log | sort`; do printf '> %s\n' $i; cat $i; done | sort | uniq >>out
# @TEST-EXEC: btest-diff out
module Test;
export {
# Create a new ID for our log stream
redef enum Log::ID += { Test };
# 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;
}
redef Log::default_rotation_interval = 1hr;
redef Log::default_rotation_postprocessor_cmd = "echo 1st";
function custom_rotate(info: Log::RotationInfo) : bool
{
print "custom rotate", info;
return T;
}
event bro_init()
{
Log::create_stream(Test, [$columns=Log]);
Log::add_filter(Test, [$name="2nd", $path="test2",
$rotation=[$interv=30mins, $postprocessor=custom_rotate]]);
}
event new_connection(c: connection)
{
Log::write(Test, [$t=network_time(), $id=c$id]);
}

View file

@ -1,5 +1,5 @@
#
# @TEST-EXEC: bro -r %DIR/rotation.trace %INPUT 2>&1 | grep "test" >out
# @TEST-EXEC: bro -b -r %DIR/rotation.trace %INPUT 2>&1 | grep "test" >out
# @TEST-EXEC: for i in test.*.log; do printf '> %s\n' $i; cat $i; done >>out
# @TEST-EXEC: btest-diff out