mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-28 16:24:54 +02:00
Summary option added to grep_log ext.ticket 3209
(cherry picked from commit a0890fa86b7ed7d31858db1e7c635ff36cc9cfd0)
This commit is contained in:
parent
afa34a11fd
commit
d70e3bd52b
@ -53,6 +53,12 @@ my $Idx_size = 0;
|
|||||||
# Regular expression to be matched
|
# Regular expression to be matched
|
||||||
my $Reg_exp = '';
|
my $Reg_exp = '';
|
||||||
|
|
||||||
|
# Flag to show or not summary module
|
||||||
|
my $summary_flag = 0;
|
||||||
|
|
||||||
|
# Number of coincidences found
|
||||||
|
my $coincidences = 0;
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# SUB error_msg
|
# SUB error_msg
|
||||||
# Print an error message and exit.
|
# Print an error message and exit.
|
||||||
@ -72,7 +78,7 @@ sub error_msg ($) {
|
|||||||
# Print a help message.
|
# Print a help message.
|
||||||
###############################################################################
|
###############################################################################
|
||||||
sub print_help () {
|
sub print_help () {
|
||||||
print "Usage: $0 <log_file> <module_name> <pattern> <up_lines_extra> <bot_lines_extra>\n";
|
print "Usage: $0 <log_file> <module_name> <pattern> <up_lines_extra> <bot_lines_extra> [--summary]\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@ -193,6 +199,7 @@ sub parse_log (;$$) {
|
|||||||
push @lines, $line;
|
push @lines, $line;
|
||||||
if ($line =~ m/$Reg_exp/i) {
|
if ($line =~ m/$Reg_exp/i) {
|
||||||
push @nl_found, $nl;
|
push @nl_found, $nl;
|
||||||
|
$coincidences++;
|
||||||
}
|
}
|
||||||
$nl++;
|
$nl++;
|
||||||
}
|
}
|
||||||
@ -236,6 +243,21 @@ sub parse_log (;$$) {
|
|||||||
return @data;
|
return @data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# SUB print_summary
|
||||||
|
# Print module summary to stdout.
|
||||||
|
###############################################################################
|
||||||
|
sub print_summary() {
|
||||||
|
my $output = "<module>\n";
|
||||||
|
$output .= "<name><![CDATA[" . $Module_name . " coincidences]]></name>\n";
|
||||||
|
$output .= "<type><![CDATA[async_data]]></type>\n";
|
||||||
|
$output .= "<datalist>\n";
|
||||||
|
$output .= "<data><value><![CDATA[$coincidences]]></value></data>\n";
|
||||||
|
$output .= "</datalist>\n";
|
||||||
|
$output .= "</module>\n";
|
||||||
|
print stdout $output;
|
||||||
|
}
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# SUB parse_log
|
# SUB parse_log
|
||||||
# Print log data to stdout.
|
# Print log data to stdout.
|
||||||
@ -245,6 +267,7 @@ sub print_log (@) {
|
|||||||
|
|
||||||
# No data
|
# No data
|
||||||
if ($#data < 0) {
|
if ($#data < 0) {
|
||||||
|
print_summary() if ($summary_flag == 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,7 +286,9 @@ sub print_log (@) {
|
|||||||
}
|
}
|
||||||
# Regular module
|
# Regular module
|
||||||
else {
|
else {
|
||||||
my $output = "<module>\n";
|
my $output;
|
||||||
|
print_summary() if ($summary_flag == 1);
|
||||||
|
$output = "<module>\n";
|
||||||
$output .= "<name><![CDATA[" . $Module_name . "]]></name>\n";
|
$output .= "<name><![CDATA[" . $Module_name . "]]></name>\n";
|
||||||
$output .= "<type><![CDATA[async_string]]></type>\n";
|
$output .= "<type><![CDATA[async_string]]></type>\n";
|
||||||
$output .= "<datalist>\n";
|
$output .= "<datalist>\n";
|
||||||
@ -294,6 +319,13 @@ $Module_name = $ARGV[1];
|
|||||||
$Reg_exp = $ARGV[2];
|
$Reg_exp = $ARGV[2];
|
||||||
my $up_lines = $ARGV[3];
|
my $up_lines = $ARGV[3];
|
||||||
my $bot_lines = $ARGV[4];
|
my $bot_lines = $ARGV[4];
|
||||||
|
my $sum_flag = $ARGV[5];
|
||||||
|
|
||||||
|
if ( ( defined($up_lines) && ($up_lines eq "--summary"))
|
||||||
|
|| ( defined($bot_lines) && ($bot_lines eq "--summary"))
|
||||||
|
|| ( defined($sum_flag) && ($sum_flag eq "--summary")) ) {
|
||||||
|
$summary_flag = 1;
|
||||||
|
}
|
||||||
# Create index file storage directory
|
# Create index file storage directory
|
||||||
if ( ! -d $Idx_dir) {
|
if ( ! -d $Idx_dir) {
|
||||||
mkdir($Idx_dir) || error_msg("Error creating directory $Idx_dir: "
|
mkdir($Idx_dir) || error_msg("Error creating directory $Idx_dir: "
|
||||||
|
Loading…
x
Reference in New Issue
Block a user