[nmstools-cvs] src/bin isis_spflog_corr.pl.in,NONE,1.1
Brought to you by:
ssinyagin
|
From: Michel H. <mi...@us...> - 2002-12-17 08:39:03
|
Update of /cvsroot/nmstools/src/bin
In directory sc8-pr-cvs1:/tmp/cvs-serv14784
Added Files:
isis_spflog_corr.pl.in
Log Message:
initial import
--- NEW FILE: isis_spflog_corr.pl.in ---
#!%%PERL%%
#
# NMSTOOLS -- NMS Helper Tools
# $Id: isis_spflog_corr.pl.in,v 1.1 2002/12/17 08:38:55 mihahn Exp $
#
# Author: Michel Hahne <morangie at bluemail dot ch>
# Copyright (C) 2001, 2002 Fault Correction and Maintenance, Cablecom GmbH
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Revision history:
# $Log: isis_spflog_corr.pl.in,v $
# Revision 1.1 2002/12/17 08:38:55 mihahn
# initial import
#
# Revision 1.0
use Time::Local;
require '%%NMSTOOLS_HOME%%/lib/lib_nmstools.pl';
%wotag = ("Mon",0,"Tue",1,"Wed",2,"Thu",3,"Fri",4,"Sat",5,"Sun",6);
%monat = ("Jan",0,"Feb",1,"Mar",2,"Apr",3,"May",4,"Jun",5,"Jul",6,
"Aug",7,"Sep",8,"Oct",9,"Nov",10,"Dec",11);
my $nodelist = $nms_config{'env'}{'DATA'} . '/mpls/nodelist';
$spflogoutfile = $nms_config{'env'}{'DATA'} . '/mpls/spflogarchive';
$spflogdir = $nms_config{'env'}{'DATA'} . '/mpls/spflogs';
$time = localtime;
$ref=0;
my @data;
opendir(DIR, $spflogdir) || die "can't opendir $spflogdir: $!";
while( $fname = readdir(DIR) )
{
$filename = $spflogdir . '/' . $fname;
next if not -r $filename;
open( IN, $filename ) || die "can't open file $filename: $!";
$state = 0;
$hostname = $fname;
if ($fname =~ /\S+\d+/)
{
$ref =+ $ref;
}
$hostlist{$hostname}=1;
@list = <IN>;
close IN;
for (@list)
{
if (/^\s*(\d+):(\d+):(\d+).+CET\s+(\w+)\s+(\w+)\s+(\d+)\s+(\d+)\s*/)
{
$h=$1; $m=$2; $s=$3;
$wd=$wotag{$4}; $mt=$monat{$5}; $d=$6; $y=$7;
# 15:33:26.846 CET Wed Nov 27 2002
}
# 10:26:49 24 323 2 mlsBSM002.00-00 TLVCONTENT
elsif (/^\s*(\d+\S+\d+\S+\d*)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(\w+\s*\w+)/)
{
$zeitspanne = $1;
$Duration=$2;
$Nodes=$3;
$Count=$4;
$Last_trigger=$5;
$Triggers = $6;
if ($zeitspanne =~ /(\d+):(\d+):(\d+)/)
{
$tage=0;
$std=$1;
$min=$2;
$sek=$3;
}
elsif ($zeitspanne =~ /(\d+)d(\d+)h/)
{
$tage=$1;
$std=$2;
$min=0;
$sek=0;
}
$tm=timelocal($s, $m, $h, $d, $mt, $y)
- $tage * 24 * 60 * 60 -
$std * 60 * 60 - $min * 60 - $sek;
$timestamp=$tm;
push(@data, [$tm , $Duration, $Nodes, $Count, $Last_trigger,
$Triggers, $hostname, 0 ]);
}
}
}
close DIR;
# summarizing events within a time period of 10 seconds on the same box
@temp = @data;
$dummy=-1;
foreach my $datum (@temp)
{
if ($dummy != -1)
{
if((($datum->[0] - $dummy->[0]) <=10) && ($datum->[5] eq $dummy->[5]) &&
($datum->[6] eq $dummy->[6]))
{
$datum->[3] += $dummy->[3];
$datum->[0] = $dummy->[0];
$dummy->[7] = 1;
}
}
$dummy=$datum;
}
foreach $datum (@temp)
{
if($datum->[7] != 1)
{
push(@temp2, [$datum->[0], $datum->[1],
$datum->[2], $datum->[3], $datum->[4],
$datum->[5], $datum->[6], $datum->[7]]);
}
}
$refcount=0;
$dummy=-1;
@log = sort {$a->[0] <=> $b->[0]} @temp2;
# summarizing events within a time period of 10 seconds on different boxes
$dummy=-1;
foreach my $datum (@log)
{
if ($dummy != -1)
{
if((($datum->[0] - $dummy->[0]) <=10) && ($datum->[5] eq $dummy->[5]))
{
$datum->[0] = $dummy->[0];
$dummy->[7] = 1;
}
}
$dummy=$datum;
}
$lasttimestamp=0;
if (-e "$spflogoutfile")
{
open( IN, $spflogoutfile ) || die "can't open file $spflogoutfile: $!";
@tempfile = <IN>;
@tempfile = grep {/spf time/} @tempfile;
close IN;
#Wed Nov 27 14:58:11 2002
if (@tempfile[0]=~/time=\"(\d+)\"/)
{
$lasttimestamp=$1;
}
}
$newesttimestamp = $lasttimestamp;
@log = sort {$b->[0] <=> $a->[0]} @log;
if (@log[0]->[0] > $lasttimestamp)
{
$newesttimestamp = @log[0]->[0];
}
unlink $spflogoutfile;
open( OUT, "+>> $spflogoutfile" ) or die "Cannot open for writing: $!";
print OUT '<?xml version="1.0"?>' . "\n";
printf OUT ("<isis-spf-log timestamp=\"%s\">\n", scalar(localtime(time)));
foreach my $datum (@log)
{
if(($datum->[7] != 1) && ($datum->[0] > $lasttimestamp))
{
printf OUT ("<spf time=\"%s\" duration=\"%s\" nodes=\"%s\" count=\"%s\" ",
$datum->[0], $datum->[1], $datum->[2], $datum->[3]);
printf OUT ("last_trigger=\"%s\" triggers=\"%s\"/>\n",
$datum->[4],$datum->[5]) ;
}
}
if (scalar(@tempfile) > 0)
{
foreach my $datum (@tempfile)
{
if ($datum=~/time=\"(\d+)\"/)
{
$temptimestamp=$1;
if (($temptimestamp + 6 * 31 * 24 * 60 * 60) > $newesttimestamp)
{
printf OUT ($datum);
}
}
}
}
printf OUT ("</isis-spf-log>\n");
close OUT;
|