PERL Script: Parse the VCS Engine Log for messages related to an object over a number of hours
Created: 03 Dec 2010 | Updated: 12 Jan 2011 | 3 comments
Description:
This script will look in the engine log for messages related to a cluster object that have occurred up to a certain number of hours ago.
==============================================================================
THE SCRIPT IS AS FOLLOWS
==============================================================================
#!/usr/bin/perl
#
# haloghist
# Written by Mark Gibson
# Version 1.0
#
# Usage:
# haloghist -help
# haloghist -res <resource> | -grp <group> | -sys <system> | -clus <cluster> -hoursago <hours>
#
# <resource> is the name of a resource in the cluster
# <system> is the name of a system
# <group> is the name of a group
# <cluster> is the name of a cluster
#
use strict;
use Getopt::Long;
use Time::Local;
my $vcs_home = $ENV{"VCS_HOME"};
if (!defined ($vcs_home)) {
$vcs_home="/opt/VRTSvcs";
}
#
# Global args
#
# Get the name of this script
my $me = $0;
$me =~ s|.*/||;
#
my $res = "";
my $grp = "";
my $sys = "";
my $clus = "";
my $hoursago = 0;
my $help = "";
my $options = "";
&usage_message() if (!defined $ARGV[0]);
$options = GetOptions ('res|r:s' => \$res,
'grp|g:s' => \$grp,
'sys|s:s' => \$sys,
'clus|c:s' => \$clus,
'hoursago|h=i' => \$hoursago,
'help' => \$help);
#
# Print the usage message if invalid options
#
&usage_message() unless ($options);
#
# Print the usage message if requested
#
&usage_message() if ($help);
#
# Check that the object exists in the cluster
#
my @resout;
my @grpout;
my @sysout;
my @clusout;
if ( ${hoursago} < 1 ) {
# Must specify a value greter than 0 for hoursago
print("$me: Must specify an integer greater than 0 for hoursago\n");
exit 1;
} elsif ( ${res} ne '' ) {
# Check that resource $res exists
@resout = `$vcs_home/bin/hares -display "${res}" > /dev/null 2>&1 `;
if ( $? != 0 ) {
print("$me: Resource ${res} does not exist\n");
exit 1;
}
} elsif ( $grp ne '' ) {
# Check that group $grp exists
@grpout = `$vcs_home/bin/hagrp -display "${grp}" >/dev/null 2>&1`;
if ( $? != 0 ) {
print("$me: Group ${grp} does not exist\n");
exit 1;
}
} elsif ( $sys ne '' ) {
# Check that system $sys exists
@sysout = `$vcs_home/bin/hasys -display "${sys}" >/dev/null 2>&1`;
if ( $? != 0 ) {
print("$me: System ${sys} does not exist\n");
exit 1;
}
} elsif ( $clus ne '' ) {
# Check that cluster $clus exists
@clusout = `$vcs_home/bin/haclus -display "${clus}" >/dev/null 2>&1`;
if ( $? != 0 ) {
print("$me: Cluster ${clus} does not exist\n");
exit 1;
}
} else {
# No valid opton specified
print("$me: No valid option specified\n");
exit 1;
}
#
# Work out the time
#
my $secondsago = $hoursago * 3600;
my $currenttime = time;
my $starttime = $currenttime - $secondsago;
#
# Open the engine_A.log file. The engine_A.log is of the form:
# YYYY/MM/DD HH:MM:SS | VCS | Severity | UMI | Message Text
#
my $line="";
my $date="";
my $time="";
my $errorcode="";
my $errorstring="";
my @var;
my $enginelog = "/var/VRTSvcs/log/engine_A.log";
open( englogfile, "< $enginelog" ) || die ("\nerror: Failed to open $enginelog for reading ($!)\n\n");
my @logcontents = <englogfile>;
close(englogfile);
foreach $line (@logcontents) {
chomp($line);
if ($line =~ /^\d{4}\/\d{2}\/\d{2}/) {
# Line starts with date so is valid
@var = split(/\s+/, $line);
$date = $var[0];
$time = $var[1];
$errorcode = $var[4];
$errorstring = join(" ", @var[5..$#var]);
# Convert date and time to epoch time
my ($hours,$mins,$secs) = split /:/,$time;
my ($years,$months,$days) = split /\//,$date;
$months--;
my $enginelogtime = timelocal($secs,$mins,$hours,$days,$months,$years);
if ( $enginelogtime ge $starttime ) {
my $log_error = "";
if ( ${res} ne '' ) {
if ( $errorstring =~ /.$res./ ) {
print("@var \n");
}
} elsif ( $grp ne '' ) {
if ( $errorstring =~ /.$grp./ ) {
print("@var \n");
}
} elsif ( $sys ne '' ) {
if ( $errorstring =~ /.$sys./ ) {
print("@var \n");
}
} elsif ( $clus ne '' ) {
if ( $errorstring =~ /.$clus./ ) {
print("@var \n");
}
} else {
# No valid opton specified
print("$me: No valid option specified\n");
exit 1;
}
}
}
}
#
# Sub - usage message
#
sub usage_message {
print "\n";
print "Usage: $me -help\n";
print " $me -r <resource> | -g <group> | -s <system> | -c <cluster> -h <hours>\n\n";
print "-r <resource> Resource name\n";
print "-g <group> Group name\n";
print "-s <system> System name\n";
print "-c <cluster> Cluster name\n";
print "-h <hoursago> Number of hours to look back in the engine_A.log file\n";
print " Must be a value greater than 0\n";
exit 0;
} Download Filed Under:
Comments 3 Comments • Jump to latest comment
hi mark
very good script
really helpful for me
thanks
kuldeeep
Hi,
I thought it would be helpful to be able to specify the log file location.
Here is what I added:
And here the full script:
are you trying to capture the history for a specific object?
Thanks and Warm Regards,
Amit Rangari
If this post helped you resolving the issue, please mark it as solution. _____________________________________________________________________________
Would you like to reply?
Login or Register to post your comment.