[nmstools-cvs] src/cgi-bin isis_spflog.cgi.in,NONE,1.1
Brought to you by:
ssinyagin
|
From: Michel H. <mi...@us...> - 2002-12-17 09:29:05
|
Update of /cvsroot/nmstools/src/cgi-bin
In directory sc8-pr-cvs1:/tmp/cvs-serv28778
Added Files:
isis_spflog.cgi.in
Log Message:
initial import
--- NEW FILE: isis_spflog.cgi.in ---
#!%%PERL%%
#
# NMSTOOLS -- NMS Helper Tools
# $Id: isis_spflog.cgi.in,v 1.1 2002/12/17 09:28:58 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.cgi.in,v $
# Revision 1.1 2002/12/17 09:28:58 mihahn
# initial import
#
# Revision 1.0
use CGI;
use Time::Local;
require '%%NMSTOOLS_HOME%%/lib/lib_nmstools.pl';
%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);
$query = new CGI;
$spfloginfile = $nms_config{'env'}{'DATA'} . '/mpls/spflogarchive';
$spflogtempfile = $nms_config{'env'}{'DATA'} . '/mpls/spflogtempfile.xml';
$spfloghtmloutfile = $nms_config{'env'}{'DATA'} . '/mpls/tempspfloghtml.html';
print $query->header(-type => 'text/html',
-expires => '+3m');
if( $query->param('month') )
{
my $day = $query->param('day');
my $month = $query->param('month');
my $year = $query->param('year');
my $time = $query->param('time');
my $std = $time;
$std =~ s/:\d+//;
my $min = $time;
$min =~ s/\d+://;
if( $query->param('output_range') eq 'd' )
{
$delta= 24 * 60 * 60;
}
elsif( $query->param('output_range') eq 'w' )
{
$delta= 7 * 24 * 60 * 60;
}
elsif( $query->param('output_range') eq 'm' )
{
$delta= 31 * 24 * 60 * 60;
}
else
{
$delta= 0;
}
my $output=localtime(timelocal(0, $min, $std, $day , $monat{$month}, $year));
print $query->h2($output);
$lasttimestamp=0;
if (-e "$spfloginfile")
{
open( IN, $spfloginfile ) || print $query->h1("can't open file $spfloginfile: $!");
@tempfile = <IN>;
@timestamp = grep {/timestamp/} @tempfile;
@tempfile = grep {/spf time/} @tempfile;
close IN;
if ($delta > 0)
{
$t1=timelocal(0, $min, $std, $day , $monat{$month}, $year);
$t2= $t1 - $delta;
}
open( OUT, "> $spflogtempfile" ) or print $query->h1("can't open file $spflogtempfile: $!");
print OUT '<?xml version="1.0"?>' . "\n";
printf OUT (@timestamp);
foreach my $datum (@tempfile)
{
if($datum=~/time=\"(\d+)\"/)
{
$t0=$1;
$zeit="time=\"" . localtime($1) . "\"";
$datum=~ s/time=\"(\d+)\"/$zeit/;
#print ($datum . "\n");
if ((($t0<$t1) && ($t0>$t2)) || ($delta==0))
{
printf OUT ($datum) ;
}
}
}
printf OUT ("</isis-spf-log>\n");
close OUT;
if( -r $spflogtempfile )
{
system(sprintf("xsltproc --output %s %s/lib/isis_spf_log-html.xsl %s",
$spfloghtmloutfile, $nms_config{'env'}{'HOME'},
$spflogtempfile));
open( IN, $spfloghtmloutfile ) or print $query->h1("can't open file $spfloghtmloutfile: $!");
while(<IN>)
{
print;
}
close IN;
unlink $spflogtempfile;
unlink $spfloghtmloutfile;
}
}
}
else
{
print $query->start_html("MPLS ISIS SPF-LOG");
printform();
}
sub printform
{
print $query->h1("ISIS SPF-LOG");
@monate = ("Jan","Feb","Mar","Apr","May","Jun","Jul",
"Aug","Sep","Oct","Nov","Dec");
#Thu Dec 12 15:20:59 2002
$time = localtime;
if($time=~/\w+\s+(\w+)\s+(\d+)\s+(\d+:\d+):\d+\s+(\d+)/)
{
$month=$1; $day=$2; $tm=$3; $year=$4;
}
print $query->start_form();
print "Day: ";
print $query->textfield('day', $day, 2, 2);
print " Month: ";
print $query->popup_menu(-name=>'month',
-values=>\@monate,
-default=>$month);
print " Year: ";
print $query->textfield('year', $year, 4, 4);
print $query->br();
print "Time: ";
print $query->textfield('time', $tm, 5, 5);
print $query->br();
print $query->radio_group( -name => 'output_range',
-values => ['all', 'd', 'w', 'm'],
-default => 'all',
-linebreak => 'true',
-labels => {
'all' => 'all records',
'd' => 'one day',
'w' => 'one week',
'm' => 'one month' } );
print $query->br();
print $query->submit();
print $query->end_form();
}
|