Concord/autoDiscover

autoDiscover
this is a ruff Perl script for "auto discovering" Cisco routers in a ATM network. it has basic support for one wan port and a number of ATM PVS for which it sets groop, main name, alias name, and speed.

i need to clean this up a bit i have an extra cli varible thats not needed (or should be but =)


 * 1) !/usr/local/bin/perl

use strict; use warnings;


 * 1) main discover
 * 2) Parameters :
 * 3) 		autoDiscover.pl discover.csv "Service"
 * 4) 		csv file must be in the correct format ie:- (with as many PVC's as needed)
 * 5) 	IPAddress,String,SiteName,Group,WanAliasName,WanSpeed:NumberOfPVCs:DLCI1,Alias1,Name1,Speed1;DLCI2,Alias2,Name2,Speed2;
 * 6) ver0.1.2 04/03/2004:	Removed ( -nmsSource \"NH:Discover\") from the nhAutoDiscover command
 * 1) ver0.1.2 04/03/2004:	Removed ( -nmsSource \"NH:Discover\") from the nhAutoDiscover command
 * 1) ver0.1.2 04/03/2004:	Removed ( -nmsSource \"NH:Discover\") from the nhAutoDiscover command

my ($dataFileName)=$ARGV[0] || die "Missing Args Should be: autoDiscover.pl discover.csv \"Service\" $!";  	# get file name of discover file my ($SdtArfName)=$ARGV[1] || die "Missing Args Should be: autoDiscover.pl discover.csv \"Service\" $!";	# get  std rule name

open DFILE, "$dataFileName" # open datafile and read in  or die or die "no file specified command format is \"autoDiscover FILE-NAME Server \" $!"; my (@dataFile) = ; close DFILE;

foreach my $site (@dataFile) { # loop  for each line/site in dataFile chomp $site ; my ($siteIP,$siteString)=makeArf("$site","$SdtArfName"); # make ARF file then return IP and Cominity String print " Discovering $siteIP with $siteString \n "; `nhAutoDiscover -l \"$siteIP\" -c \"$siteString\" -mode \"lanwan,router\" -dciRule \"tmp/$siteIP.arf\" > tmp\/$siteIP.Results.temp`; # this is the command used to do the discover checkResults("$siteIP");	# run the results sub };

sub checkResults { my $NH_HOME= "/nethealth1/poller/"; # point to the poller CFG file NOTE replace this with ENV[NH_HOME] my($segmentFieldKey, $segmentFieldValue, %segmentFields, $nullVar); my($siteIPAdd)=$_[0]; # read in  IP  from parent NOTE make a check for this
 * 1) Function Check Discover Results
 * 2) Parameters :
 * 3) 		Ip Address of site to be found : x.x.x.x
 * 4) 		Poller Cfg file : this is the data file
 * 5) 			should be in the $NH_HOME/poller dir
 * 6) Returns :
 * 7) Ver0.1.2 04/03/2004:	clear out the $segmentFields vars at start of loop ( to stop KeyValue passing on to next segment )
 * 8) 			put Speach marks around $siteIPAdd (next unless /\"$siteIPAdd\"/;) as it was finging extra segments ie not just .5 but .51
 * 1) Ver0.1.2 04/03/2004:	clear out the $segmentFields vars at start of loop ( to stop KeyValue passing on to next segment )
 * 2) 			put Speach marks around $siteIPAdd (next unless /\"$siteIPAdd\"/;) as it was finging extra segments ie not just .5 but .51

local $/ = "}\n"; 			# set delimiter open(DISCOVERLOG, ">>tmp/discover.log.temp") || die "can not open : $!"; open(POLLER, "$NH_HOME/poller.cfg") || die "can not open : $!";

while() { ($segmentFields{segment}, $segmentFields{deviceSpeed2}, $segmentFields{sysName}, $segmentFields{aliasName}, $segmentFields{mibTranslationFile})=("","","","",""); next unless /\s+segment/; next unless /\"$siteIPAdd\"/; s/\n\s+\}\n//g; s/["{]//g; 	foreach (split(/\n/)) {		($nullVar,$segmentFieldKey,$segmentFieldValue)=split(/\s+/,$_,3);		$segmentFields { $segmentFieldKey } = $segmentFieldValue ; 	} print DISCOVERLOG "$segmentFields{segment}, $segmentFields{deviceSpeed2}, $segmentFields{sysName}, $segmentFields{aliasName}, $segmentFields{mibTranslationFile}\n" ; } close POLLER; close DISCOVERLOG; }

sub makeArf {
 * 1) Start of sub that makes arf files
 * 2) this function creates a arf rule file from input Data
 * 3) Version 0.1 6/11/03 original
 * 4) 0.2 21/11/03 tryed to convert to sub
 * 5) 0.3 42/11/03 finished converting to sub
 * 6) 0.4 12/03 worked on results sub
 * 7) 0.5 20/1/2004 tweeked rule order
 * 1) 0.5 20/1/2004 tweeked rule order

