Title: Message
I am using snmp to walk a couple of tables on some switches to output a list of mac to port numbers. It works fine when using only 1 switch, when I put multiple switches in the list to walk, the output gets messed up showing multiple ports and or the same port but with different hosts. I have tried to put in "sleep" statements thinking maybe some data was lingering in but that did not help. I also tried replacing the "foreach" with a "while - foreach" on line 7 but then is skips the first switch and only walks the second switch. Any thoughts?  Unfortuantely I can't uprgrade my switches so they will accept SNMP v2 so I am stuck with walking instead of a bulkget. My file is structured like this:
 
file: switches
x.x.x.x,-c <community string>,1.3.6.1.2.1.17.4.3.1.1,1.3.6.1.2.1.17.4.3.1.2
x.x.x.x,-c <community string>,1.3.6.1.2.1.17.4.3.1.1,1.3.6.1.2.1.17.4.3.1.2
 
SCRIPT:
#!/usr/bin/perl -w
$s='/usr/local/bin/snmpwalk';
$ver='-v 1';
$mastermac='/home/tmp/output';
$file='/home/tmp/switches';
open (FILE, "<$file");
foreach (<FILE>) {
        ($host,$com,$oid1,$oid2)=split(/,/, $_);
        #if ($blade eq 24) {
        &walk;
        &pre24;
        &blade24;
}
close (FILE);
sub walk {
open (S,"$s $ver $host $com $oid1|");
while (<S>) {
push @pmac, "$host-$_";
}
close(S);
open (T,"$s $ver $host $com $oid2|");
while (<T>) {
push @pport, "$host-$_";
}
close(T);
}
################################
## 24 Port pre-processor
################################
sub pre24 {
foreach $a(@pmac){
        if ($a =~ /^(.*)\-SNMPv2-SMI::mib-2.17.4.3.1.1.\d.\d+.(\d+\.\d+\.\d+\.\d+).*\:\s+(.+\s.+\s.+\s.+\s.+\s.+)/i && ($3 !~ /^00\s00\s1D.*/i)){
push @mac, "$1-$2-$3";
}}
foreach $b(@pport){
        if ($b =~ /^(.*)\-SNMPv2-SMI::mib-2.17.4.3.1.2.\d.\d+.(\d+\.\d+\.\d+\.\d+).*\:\s+(\d+)/i && ($3 lt 25) && ($3 gt 0)) {
push @port, "$1-$2-$3";
}}
}
################################
## 48 Port pre-processor
################################
sub pre48 {
foreach $a(@pmac){
        if ($a =~ /^(.*)\-SNMPv2-SMI::mib-2.17.4.3.1.1.\d.\d+.(\d+\.\d+\.\d+\.\d+).*\:\s+(.+\s.+\s.+\s.+\s.+\s.+)/i && ($3 !~ /^00\s00\s1D.*/i)){
push @mac, "$1-$2-$3";
}}
foreach $b(@pport){
        if ($b =~ /^(.*)\-SNMPv2-SMI::mib-2.17.4.3.1.2.\d.\d+.(\d+\.\d+\.\d+\.\d+).*\:\s+(\d+)/i && ($3 lt 49) && ($3 gt 0)) {
push @port, "$1-$2-$3";
}}
}
 
sub blade24 {
#open (M, ">>$mastermac");
foreach (@port){
                foreach $y(@mac){
                ($host,$id,$m)=split(/-/, $y);
                        if ($_ =~ /^(\d+\.\d+\.\d+\.\d+)\-(.*)\-(\d+)/i && ($2 eq $id)){
push @final, "$host-$m-$3";
#print M "$host-$m-$3\n";
}}}
#close (M);
}
 
open (M, ">>$mastermac");
foreach (@final){
print M "$_\n";
}
close(M);
 

Thanks,

Rich

 

 
-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>

Reply via email to