#!/usr/bin/perl -w # #******************************************************************************* # #Copyright (c) 2009, Perforce Software, Inc. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE SOFTWARE, INC. BE LIABLE FOR ANY # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #******************************************************************************* # #Author: Stephen Moon # #Date: July 29, 2009 #Last Modified: August 25, 2010 #Program: Outputs the Perforce log error messages as well as user actions # to a file if the user is specified. # #******************************************************************************* use strict; my $argc = @ARGV; my $output_file = "error.txt"; if ($argc > 2 || $argc < 1) { die("Usage: getInfo.pl []\n"); } if( -f $output_file) { unlink $output_file; } #delete the error.txt file if it exists my ($user_file,$user_name) = ""; open(INPUT, "< $ARGV[0]") or die("Unable to open $ARGV[0]: $!"); open(ERROR, "> $output_file") or die("Unable to open $output_file: $!"); if(!defined($ARGV[1])) { #pass } else { #only executes the below if a user name is specified at the command prompt $user_name = $ARGV[1]; $user_file = $ARGV[1] . ".txt"; open(USER, "> $user_file") or die("Unable to open $user_file: $!"); } my $error = 0; #boolean value my $userFound = 0; #boolean value my $count_server_error = 0; my ($line_ct, $user_count) = (0,0); if(defined($ARGV[1])) { print USER "\nLog filename: $ARGV[0]\n"; } #loop to parse through the Perforce log while() { chomp; $line_ct++; if(/^Perforce server error.*$/) { $error = 1; $count_server_error++; print ERROR "\nLog filename: $ARGV[0]\n"; } elsif(/^Perforce server info.*$/) { $error = 0; } elsif(defined($user_name)) { if(/^.*\s$user_name\@.*$/) { $userFound = 1; print USER "$line_ct: $_\n"; $user_count++; } } if($error == 1) { print ERROR "$line_ct: $_\n"; } if($userFound == 1) { if(/^\s*$/) { $userFound = 0; } elsif(/^\-\-\-.*$/ and $userFound != 0) { #print USER "$line_ct: $_\n"; } } } if(defined($user_name)) { &messages($user_name,$user_count,$count_server_error); } else { $user_name = undef; &messages($user_name,$user_count,$count_server_error); } close(INPUT); close(ERROR); close(USER); #subroutine to output the error message to a file sub messages() { my $user_name = shift; my $user_count = shift; my $count_server_error = shift; if(!defined($user_name)) { print ERROR "The count of Perforce server error: " . $count_server_error; print "The count of Perforce server error: " . $count_server_error . "\n"; } else { print ERROR "The count of " . $user_name . " actions on the database: " . $user_count . "\n"; print ERROR "The count of Perforce server error: " . $count_server_error; print "The count of " . $user_name . " actions on the database: " . $user_count . "\n"; print "The count of Perforce server error: " . $count_server_error . "\n"; } }