my ($csvData)="$_[0]"; my ($siteLink,$siteNoOfPVCs,$siteAllPVCs)=split(/:/,$csvData,3); #split up main / pvc info my ($siteIP,$siteString,$siteName,$siteGroup,$siteCCTReff,$siteACRate)=split(/,/,$siteLink,6); #split up main info my @sitePVCs = split(/;/,$siteAllPVCs,$siteNoOfPVCs);

my $siteARFFILE = "$siteIP.arf"; open ARFFILE, ">tmp/$siteARFFILE" or die "can not open '$siteARFFILE': $!"; print ARFFILE <; close IN; print ARFFILE "@standardRules\n"; #print standard bits
 * 1) open standard file and print

print ARFFILE <<EOF; name matches ".*-BRI.*": { exclude ; }\n EOF
 * 1) print -BRI rule

print ARFFILE <<EOF; name matches ".*-BVI.*": { exclude ; }\n EOF
 * 1) print -BVI rule

print ARFFILE <<EOF; name matches ".*-Dialer.*": { exclude ; }\n EOF
 * 1) print -Dialer rule

print ARFFILE <<EOF; ifType matches "ppp": { exclude ; }\n EOF
 * 1) print -PPP rule

print ARFFILE <<EOF; name matches ".*-Cpu-.*": { setName ("$siteName-cpu"); setGroup ("$siteGroup"); setAlias ("\$1-\$2") ; }\n EOF
 * 1) print -Cpu- rule

print ARFFILE <<EOF; name matches ".*Ethernet.*": {   setName ("$siteName-lan\$2") ; setGroup ("$siteGroup") ; setAlias ("\$1Lan\$2") ; }\n EOF
 * 1) print Ethernet rule

foreach my $PVC (@sitePVCs){ # loop for each PVC my ($PVCdlci,$PCVreff,$PVCname,$PVCcir)=split(/,/,$PVC,4); # split out pvc info

print ARFFILE <<EOF; name matches ".*-Serial.*-dlci-$PVCdlci": { setName ("$siteName-$PVCname") ; setGroup ("$siteGroup") ; setAlias ("\$1-S\$2-$PCVreff") ; setSpeedIn ("$PVCcir") ; setSpeedOut ("$PVCcir") ; setDeviceSpeedIn ("$PVCcir") ; setDeviceSpeedOut ("$PVCcir") ; }\n EOF
 * 1) print PVC rules

}

print ARFFILE <<EOF; name matches ".*-dlci-.*": {   exclude  ; }\n EOF
 * 1) print dlci drop out rule

print ARFFILE <<EOF; name matches ".*-Serial.*:.*":{ setName ("$siteName-wan\$2:\$3") ; setGroup ("$siteGroup") ; setAlias ("\$1-s\$2:\$3-$siteCCTReff") ; setSpeedIn ("$siteACRate") ; setSpeedOut ("$siteACRate") ; setDeviceSpeedIn ("$siteACRate") ; setDeviceSpeedOut ("$siteACRate") ; }\n EOF
 * 1) print -Serial*:* rule

print ARFFILE <<EOF; name matches ".*-Serial.*":{ setName ("$siteName-wan\$2") ; setGroup ("$siteGroup") ; setAlias ("\$1-S\$2-$siteCCTReff") ; setSpeedIn ("$siteACRate") ; setSpeedOut ("$siteACRate") ; setDeviceSpeedIn ("$siteACRate") ; setDeviceSpeedOut ("$siteACRate") ; }\n EOF
 * 1) print -Serial rule

print ARFFILE <<EOF; name matches ".*-RH\$": { setName ("$siteName-rh") ; setGroup ("$siteGroup") ; setAlias ("\$1-rh") ; }\n EOF
 * 1) print -RH rule

print ARFFILE <<EOF; name matches ".*": {   exclude  ; }\n EOF
 * 1) print drop out rule

print ARFFILE <<EOF; EOF
 * 1) print footer rule
 * 1) End of Discover Rule
 * 2) \n
 * 1) \n

close(ARFFILE) or die("can not close '$siteARFFILE': $!"); return ($siteIP,$siteString);     # return the IP and comunity string to main ruteen }; #end of makeArf Sub

Back to Concord Index