From c8c0341e94f7347576373dea3e5015276c39b3a6 Mon Sep 17 00:00:00 2001 From: Jason Etheridge Date: Fri, 25 Sep 2015 14:10:22 -0400 Subject: [PATCH] osrfsys log parser Some tweaks probably needed to the regular expressions within based on the log format. ./trace_logs.pl [--follow-pid] [--follow-auth] [--follow-trace] [--include-errors] [--search="substring"] [logfile1] [logfile2] [...] or ./trace_logs.pl [-p] [-a] [-t] [-e] [-s "substring"] [logfile1] [logfile2] [...] This script searches the specified (or piped) logfiles and spits out lines containing the "substring". It optionally parses the logfiles and prints out related lines based on PID, threadtrace, and authtoken values that it encounters in the matching lines. --include-errors will pull in lines containing [ERR Signed-off-by: Jason Etheridge --- ESI-Examples/sys/scripts/trace_logs.pl | 75 ++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100755 ESI-Examples/sys/scripts/trace_logs.pl diff --git a/ESI-Examples/sys/scripts/trace_logs.pl b/ESI-Examples/sys/scripts/trace_logs.pl new file mode 100755 index 0000000..72819ee --- /dev/null +++ b/ESI-Examples/sys/scripts/trace_logs.pl @@ -0,0 +1,75 @@ +#!/usr/bin/perl + +# Copyright (C) 2014-2015 Equinox Software Inc. +# Jason Etheridge +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +use Getopt::Long; +my $help = 0; +my $man = 0; +my $follow_pid = 0; +my $follow_auth = 0; +my $follow_trace = 0; +my $include_errors = 0; +my $search = ''; +GetOptions( + 'follow-pid|follow_pid|pid' => \$follow_pid, + 'follow-auth|follow_auth|auth' => \$follow_auth, + 'follow-trace|follow_trace|trace' => \$follow_trace, + 'include-errors|errors' => \$include_errors, + 'search=s' => \$search, + 'help|?' => \$help); +if ($help || ((@ARGV == 0) && (-t STDIN))) { + print qq^$0 [--follow-pid] [--follow-auth] [--follow-trace] [--include-errors] [--search="substring"] [logfile1] [logfile2] [...] +or $0 [-p] [-a] [-t] [-e] [-s "substring"] [logfile1] [logfile2] [...] +This script searches the specified (or piped) logfiles and spits out lines containing the "substring". +It optionally parses the logfiles and prints out related lines based on PID, threadtrace, and authtoken +values that it encounters in the matching lines. --include-errors will pull in lines containing [ERR\n^; + exit 0; +} + +my %search_hash = (); +$search_hash{$search} = 1; +if ($include_errors) { + $search_hash{'[ERR'} = 1; +} + +while($line = <>) { + my $found = 0; + for $term (keys %search_hash) { + if (index($line,$term) > -1) { + $found = 1; + last; + } + } + if ($found) { + if ($follow_pid) { + if ($line =~ /^\[.+?\] \S+ \[.+?:(\d+):.+/) { + $search_hash{$1} = 1; + } + } + if ($follow_auth) { + if ($line =~ /([0123456789abcdef]{32})/) { + $search_hash{$1} = 1; + } + } + if ($follow_trace) { + if ($line =~ /^\[.+?\] \S+ \[.+?:\d+:.+?:\d+:(\d+)\]/) { + $search_hash{$1} = 1; + } + } + print $line; + } +} -- 2.11.0