summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d0900a4)
raw | patch | inline | side by side (parent: d0900a4)
author | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Wed, 19 Mar 2008 10:16:12 +0000 (10:16 +0000) | ||
committer | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Wed, 19 Mar 2008 10:16:12 +0000 (10:16 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@9938 594d385d-05f5-0310-b6e9-bd551577e9d8
gosa-si/tests/log-parser.pl | patch | blob | history |
index 79885bbabd0be1f00f85893197f5d9f4137b15ac..256c310f232a0dd13d10d51b1e6c6b5d99ab0a2e 100755 (executable)
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 = <FILE>){
-
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";
}
+
}
+
+
+