From: rettenbe Date: Wed, 19 Mar 2008 10:16:12 +0000 (+0000) Subject: more options to select one gosa-si message X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=a1ee27a704cad4619b1444b84c82d38e9c8f508f;p=gosa.git more options to select one gosa-si message git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@9938 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-si/tests/log-parser.pl b/gosa-si/tests/log-parser.pl index 79885bbab..256c310f2 100755 --- a/gosa-si/tests/log-parser.pl +++ b/gosa-si/tests/log-parser.pl @@ -23,36 +23,102 @@ use warnings; use Getopt::Long; my $log_file = "/var/log/gosa-si-server.log"; -my $within_log_session = 0; - +my $within_session = 0; +my $within_incoming = 0; my $session; -GetOptions("s|session=s" => \$session); +my $incoming; + +sub check_incoming { + my ($line) = @_ ; + my @line_list = split(" ", $line); + + # new incoming msg, set all values back to default + if ($line =~ /INFO: Incoming msg with session ID \d+ from/ ) { + $within_incoming = 0; + } + + if ($line =~ /INFO: Incoming msg with session ID \d+ from '$incoming'/) { + $within_incoming = 1; + return $line; + } else { + if ($within_incoming) { + return $line; + } else { + return; + } + } +} + +sub check_session { + my ($line) = @_ ; + my @line_list = split(" ", $line); + + if (not $line_list[4]) { + if ($within_session) { + return $line; + } + return; + } + + if($line_list[4] eq $session) { + $within_session = 1; + return $line; + } else { + $within_session = 0; + } + return; +} -if( not defined $session) { die "\tplease define a session to parse\n\ti.e. 'perl log-parser.pl -s 4'\n" }; +### MAIN ###################################################################### -print "session: $session\n"; +GetOptions( + "s|session=s" => \$session, + "i|incoming=s" => \$incoming, + ); + +# check script pram +my $check_script_pram = 0; +if (defined $session) { + print "session: $session\n"; + $check_script_pram++; +} +if (defined $incoming) { + print "incoming msg for mac: $incoming\n"; + $check_script_pram++; +} + +if ($check_script_pram == 0) { + # print usage and die + print "exiting script\n"; + exit(0); +} open(FILE, "<$log_file") or die "\t can not open log-file"; - # Read lines my $line; while ($line = ){ - chomp($line); - my @line_list = split(" ", $line); - - if (not $line_list[4]) { - if ($within_log_session) { - print "$line\n"; + my $line2print; + if (defined $session && (not defined $incoming)) { + $line2print = &check_session($line); + + } elsif (defined $incoming && (not defined $session)) { + $line2print = &check_incoming($line); + + } elsif ((defined $incoming) && (defined $session)) { + my $line1 = &check_session($line); + my $line2 = &check_incoming($line); + if ((defined $line1) && (defined $line2)) { + $line2print = $line; } - next; } - if($line_list[4] eq $session) { - print "$line\n"; - $within_log_session = 1; - - } else { - $within_log_session = 0; + # printing + if (defined $line2print) { + print "$line\n"; } + } + + +