Using this code segment you can convert the TraceCounters.log file into .cvs files to import into a spread sheet.
Code:
#!/usr/bin/perl
use strict;
#---------------------------------------------------------------------------
# ParseTraceCounters
# Separate the TraceCounters.log file, produced by a NerveCenter
# Server, into separate spreadsheet files.
#
# Created for NerveCenter v5.1 by LogMatrix, Marlborough MA. 01752 USA.
# Copyright (C) 2011. LogMatrix, Inc.
#
# This script may be freely modified as long as this header is retained.
#
#---------------------------------------------------------------------------
# Usage:
# From the directory where NerveCenter's TraceCounters.log file is found:
# C:> Parse_TraceCounters.pl [append]
# % Parse_TraceCounters.pl [append]
#
# If "append" is given as the argument, the produced spreadsheet files
# are not reset. Otherwise, the spreadsheet files are re-created and
# any/all prior data is lost.
#
#---------------------------------------------------------------------------
# Access TraceCounters.log file or exit.
my $FH;
my $UNIX_LOG_FILE = "./TraceCounters.log";
my $Windows_Log_File = ".\\TraceCounters.log";
# The Default operating system for the script is UNIX. Manually edit for Windows
# We should add a switch to the program (UNIX or Windows)
my $LogFile = $UNIX_LOG_FILE;
# my $LogFile = $Windows_Log_File;
open(FH,$LogFile) or die "Cannot open $LogFile\n";
#---------------------------------------------------------------------------
# Look for optional "append"
my $append = 0;
my $arg = shift;
if ( defined $arg ) {
if ( $arg eq "append" ) {
$append = 1;
} else {
print "Usage:\n\tParse_TraceCounters.pl [append]\n";
exit 0;
}
}
#---------------------------------------------------------------------------
# Prepare spreadsheet handles
my $RE; # Resync.csv
my $AC; # Actions.csv
my $CL; # Client.csv
my $AR; # Alarms.csv
my $TRI;# Triggers.csv
my $OPC;# OPC.csv
my $IN; # Informs.csv
my $SN; # SNMP.csv
my $IC; # ICMP.csv
my $TR; # Traps.csv
my $DB; # DB.csv
my $PR; # Protocol.csv
my $HP; # HPOV.csv
#---------------------------------------------------------------------------
# Open/Initialize spreadsheets
# Give each spreadsheet a header row if creating it.
# Open in append mode if requested, otherwise re-create file.
sub openResync_csv {
if ( $append && open( RE, "<Resync.csv" ) ) {
close( RE );
open( RE, ">>Resync.csv" );
} else {
open( RE, ">Resync.csv" );
print RE "Date/Time,Received,Added,Updated,Deleted\n";
}
}
sub updateResync_csv {
my $line = shift;
chomp $line;
$line =~ s/=/,/g;
$line =~ s/\s-\s/,/g;
$line =~ s/:\s/,/g;
my @cells=split('\,', $line);
print RE "$cells[0],$cells[3],$cells[5],$cells[7],$cells[9]\n";
}
openResync_csv;
sub openActions_csv {
if ( $append && open( AC, "<Actions.csv" ) ) {
close( AC );
open( AC, ">>Actions.csv" );
} else {
open( AC, ">Actions.csv" );
print AC "Date/Time,Requested,Completed,Queued\n";
}
}
sub updateActions_csv {
my $line = shift;
chomp $line;
$line =~ s/=/,/g;
$line =~ s/\s-\s/,/g;
$line =~ s/:\s/,/g;
my @cells=split('\,', $line);
print AC "$cells[0],$cells[3],$cells[5],$cells[7]\n";
}
openActions_csv;
sub openClient_csv {
if ( $append && open( AC, "<Client.csv" ) ) {
close( CL );
open( CL, ">>Client.csv" );
} else {
open( CL, ">Client.csv" );
print CL "Date/Time,Connections,Messages Sent\n";
}
}
sub updateClient_csv {
my $line = shift;
chomp $line;
$line =~ s/=/,/g;
$line =~ s/\s-\s/,/g;
$line =~ s/:\s/,/g;
my @cells=split('\,', $line);
print CL "$cells[0],$cells[3],$cells[5]\n";
}
openClient_csv;
sub openAlarms_csv {
if ( $append && open( AL, "<Alarms.csv" ) ) {
close( AL );
open( AL, ">>Alarms.csv" );
} else {
open( AL, ">Alarms.csv" );
print AL "Date/Time,Transitioned\n";
}
}
sub updateAlarms_csv {
my $line = shift;
chomp $line;
$line =~ s/=/,/g;
$line =~ s/\s-\s/,/g;
$line =~ s/:\s/,/g;
my @cells=split('\,', $line);
print AL "$cells[0],$cells[3]\n";
}
openAlarms_csv;
sub openTriggers_csv {
if ( $append && open( TRI, "<Triggers.csv" ) ) {
close( TRI );
open( TRI, ">>Triggers.csv" );
} else {
open( TRI, ">Triggers.csv" );
print TRI "Date/Time,Processed,Poll Fired,OPC Mask Fired,Mask Fired,Action Fired\n";
}
}
sub updateTriggers_csv {
my $line = shift;
chomp $line;
$line =~ s/=/,/g;
$line =~ s/\s-\s/,/g;
$line =~ s/:\s/,/g;
$line =~ s/\.\s/,/g;
my @cells=split('\,', $line);
print TRI "$cells[0],$cells[3],$cells[5],$cells[7],$cells[9],$cells[11]\n";
}
openTriggers_csv;
sub openOPC_csv {
if ( $append && open( OPC, "<OPC.csv" ) ) {
close( OPC );
open( OPC, ">>OPC.csv" );
} else {
open( OPC, ">OPC.csv" );
print OPC "Date/Time,Received,Processed\n";
}
}
sub updateOPC_csv {
my $line = shift;
chomp $line;
$line =~ s/=/,/g;
$line =~ s/\s-\s/,/g;
$line =~ s/:\s/,/g;
$line =~ s/\.\s/,/g;
my @cells=split('\,', $line);
print OPC "$cells[0],$cells[3],$cells[5]\n";
}
openOPC_csv;
sub openInforms_csv {
if ( $append && open( IN, "<Informs.csv" ) ) {
close( IN );
open( IN, ">>Informs.csv" );
} else {
open( IN, ">Informs.csv" );
print IN "Date/Time,Received,Processed,OV Received,OV Pending,OV Sent,PA Requested,PA Send,OPC Requested,OPC Sent\n";
}
}
sub updateInforms_csv {
my $line = shift;
chomp $line;
$line =~ s/=/,/g;
$line =~ s/\s-\s/,/g;
$line =~ s/:\s/,/g;
$line =~ s/\.\s/,/g;
my @cells=split('\,', $line);
print IN "$cells[0],$cells[3],$cells[5],$cells[7],$cells[9],$cells[11],$cells[13],$cells[15],$cells[17],$cells[19]\n";
}
openInforms_csv;
sub openSNMP_csv {
if ( $append && open( SN, "<SNMP.csv" ) ) {
close( SN );
open( SN, ">>SNMP.csv" );
} else {
open( SN, ">SNMP.csv" );
print SN "Date/Time,Requests,Responses,Errors,Pending,Retries,Timeouts,Dropped\n";
}
}
sub updateSNMP_csv {
my $line = shift;
chomp $line;
$line =~ s/=/,/g;
$line =~ s/\s-\s/,/g;
$line =~ s/:\s/,/g;
my @cells=split('\,', $line);
print SN "$cells[0],$cells[3],$cells[5],$cells[7],$cells[9],$cells[11],$cells[13],$cells[15]\n";
}
openSNMP_csv;
sub openICMP_csv {
if ( $append && open( IC, "<ICMP.csv" ) ) {
close( IC );
open( IC, ">>ICMP.csv" );
} else {
open( IC, ">ICMP.csv" );
print IC "Date/Time,Requests,Responses,Matched,Errors,Pending,Retries,Timeouts,Dropped\n";
}
}
sub updateICMP_csv {
my $line = shift;
chomp $line;
$line =~ s/=/,/g;
$line =~ s/\s-\s/,/g;
$line =~ s/:\s/,/g;
my @cells=split('\,', $line);
print IC "$cells[0],$cells[3],$cells[5],$cells[7],$cells[9],$cells[11],$cells[13],$cells[15],$cells[17]\n";
}
openICMP_csv;
sub openTraps_csv {
if ( $append && open( TR, "<Traps.csv" ) ) {
close( TR );
open( TR, ">>Traps.csv" );
} else {
open( TR, ">Traps.csv" );
print TR "Date/Time,Received,Dropped,Errors,Unused\n";
}
}
sub updateTraps_csv {
my $line = shift;
chomp $line;
$line =~ s/=/,/g;
$line =~ s/\s-\s/,/g;
$line =~ s/:\s/,/g;
my @cells=split('\,', $line);
print TR "$cells[0],$cells[3],$cells[5],$cells[7],$cells[9]\n";
}
openTraps_csv;
sub openDB_csv {
if ( $append && open( DB, "<DB.csv" ) ) {
close( DB );
open( DB, ">>DB.csv" );
} else {
open( DB, ">DB.csv" );
print DB "Date/Time,Completed,Pending,Connections Restored,Connections Lost\n";
}
}
sub updateDB_csv {
my $line = shift;
chomp $line;
$line =~ s/=/,/g;
$line =~ s/\s-\s/,/g;
$line =~ s/:\s/,/g;
my @cells=split('\,', $line);
print DB "$cells[0],$cells[3],$cells[5],$cells[7],$cells[9]\n";
}
openDB_csv;
sub openProtocol_csv {
if ( $append && open( PR, "<Protocol.csv" ) ) {
close( PR );
open( PR, ">>Protocol.csv" );
} else {
open( PR, ">Protocol.csv" );
print PR "Date/Time,Timer Count\n";
}
}
sub updateProtocol_csv {
my $line = shift;
chomp $line;
$line =~ s/=/,/g;
$line =~ s/\s-\s/,/g;
$line =~ s/:\s/,/g;
my @cells=split('\,', $line);
print PR "$cells[0],$cells[3]\n";
}
openProtocol_csv;
sub openHPOV_csv {
if ( $append && open( HP, "<HPOV.csv" ) ) {
close( HP );
open( HP, ">>HPOV.csv" );
} else {
open( HP, ">HPOV.csv" );
print HP "Date/Time,Traps Received\n";
}
}
sub updateHPOV_csv {
my $line = shift;
chomp $line;
$line =~ s/=/,/g;
$line =~ s/\s-\s/,/g;
$line =~ s/:\s/,/g;
my @cells=split('\,', $line);
print HP "$cells[0],$cells[3]\n";
}
openHPOV_csv;
#---------------------------------------------------------------------------
# Process TraceCounters.log file.
while(<FH>) {
if($_ =~ /Resync/) { updateResync_csv($_); }
elsif($_ =~ /Actions/) { updateActions_csv($_); }
elsif($_ =~ /Client/) { updateClient_csv($_); }
elsif($_ =~ /Alarms/) { updateAlarms_csv($_); }
elsif($_ =~ /Triggers/) { updateTriggers_csv($_); }
elsif($_ =~ /OPC/) { updateOPC_csv($_); }
elsif($_ =~ /Informs/) { updateInforms_csv($_); }
elsif($_ =~ /SNMP/) { updateSNMP_csv($_); }
elsif($_ =~ /ICMP_polls/) { updateICMP_csv($_); }
elsif($_ =~ /Trap/) { updateTraps_csv($_); }
elsif($_ =~ /DB/) { updateDB_csv($_); }
elsif($_ =~ /DoTimer/) { updateProtocol_csv($_); }
elsif($_ =~ /HP/) { updateHPOV_csv($_); }
}
#---------------------------------------------------------------------------
# Close spreadsheets and log file
close(RE);
close(AC);
close(CL);
close(AL);
close(TRI);
close(OPC);
close(IN);
close(SN);
close(IC);
close(TR);
close(DB);
close(PR);
close(HP);
close(FH);
#---------------------------------------------------------------------------
# ###