Changeset 39


Ignore:
Timestamp:
Feb 13, 2008, 3:09:48 PM (13 years ago)
Author:
g7moreau
Message:
  • Add support for snmp v3 in search-mac-on-switch command. But the switch must now be defined in the klask configuration file
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/klask

    r38 r39  
    836836   
    837837   if ($switch_name eq '' or $mac_address eq '') {
    838       print "Usage: klask search-mac-on-switch SWITCH_NAME MAC_ADDRESS\n";
    839       exit 1;
    840       }
    841    
     838      die "Usage: klask search-mac-on-switch SWITCH_NAME MAC_ADDRESS\n";
     839      }
     840
     841   if (not defined $SWITCH_DB{$switch_name}) {
     842      die "Switch $switch_name must be defined in klask configuration file\n";
     843      }
     844
     845   my $sw = $SWITCH_DB{$switch_name};
     846   my %session = ( -hostname => $sw->{hostname} );
     847      $session{-version} = $sw->{version}   || 1;
     848      $session{-port}    = $sw->{snmpport}  || $DEFAULT{snmpport}  || 161;
     849   if (exists $sw->{version} and $sw->{version} eq 3) {
     850      $session{-username} = $sw->{username} || 'snmpadmin';
     851      }
     852   else {
     853      $session{-community} = $sw->{community} || $DEFAULT{community} || 'public';
     854      }
     855
    842856   my $research = "1.3.6.1.2.1.17.4.3.1.2".arp_hex_to_dec($mac_address);
    843857   print "Klask search OID $research on switch $switch_name\n";
    844858
    845    my ($session, $error) = Net::SNMP->session( -hostname => $switch_name );
     859   my ($session, $error) = Net::SNMP->session( %session );
    846860   print "$error \n" if $error;
    847861
Note: See TracChangeset for help on using the changeset viewer.