File: //var/opt/OV/bin/instrumentation/infraspi_collector.pl
#! /usr/bin/perl
###############################
#
# @(#)HP Operations Smart Plug-ins for Infrastructure 11.14.014 06/07/14
#
###############################
use warnings;
my $OUTPUT_DIR_PATH;
my $OS = $^O;
if($^O eq qw/MSWin32/)
{
create_dir_win();
infraspi_data_collect_win();
exit;
}
else
{
$OUTPUT_DIR_PATH = "/var/opt/OV/tmp/oa_data";
infraspi_data_collect_linux();
}
sub create_dir_win{
$OUTPUT_DIR_PATH = $ENV{'ovdatadir'}."tmp"."\\oa_data"."\\infraspi_data";
use File::Path qw(mkpath rmtree);
if( -d "$OUTPUT_DIR_PATH")
{
print "INFO: The Output directory already exists, removing the existing directory\n";
rmtree("$OUTPUT_DIR_PATH");
print "INFO: Infraspi_data directory removed successfully\n";
}
print "INFO: Creating output directory.\n";
mkpath("$OUTPUT_DIR_PATH");
}
sub infraspi_data_collect_win{
my $OS = $^O;
#Creating a logfile Infraspi_log.txt
my $logfile = $OUTPUT_DIR_PATH."\\"."Infraspi_log.txt";
print "\n Collecting Infraspi related information \n";
print "======================================== \n";
print "INFO: Copying Infraspi.txt file to output directory $OUTPUT_DIR_PATH \n";
`copy $ENV{'OvDataDir'}log\\Infraspi.txt $OUTPUT_DIR_PATH`;
$Agtrep= $OUTPUT_DIR_PATH."\\agtrep_data";
if( -d "$Agtrep")
{
print "INFO: The agtrep directory already exists \n";
}
else
{
print "INFO: Creating the agtrep_data directory \n";
`mkdir $Agtrep`;
}
print "INFO: Copying the Agtrep xml files to output directory $OUTPUT_DIR_PATH \n";
`copy $ENV{'ovdatadir'}tmp\\agtrep\\*.* $OUTPUT_DIR_PATH\\agtrep_data`;
`copy $ENV{'ovdatadir'}datafiles\\agtrep.* $OUTPUT_DIR_PATH\\agtrep_data`;
#Checking if the logfile Infraspi_log.txt already exists
if ( -e $logfile)
{
print "INFO: Previous logfile Infraspi_log.txt already exists ...\n";
unlink("$logfile");
print "INFO: Old log file Infraspi_log.txt deleted successfully ...\n";
}
open (FILE, ">>$logfile") or die "unable to open the file\n";
my $header = "*******************Start of Infraspi log file containing output of commands**********\
-------Output of what.pl file-------\n";
print FILE $header;
close (FILE);
#Collecting the output of what.pl
print "INFO: Collecting the output of what.pl into $logfile \n";
system("$ENV{'ovdatadir'}bin\\instrumentation\\ispi-ovperl what.pl >> $logfile");
#Collecting the ROLE
print "INFO: Checking if the node is Standalone or Guest \n";
$ENV{CODAMAGIC} = qw/0x05201993/;
open (ROLE, "ovcodautil -ds scope -o CONFIGURATION -m GBL_LS_ROLE -last -flat| findstr GBL_LS_ROLE |") or die "Unable to fetch configuration information\n";
my $role;
while (<ROLE>) {
chomp;
my @fields = split (":",$_);
$role = $fields[1];
}
my $stand_guest = 0;
#Checking for Standalone or Guest Machines
if ($role =~ m/stand/i)
{
$stand_guest=1;
print "INFO: The node is Standalone node.\n";
}
elsif($role =~ m/guest/i)
{
$stand_guest=1;
print "INFO: The node is a Guest node.\n";
}
else
{
print "INFO: The node is a Host.\n";
}
if ($stand_guest)
{
open ( SHOW, "ovcodautil -showds |");
while (<SHOW>)
{
chomp $_;
next if $_ =~ /NumDataSources/;
if ($_ =~ /CODA/)
{
if ($?)
{
print "WARN: CODA data source does not exist \n";
open (FILE, ">>$logfile") or die "unable to open the file\n";
print FILE "\n CODA data source does not exist \n";
close (FILE);
}
else
{
print "INFO: Dumping the output of CODA datasource into $logfile ..\n";
open (FILE, ">>$logfile") or die "unable to open the file\n";
print FILE "-------Output of CODA dump-------\n";
close (FILE);
system("ovcodautil -dumpcoda -flat -last >>$logfile");
}
}
else
{
if ($?)
{
print "WARN: $_ data source does not exist \n";
open (FILE, ">>$logfile") or die "unable to open the file\n";
print FILE "\n $_ data source does not exist \n";
close (FILE);
}
else
{
print "INFO: Dumping the output of $_ datasource into $logfile ..\n";
open (FILE, ">>$logfile") or die "unable to open the file\n";
print FILE "-------Output of $_ dump-------\n";
close (FILE);
system("ovcodautil -ds $_ -flat -last >>$logfile");
}
}
}
close (SHOW);
}
else
{
open ( SHOW, "ovcodautil -showds |");
while (<SHOW>)
{
chomp $_;
next if $_ =~ /NumDataSources/;
if ($_ =~ /CODA/)
{
if ($?)
{
print "WARN: CODA data source does not exist \n";
open (FILE, ">>$logfile") or die "unable to open the file\n";
print FILE "\n CODA data source does not exist \n";
close (FILE);
}
else
{
print "INFO: Dumping the output of CODA datasource into $logfile ..\n";
open (FILE, ">>$logfile") or die "unable to open the file\n";
print FILE "-------Output of CODA dump-------\n";
close (FILE);
system("ovcodautil -dumpcoda -flat -last >>$logfile");
}
}
else
{
if ($?)
{
print "WARN: $_ data source does not exist \n";
open (FILE, ">>$logfile") or die "unable to open the file\n";
print FILE "\n $_ data source does not exist \n";
close (FILE);
}
else
{
print "INFO: Dumping the output of $_ datasource into $logfile ..\n";
open (FILE, ">>$logfile") or die "unable to open the file\n";
print FILE "-------Output of $_ dump-------\n";
close (FILE);
system("ovcodautil -ds $_ -flat -last >>$logfile");
}
}
}
close (SHOW);
#Collecting Logical data source
system("ovcodautil -obj | findstr SCOPE | findstr LOGICAL ");
if ($?)
{
print "WARN: LOGICAL object doesnt exist in SCOPE data source \n";
print "INFO: \n LOGICAL object doesnt exist in SCOPE data source \n";
}
else
{
print "INFO: Dumping the SCOPE data source for object LOGICAL into $logfile \n";
open (FILE, ">>$logfile") or die "unable to open the file\n";
print FILE "\n-------Output of LOGICAL dumpds-------\n";
close (FILE);
system("ovcodautil -ds SCOPE -o LOGICAL -flat -last >>$logfile");
}
}
close (ROLE);
# if this is a cluster node, get the dumpds of CISPI
system("ovcodautil -showds | findstr CISPI");
if(!$?)
{
print "INFO: Dumping CISPI data source into $logfile \n";
open (FILE, ">>$logfile") or die "unable to open the file\n";
print FILE "\n ------------Output of CISPI data source---------\n";
close (FILE);
system("ovcodautil -ds CISPI -flat -last >>$logfile");
}
open (FILE, ">>$logfile") or die "unable to open the file\n";
print FILE "\n*****************End of log file*******************\n";
close (FILE);
}
sub infraspi_data_collect_linux{
my $OS = $^O;
if ($OS !~ /aix/)
{
$ENV{'PATH'} = "$ENV{'PATH'}:/opt/OV/bin:/opt/perf/bin:/opt/OV/bin/OpC:/opt/OV/bin/OpC/install:/opt/OV/bin/OpC/utils";
}
else
{
$ENV{'PATH'} = "$ENV{'PATH'}:/usr/lpp/OV/bin:/opt/perf/bin:/usr/lpp/OV/bin/OpC:/usr/lpp/OV/bin/OpC/install:/usr/lpp/OV/bin/OpC/utils";
}
print "\n Collecting Infraspi related information \n";
print "======================================== \n";
print "INFO: Copying Infraspi.txt file to output directory $OUTPUT_DIR_PATH/infraspi_data ...\n";
$OUTPUT_DIR_PATH = $OUTPUT_DIR_PATH."/"."infraspi_data";
`cp /var/opt/OV/log/Infraspi.txt $OUTPUT_DIR_PATH`;
`mkdir -p $OUTPUT_DIR_PATH/agtrep_data`;
print "INFO: Copying the Agtrep xml files to output directory $OUTPUT_DIR_PATH/agtrep_data ...\n";
`cp -r /var/opt/OV/tmp/agtrep/*.* $OUTPUT_DIR_PATH/agtrep_data`;
`cp -r /var/opt/OV/datafiles/agtrep.* $OUTPUT_DIR_PATH/agtrep_data`;
#Creating a logfile Infraspi_log.txt
my $logfile = $OUTPUT_DIR_PATH."/"."Infraspi_log.txt";
#Checking if the logfile Infraspi_log.txt already exists
if ( -e $logfile)
{
print "INFO: Previous logfile Infraspi_log.txt already exists ...\n";
unlink("$logfile");
print "INFO: Old log file Infraspi_log.txt deleted successfully ...\n";
}
open (FILE, ">>$logfile") or die "unable to open the file\n";
my $header = "*******************Start of Infraspi log file containing output of commands**********\
-------Output of what.pl file-------\n";
print FILE $header;
#Collecting the output of what.pl
print "INFO: Collecting the output of what.pl into $logfile ...\n";
system("/var/opt/OV/bin/instrumentation/ispi-ovperl what.pl >>$logfile");
#Collecting the ROLE
print "INFO: Checking if the node is Standalone, Guest, Proxy or Peer ...\n";
$ENV{CODAMAGIC} = qw/0x05201993/;
open (ROLE, "ovcodautil -ds scope -o CONFIGURATION -m GBL_LS_ROLE -last -flat| grep GBL_LS_ROLE | cut -d\":\" -f2|") or die "Unable to fetch configuration information\n";
my $role;
while (<ROLE>) {
chomp $_;
$_ =~ s/ //g;
$role = $_;
}
my $stand_guest = 0;
#Checking for Standalone or Guest Machines
if (lc($role) eq "stand" )
{
$stand_guest=1;
print "INFO: The node is Standalone node ...\n";
}
elsif(lc($role) eq "guest")
{
$stand_guest=1;
print "INFO: The node is a Guest node ...\n";
}
elsif( lc($role) eq "proxy" )
{
print "INFO: The node is a Proxy node ...\n";
}
elsif( lc($role) eq "peer" )
{
$stand_guest=1;
print "INFO: The node is a Peer LPAR ...\n";
}
else
{
print "INFO: The node is a Host ...\n";
}
if ($stand_guest)
{
open ( SHOW, "ovcodautil -showds |");
while (<SHOW>)
{
chomp $_;
next if $_ =~ /NumDataSources/;
if ($_ =~ /CODA/)
{
print "INFO: Dumping the output of CODA datasource into $logfile ..\n";
print FILE "-------Output of CODA dump-------\n";
open (CODA,"ovcodautil -dumpcoda -flat -last 2>&1 | tee |");
my @CODA_CONTENT = <CODA>;
if ( $CODA_CONTENT[0] =~/Cannot find requested object/)
{
print "WARN: No collection for the CODA datasource \n";
print FILE "No collection for the CODA datasource \n";
}
else
{
print FILE @CODA_CONTENT;
}
close (CODA);
}
else
{
print "INFO: Dumping the $_ data source into $logfile ...\n";
print FILE "-------Output of $_ dumpds-------\n";
open (DUMP,"ovcodautil -ds $_ -flat -last 2>&1 | tee |");
my @DUMP_CONTENT = <DUMP>;
if ( $DUMP_CONTENT[0] =~/Cannot find requested object/)
{
print "WARN: No collection for the $_ datasource \n";
print FILE "No collection for the $_ datasource \n";
}
else
{
print FILE @DUMP_CONTENT;
}
close (DUMP);
}
}
close (SHOW);
}
else
{
open ( SHOW, "ovcodautil -showds |");
while (<SHOW>)
{
chomp $_;
next if $_ =~ /NumDataSources/;
if ($_ =~ /CODA/)
{
print "INFO: Dumping the output of CODA datasource into $logfile ..\n";
print FILE "-------Output of CODA dump-------\n";
open (CODA,"ovcodautil -dumpcoda -flat -last 2>&1 | tee |");
my @CODA_CONTENT = <CODA>;
if(grep $_ =~ /Cannot find requested object/, @CODA_CONTENT)
{
print "WARN: No collection for the CODA datasource \n";
print FILE "No collection for the CODA datasource \n";
}
else
{
print FILE @CODA_CONTENT;
}
close (CODA);
}
else
{
next if $_ =~ /NumDataSources/;
print "INFO: Dumping the $_ data source into $logfile ...\n";
print FILE "-------Output of $_ dumpds-------\n";
open (DUMP,"ovcodautil -ds $_ -flat -last 2>&1 | tee |");
my @DUMP_CONTENT = <DUMP>;
if(grep $_ =~ /Cannot find requested object/, @DUMP_CONTENT)
{
print "WARN: No collection for the $_ datasource \n";
print FILE "No collection for the $_ datasource \n";
}
else
{
print FILE @DUMP_CONTENT;
}
close (DUMP);
}
}
close (SHOW);
#Collecting Logical data source
system("ovcodautil -obj | grep SCOPE | grep LOGICAL ");
if ($?)
{
print "WARN: LOGICAL object doesnt exist in SCOPE data source ...\n";
print FILE "\n LOGICAL object doesnt exist in SCOPE data source ...\n";
}
else
{
print "INFO: Dumping the SCOPE data source for object LOGICAL into $logfile ...\n";
print FILE "-------Output of LOGICAL dumpds-------\n";
open (LOGICAL,"ovcodautil -ds SCOPE -o LOGICAL -flat -last 2>&1 | tee |");
my @LOGICAL_CONTENT = <LOGICAL>;
if ( $LOGICAL_CONTENT[0] =~/Cannot find requested object/)
{
print "WARN: No collection for the LOGICAL datasource \n";
print FILE "No collection for the LOGICAL datasource \n";
}
else
{
print FILE @LOGICAL_CONTENT;
}
close (LOGICAL);
}
}
#Special case for Role as proxy
if ( lc($role) eq "proxy")
{
#Checking if the node is vMA or VA
open (OACORESTATUS, "ovc | grep oacore |") or die ("unable to get ovc status");
my $OACOREFlag=0;
while ( <OACORESTATUS> )
{
my @Items = split/\s+/;
if($Items[0] eq "oacore" and $Items[$#Items] eq "Running")
{
$OACOREFlag=1;
last;
}
}
close OACORESTATUS;
if($OACOREFlag == 1)
{
print "INFO: The node is a HP OAVA ...\n";
print "INFO: Dumping the output of OACONFIG into the $logfile ...\n";
print FILE "\n--------Output of oaconfig--------\n";
system("oaconfig -lt >>$logfile");
}
else
{
print "INFO: The node is a vMA ...\n";
my $vmaversion;
#Below check is for vMA greater than equals to 4.1
if (-e "/etc/vma-release")
{
$vmaversion = `cat /etc/vma-release | grep vMA | cut -d" " -f2 | cut -d. -f1,2`;
print "INFO: The vMA node is vMA".$vmaversion."\n";
print FILE "The vMA node is vMA".$vmaversion."\n";
print "INFO: Kindly wait for some time, dumping the output of vifpTargetCheck into $logfile ...\n";
print FILE "------------Output of vifpTargetCheck------------\n";
system("/var/opt/OV/bin/instrumentation/vifpTargetCheck.pl >>$logfile");
print "INFO: Dumping the output of vifp list into $logfile ...\n";
print FILE "------------Output of vifp listservers-----------\n";
system("vifp listservers >>$logfile");
if ( $vmaversion >= 5.1)
{
#Check if the vMA is greater than equals to 5.1,then whether all the ovc services running under root or NPU(vi-admin) mode
print "INFO: Dumping the output of ovc services running in NPU mode into $logfile ...\n";
print FILE "------------Output of ovc services-----------\n";
system("ps -eaf | grep ovc >>$logfile");
}
}
}
}
close (ROLE);
# if this is a cluster node, get the dumpds of CISPI
system("ovcodautil -showds | grep CISPI");
if(!$?)
{
print "INFO: Dumping CISPI data source into $logfile ...\n";
print FILE "\n------------Output of CISPI data source------------\n";
open (CISPI,"ovcodautil -ds CISPI -flat -last 2>&1 | tee |");
my @CISPI_CONTENT = <CISPI>;
if ( $CISPI_CONTENT[0] =~/Cannot find requested object/)
{
print "WARN: No collection for the CISPI datasource \n";
print FILE "No collection for the CISPI datasource \n";
}
else
{
print FILE @CISPI_CONTENT;
}
close (CISPI);
}
print FILE "\n*****************End of log file*******************\n";
close (FILE);
}