Changeset 129
- Timestamp:
- May 18, 2013, 10:42:58 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/klask
r128 r129 66 66 'search-mac-on-switch' => \&cmd_search_mac_on_switch, 67 67 'bad-vlan-config' => \&cmd_bad_vlan_config, 68 'set-vlan-port' => \&cmd_set_vlan_port, 69 'get-vlan-port' => \&cmd_get_vlan_port, 70 'set-vlan-name' => \&cmd_set_vlan_name, 71 'get-vlan-name' => \&cmd_get_vlan_name, 68 72 ); 69 73 … … 136 140 searchPort1 => '1.3.6.1.2.1.17.4.3.1.2', # BRIDGE-MIB (802.1D). 137 141 searchPort2 => '1.3.6.1.2.1.17.7.1.2.2.1.2.0', # Q-BRIDGE-MIB (802.1Q) replace last 0 with real vlan number if needed 138 listVlan => '1.3.6.1.2.1.17.7.1.4.3.1.1', 142 vlanPortDefault => '1.3.6.1.2.1.17.7.1.4.5.1.1', # dot1qPvid 143 vlanStatus => '1.3.6.1.2.1.17.7.1.4.3.1.5', # integer 4 Create, 6 Destroy 144 vlanName => '1.3.6.1.2.1.17.7.1.4.3.1.1', # string 139 145 ); 140 146 … … 627 633 klask - ports manager and finder for switch 628 634 635 klask version 636 629 637 klask updatedb 630 638 klask exportdb --format [txt|html] … … 640 648 641 649 klask ip-free --day number_of_day --format [txt|html] [vlan_name] 650 651 klask bad-vlan-config 642 652 643 653 klask enable switch port … … 1350 1360 } 1351 1361 1362 sub cmd_set_vlan_port { 1363 my $switch_name = shift || q{}; 1364 my $mac_address = shift || q{}; 1365 1366 if ($switch_name eq q{} or $mac_address eq q{}) { 1367 die "Usage: klask search-mac-on-switch SWITCH_NAME MAC_ADDRESS\n"; 1368 } 1369 1370 $switch_name = join(',', map {$_->{hostname}} @SWITCH ) if $switch_name eq q{*}; 1371 1372 for my $sw_name (split /,/, $switch_name) { 1373 if (not defined $SWITCH_DB{$sw_name}) { 1374 die "Switch $sw_name must be defined in klask configuration file\n"; 1375 } 1376 1377 my $sw = $SWITCH_DB{$sw_name}; 1378 my %session = ( -hostname => $sw->{hostname} ); 1379 $session{-version} = $sw->{version} || 1; 1380 $session{-port} = $sw->{snmpport} || $DEFAULT{snmpport} || 161; 1381 if (exists $sw->{version} and $sw->{version} eq '3') { 1382 $session{-username} = $sw->{username} || 'snmpadmin'; 1383 } 1384 else { 1385 $session{-community} = $sw->{community} || $DEFAULT{community} || 'public'; 1386 } 1387 1388 my $research1 = $OID_NUMBER{searchPort1} . mac_address_hex_to_dec($mac_address); 1389 my $research2 = $OID_NUMBER{searchPort2} . mac_address_hex_to_dec($mac_address); 1390 print "Klask search OID $research1 on switch $sw_name\n"; 1391 print "Klask search OID $research2 on switch $sw_name\n"; 1392 1393 my ($session, $error) = Net::SNMP->session( %session ); 1394 print "$error \n" if $error; 1395 1396 my $result = $session->get_request( 1397 -varbindlist => [$research1] 1398 ); 1399 if (not defined $result) { 1400 $result = $session->get_request( 1401 -varbindlist => [$research2] 1402 ); 1403 $result->{$research1} = $result->{$research2} if defined $result; 1404 } 1405 1406 if (defined $result and $result->{$research1} ne 'noSuchInstance') { 1407 my $swport = $result->{$research1}; 1408 print "Klask find MAC $mac_address on switch $sw_name port $swport\n"; 1409 } 1410 else { 1411 print "Klask do not find MAC $mac_address on switch $sw_name\n"; 1412 } 1413 1414 $session->close; 1415 } 1416 return; 1417 } 1418 1419 sub cmd_get_vlan_port { 1420 } 1421 1422 sub cmd_set_vlan_name { 1423 } 1424 1425 sub cmd_get_vlan_name { 1426 my $switch_name = shift || q{}; 1427 my $vlan_id = shift || q{}; 1428 1429 if ($switch_name eq q{} or $vlan_id eq q{}) { 1430 die "Usage: klask get-vlan-name SWITCH_NAME VLAN_ID\n"; 1431 } 1432 1433 $switch_name = join(',', map {$_->{hostname}} @SWITCH ) if $switch_name eq q{*}; 1434 1435 for my $sw_name (split /,/, $switch_name) { 1436 if (not defined $SWITCH_DB{$sw_name}) { 1437 die "Switch $sw_name must be defined in klask configuration file\n"; 1438 } 1439 1440 my $sw = $SWITCH_DB{$sw_name}; 1441 my %session = ( -hostname => $sw->{hostname} ); 1442 $session{-version} = $sw->{version} || 1; 1443 $session{-port} = $sw->{snmpport} || $DEFAULT{snmpport} || 161; 1444 if (exists $sw->{version} and $sw->{version} eq '3') { 1445 $session{-username} = $sw->{username} || 'snmpadmin'; 1446 } 1447 else { 1448 $session{-community} = $sw->{community} || $DEFAULT{community} || 'public'; 1449 } 1450 1451 my $search_vlan_name = $OID_NUMBER{vlanName} . "$vlan_id"; 1452 1453 my ($session, $error) = Net::SNMP->session( %session ); 1454 print "$error \n" if $error; 1455 1456 my $result = $session->get_request( 1457 -varbindlist => [$search_vlan_name] 1458 ); 1459 1460 if (defined $result and $result->{$search_vlan_name} ne 'noSuchInstance') { 1461 my $vlan_name = $result->{$search_vlan_name}; 1462 print "Klask find VLAN $vlan_id on switch $sw_name with name $swport\n"; 1463 } 1464 else { 1465 print "Klask do not find VLAN $vlan_id on switch $sw_name\n"; 1466 } 1467 1468 $session->close; 1469 } 1470 return; 1471 } 1472 1352 1473 sub cmd_ip_location { 1353 1474 my $computerdb = YAML::Syck::LoadFile("$KLASK_DB_FILE");
Note: See TracChangeset
for help on using the changeset viewer.