Skip to content
Snippets Groups Projects
Commit 24996a35 authored by Mark Harrison's avatar Mark Harrison
Browse files

Limit the number of error lines that can be contained in errstring

parent 737e03ad
No related branches found
No related tags found
No related merge requests found
...@@ -44,6 +44,11 @@ The name of the file to monitor. ...@@ -44,6 +44,11 @@ The name of the file to monitor.
Regular expression for matching error lines. Regular expression for matching error lines.
=item maxerrs
Maximum number of error lines to include in the error string output. Defaults
to 5.
=back =back
=head1 METRICS =head1 METRICS
...@@ -67,6 +72,8 @@ sub handler { ...@@ -67,6 +72,8 @@ sub handler {
my $config = $self->{config}; my $config = $self->{config};
my $file = $config->{filename}; my $file = $config->{filename};
$config->{maxerrs} = 5 unless exists($config->{maxerrs});
my @statinfo = stat($file); my @statinfo = stat($file);
if (!exists($self->{file_dev}) || if (!exists($self->{file_dev}) ||
...@@ -89,8 +96,10 @@ sub handler { ...@@ -89,8 +96,10 @@ sub handler {
while(<$log>) { while(<$log>) {
chomp; chomp;
if (/$config->{match}/) { if (/$config->{match}/) {
$self->{errstring} .= " " if (length($self->{errstring})); if ($self->{errs} < $config->{maxerrs}) {
$self->{errstring} .= $_; $self->{errstring} .= " " if (length($self->{errstring}));
$self->{errstring} .= $_;
}
$self->{errs}++; $self->{errs}++;
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment