#!/usr/bin/env perl # Program: MSA-P2000-log-check.pl # # Description: Basic analysis of MSA/P2000 logfile # # If you obtain this script via Web, convert it to Unix format. # # Usage: MSA-P2000-log-check.pl [-h] -f logfile > MSA-report.txt # -h Print this help message # -f logfile Read variables from a config file # # Last Update: 21 September 2012 # Designed by: Dusan U. Baljevic (dusan.baljevic@ieee.org) # Coded by: Dusan U. Baljevic (dusan.baljevic@ieee.org) # # Copyright 2006-2015 Dusan Baljevic # # 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 3 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 . # # Perl script MSA-P2000-log-check.pl is a modest attempt to automate basic # analysis and formatting of messages with important severities # in MSA/P2000 logs. # # The script has been developed over several wours on Linux servers, # so errors (although not planned) might exist. Please use with care. # # My goals were: # # A) Simplicity to do basic MSA/P2000 log analysis; # B) Portability; # C) Standard Perl interperter; # D) No temporary files; # E) No repeated runs of similar commands; # F) Not to replace more comprehensive debugging tools; # G) Usefullness of results, not their formatting on the screen; # # Like all scripts and programs, this one will continue to # change as our needs change. # Define important environment variables # $ENV{'PATH'} = "/bin:/usr/sbin:/sbin:/usr/bin:/usr/local/bin"; # Define Shell # $ENV{'SHELL'} = '/bin/sh' if $ENV{'SHELL'} ne ''; $ENV{'IFS'} = '' if $ENV{'IFS'} ne ''; use strict; use vars qw($CMD $SCRIPT_VERSION $REC_VERSION $BEST_VERSION $CUR_VERSION $OLDER_PERL_FLAG $opt_h $opt_f $LOGFILE); if ( $CUR_VERSION < $REC_VERSION ) { print "WARNING: This script has only been tested for use with Perl version $REC_VERSION and above. The Perl on this server is version $CUR_VERSION. Proper functionality with older Perl is unknown and unsupported. It is recommended to: a) Change the first line in this script #!/usr/bin/env perl to a full path of a newer version of Perl, for example: #!/usr/in/perl or #!/opt/perl/bin/perl or b) Change the environment variable PATH outside this script and put the better version of Perl first in the directory search. \n"; exit(1); } elsif ( $CUR_VERSION < $BEST_VERSION ) { $OLDER_PERL_FLAG++; print "NOTE: For best results (and to avoid bugs in older versions) it is highly recommended to upgrade Perl to $BEST_VERSION or higher. \n"; } # Global variables # my @BADENT = q{}; my @BADENT2 = q{}; my $EVENTID = ''; my $TIMEID1 = ''; my $TIMEID2 = ''; my $CODEID = ''; my $SEVERITY = ''; my @MESSAGE = q{}; my $ERRCNT = 0; my $CRITCNT = 0; my $WARNCNT = 0; my $WARNSTR = 'AUDIT-WARN:'; my $ERRSTR = 'AUDIT-FAIL:'; my $NOTESTR = 'AUDIT-NOTE:'; my $INFOSTR = 'AUDIT-INFO:'; my $PASSSTR = 'AUDIT-PASS:'; sub Usage { if ( eval "require File::Basename" ) { import File::Basename; $CMD = basename( "$0", ".pl" ); Prusage(); } else { $CMD = `basename $0`; chomp($CMD); Prusage(); } } sub Prusage { print < == 0 ) { # print "$ERRSTR This log analysis should be run without root privileges\n"; # exit(1); #} if ( -T "$LOGFILE" && -s "$LOGFILE" ) { print "$PASSSTR Analysing $LOGFILE\n\n"; if ( open( CC, "awk '! /^#/ && ! /awk/ {print}' $LOGFILE |" ) ) { while () { next if ( grep( /^$|sendThisReply|NO_ERROR/, $_ ) ); $_ =~ s/\s+$//g; if ( grep( /EVENT/, $_ ) ) { if ( grep( /WARNING\s+|ERROR\s+|CRITICAL\s+/, $_ ) ) { push(@BADENT2, "$_\n"); } next; } if ( grep( /WARNING\s+|ERROR\s+|CRITICAL\s+/, $_ ) ) { ( $EVENTID, $TIMEID1, $TIMEID2, $CODEID, $SEVERITY, @MESSAGE) = split(/\s+/, $_); push(@BADENT, "EVENTID: $EVENTID\n"); push(@BADENT, "TIME: $TIMEID1 $TIMEID2\n"); push(@BADENT, "CODEID: $CODEID\n"); push(@BADENT, "SEVERITY: $SEVERITY\n"); push(@BADENT, "DESCRIPTION: @MESSAGE\n"); push(@BADENT, "\n"); if ( "$SEVERITY" eq "ERROR" ) { $ERRCNT++; } if ( "$SEVERITY" eq "WARNING" ) { $WARNCNT++; } if ( "$SEVERITY" eq "CRITICAL" ) { $CRITCNT++; } } } } else { print "$ERRSTR Cannot open $LOGFILE\n"; } close(CC); } if ( @BADENT ) { print @BADENT; print "EVENT STATUS:\n"; print @BADENT2; } print "\nSUMMARY:\n"; print "Count of Messages with Severity CRITICAL: $CRITCNT\n"; print "Count of Messages with Severity ERROR: $ERRCNT\n"; print "Count of Messages with Severity WARNING: $WARNCNT\n"; exit(0);