Changeset 141
- Timestamp:
- May 20, 2014, 9:01:54 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/klask
r140 r141 70 70 'set-vlan-name' => \&cmd_set_vlan_name, 71 71 'get-vlan-name' => \&cmd_get_vlan_name, 72 'rebootsw' => \&cmd_rebootsw' 72 73 ); 73 74 … … 143 144 vlanStatus => '1.3.6.1.2.1.17.7.1.4.3.1.5', # integer 4 Create, 6 Destroy 144 145 vlanName => '1.3.6.1.2.1.17.7.1.4.3.1.1', # string 146 hpicfReset => '1.3.6.1.4.1.11.2.14.11.1.4.1', # HP reboot switch 145 147 ); 146 148 … … 1499 1501 1500 1502 sub cmd_get_vlan_port { 1503 @ARGV = @_; 1504 1505 my $verbose; 1506 GetOptions( 1507 'verbose|v' => \$verbose, 1508 ); 1509 1510 my $switch_name = shift @ARGV || q{}; 1511 my $switch_port = shift @ARGV || q{}; 1512 1513 if ($switch_name eq q{} or $switch_port eq q{}) { 1514 die "Usage: klask get-vlan-port SWITCH_NAME PORT\n"; 1515 } 1516 1517 for my $sw_name (split /,/, $switch_name) { 1518 if (not defined $SWITCH_DB{$sw_name}) { 1519 die "Switch $sw_name must be defined in klask configuration file\n"; 1520 } 1521 1522 my $sw = $SWITCH_DB{$sw_name}; 1523 my %session = ( -hostname => $sw->{hostname} ); 1524 $session{-version} = $sw->{version} || 1; 1525 $session{-port} = $sw->{snmpport} || $DEFAULT{snmpport} || 161; 1526 if (exists $sw->{version} and $sw->{version} eq '3') { 1527 $session{-username} = $sw->{username} || 'snmpadmin'; 1528 } 1529 else { 1530 $session{-community} = $sw->{community} || $DEFAULT{community} || 'public'; 1531 } 1532 1533 my $search = $OID_NUMBER{'hpicfReset'} . ".$switch_port"; 1534 1535 my ($session, $error) = Net::SNMP->session( %session ); 1536 print "$error \n" if $error; 1537 1538 my $result = $session->get_request( 1539 -varbindlist => [$search], 1540 ); 1541 1542 if (defined $result and $result->{$search} ne 'noSuchInstance') { 1543 my $vlan_id = $result->{$search} || 'empty'; 1544 print "Klask VLAN Id $vlan_id on switch $sw_name on port $switch_port\n"; 1545 } 1546 else { 1547 print "Klask do not find VLAN Id $vlan_id on switch $sw_name on port $switch_port\n"; 1548 } 1549 1550 $session->close; 1551 } 1552 return; 1501 1553 } 1502 1554 1503 1555 sub cmd_set_vlan_name { 1556 } 1557 1558 # snmpset -v 1 -c public sw1-batG0-legi.hmg.priv "$OID_NUMBER{'hpicfReset'}.0" i 2; 1559 sub cmd_rebootsw { 1560 @ARGV = @_; 1561 1562 my $verbose; 1563 GetOptions( 1564 'verbose|v' => \$verbose, 1565 ); 1566 1567 my $switch_name = shift @ARGV || q{}; 1568 1569 if ($switch_name eq q{} or $mac_address eq q{}) { 1570 die "Usage: klask rebootsw SWITCH_NAME\n"; 1571 } 1572 1573 for my $sw_name (split /,/, $switch_name) { 1574 if (not defined $SWITCH_DB{$sw_name}) { 1575 die "Switch $sw_name must be defined in klask configuration file\n"; 1576 } 1577 1578 my $sw = $SWITCH_DB{$sw_name}; 1579 my %session = ( -hostname => $sw->{hostname} ); 1580 $session{-version} = $sw->{version} || 1; 1581 $session{-port} = $sw->{snmpport} || $DEFAULT{snmpport} || 161; 1582 if (exists $sw->{version} and $sw->{version} eq '3') { 1583 $session{-username} = $sw->{username} || 'snmpadmin'; 1584 } 1585 else { 1586 $session{-community} = $sw->{community} || $DEFAULT{community} || 'public'; 1587 } 1588 1589 my ($session, $error) = Net::SNMP->session( %session ); 1590 print "$error \n" if $error; 1591 1592 my $result = $session->set_request( 1593 -delay => 1, 1594 -varbindlist => ["$OID_NUMBER{'hpicfReset'}.0", INTEGER, 2], 1595 ); 1596 1597 $session->close; 1598 } 1599 return; 1504 1600 } 1505 1601
Note: See TracChangeset
for help on using the changeset viewer.