#!/opt/p7perl/bin/perl 

#  /opt/p7perl/bin/perl # for c.08

use Cwd;

#$WORKDIR=cwd();
$WORKDIR="/h/bmetzger/s/tm";

$RAW_DATA="/var/opt/a7trafmon/file/export/ah/01/measdata022.txt";
#$RAW_DATA="${WORKDIR}/testfile";
$REPORT_FILE="${WORKDIR}/tm_report.out";

sub parseit {

   open (INFILE, "<$RAW_DATA") || die "Cannot open $file:  $!";
   open (REPORT, ">$REPORT_FILE") ; 

   while (defined ($line = <INFILE>)) {

# pg 546 TM operator manual
# "238-211-0<0>5-59-13","07/04/16:01:14:57","07/04/16:01:24:42","F",15,0.17,0.17,4095000.00,0.04,0.96

# a- Network Entity String
# b- Aggregation Period Start Time (when tm_get_site_data is run)
# c- Aggregation Period Stop Time
# d- Result Type Identifier.
# e- Measurement Update Frequency (in seconds)
# f- Aggregated Actual Measurement Result
# g- Aggregated Normalized Measurement Result
# h- Divisior
# i- Minimum value
# j- Maximum value

# TM calculates the load against the link capacity as specified in the etr
# For example:
#    if we had 2 x56kb links
#    2 x 56kb links measured for 10 minutes(600s) =  112kb x 600sec = 67.2 Mbit/sec

#    TM counts the MSUM-^Rs seen in 600sec and then does a division thus
#    ( this assumes a max length of 272 octects for an MSU)
#    (number MSUM-^Rs seen)/ 67.2 = link load 

           ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j) = split (/,/, $line);  #split on ","

           if ($j >=.97 ) {print REPORT "$line" };

   } # end of searching each line in all files for values
     close (INFILE);
} # end of parseit

parseit(); 

