#!/usr/local/bin/perl5 # -*- mode: Perl -*- ################################################################## # This file controls the deletion of the MRTG monitoring from OV ################################################################## # Created by Laurie Gellatly ################################################################# # # Distributed under the GNU copyleft # # $Id: ovdel,v 1.1.1.1 2002/02/26 10:16:36 oetiker Exp $ # use Socket; use strict; use vars '$DEBUG'; my $DEBUG = 0; my $company = "Company"; my $rundir = "/opt/mrtg/run"; my $webdir = "/var/opt/ns-fasttrack/docs/mrtg/"; my $cronfile = "mrtgc"; my $roothtml = "routers.html"; my $ov_conf = "/etc/opt/OV/share/conf"; my $ovconf = $ov_conf."/snmpCol.conf"; my $buildhtf = "buildht"; my $dnsfile = "ovmrtgc.csv"; # Change the next line to " &" if all jobs are to be submitted at once my $backgrnd = " "; my($router,$sysn,$sysncfg,$sysnhtml,$head,$cnt,$at); my(@sysipnms,@mrtgc,@mrtgd,@sysnms,@ovconfd,@ovmrtgc,@buildhtt); sub main { $router = $ARGV[0]; die < collects`; `xnmcollect -merge collects`; # eventaully HP may decide to remove lines using xnmcollect and then we would # not need the following loop: open (SNMPCOL,"<".$ovconf); # This next piece of code removes any lines in snmpCol.conf that start with XC while(){ if (/^XC /){ next; } else { $ovconfd[@ovconfd] = $_; } } close (SNMPCOL); open (SNMPCOL,">".$ovconf); for ($cnt = 0; $cnt < @ovconfd ; $cnt++){ print SNMPCOL "$ovconfd[$cnt]"; } close (SNMPCOL); `xnmcollect -event`; # Remove the .cfg and .ok files as no longer needed for ($cnt = 0; $cnt < @sysipnms ; $cnt++){ ($router,$mrtgd[@mrtgd]) = split /\,/, lc($sysipnms[$cnt]); unlink($mrtgd[$cnt].".cfg",$mrtgd[$cnt].".ok"); } @mrtgd = sort(@mrtgd); # Assumes that the mrtgc.csv file is in alpha order open (DNSFILE,"<".$dnsfile); $at = 0; while(){ chomp; $head = $_; $sysn = lc((split /\,/,$head)[1]); if ($sysn gt $mrtgd[$at]) { while($at < @mrtgd) { if($sysn le $mrtgd[++$at]){last; } } } if (($sysn lt $mrtgd[$at]) || ($at >= @mrtgd)) { #keep these lines $mrtgc[@mrtgc] = $sysn; $ovmrtgc[@ovmrtgc] = $head; } # } } close (DNSFILE); #Now rebuild the mrtgc.csv file open (DNSFILE,">".$dnsfile); for ($cnt = 0 ; $cnt < @ovmrtgc ; ++$cnt){ print DNSFILE "$ovmrtgc[$cnt]\n"; } close (DNSFILE); #Build the index by keeping the original lines. open (BUILDHT,"<".$buildhtf); $head = 0; $at = 0; # This next piece of code assumes that the $buildhtf file is in alpha order while(){ chomp; if (/index (.*)\.cfg/){ $sysn = $1; $head = $_; if ($sysn gt $mrtgd[$at]) { while($at < @mrtgd) { if($sysn le $mrtgd[++$at]){last; } } } if (($sysn lt $mrtgd[$at]) || ($at >= @mrtgd)) { $buildhtt[@buildhtt] = $head; } } } close (BUILDHT); open (BUILDHT,">".$buildhtf); print BUILDHT <".$webdir.$roothtml); print HTMLF <

$company Router MRTG Traffic Analysis

ECHO for ($cnt = 0; $cnt < @mrtgc ; $cnt++){ $sysn = $mrtgc[$cnt]; $sysnhtml = $sysn.".html"; print HTMLF "$sysn<\/A>
\n"; } print HTMLF <
ECHO close(HTMLF); open (MRTGC,">".$cronfile); print MRTGC <