Changeset 209
- Timestamp:
- Feb 16, 2017, 9:38:46 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/klask
r208 r209 40 40 my %SWITCH_DB = (); 41 41 LEVEL_OF_EACH_SWITCH: 42 for my $sw (@SWITCH_LIST) {42 for my $sw (@SWITCH_LIST) { 43 43 $SWITCH_LEVEL{$sw->{hostname}} = $sw->{level} || $DEFAULT{switch_level} || 2; 44 44 $SWITCH_DB{$sw->{hostname}} = $sw; … … 349 349 INIT_EACH_SWITCH: 350 350 for my $sw (@SWITCH_LIST) { 351 my %session = ( -hostname => $sw->{hostname} ); 352 $session{-version} = $sw->{version} || 1; 353 $session{-port} = $sw->{snmpport} || $DEFAULT{snmpport} || 161; 354 if (exists $sw->{version} and $sw->{version} eq '3') { 355 $session{-username} = $sw->{username} || 'snmpadmin'; 356 } 357 else { 358 $session{-community} = $sw->{community} || $DEFAULT{community} || 'public'; 359 } 360 361 $sw->{local_session} = \%session; 362 363 my ($session, $error) = Net::SNMP->session( %{$sw->{local_session}} ); 351 my ($session, $error) = Net::SNMP->session( %{$sw->{snmp_param_session}} ); 364 352 print "$error \n" if $error; 365 353 … … 483 471 LOOP_ON_SWITCH: 484 472 for my $sw (@switch_search) { 485 my ($session, $error) = Net::SNMP->session( %{$sw->{ local_session}} );473 my ($session, $error) = Net::SNMP->session( %{$sw->{snmp_param_session}} ); 486 474 print "$error \n" if $error; 487 475 … … 541 529 LOOP_ON_ALL_SWITCH: 542 530 for my $sw (@SWITCH_LIST) { 543 my ($session, $error) = Net::SNMP->session( %{$sw->{ local_session}} );531 my ($session, $error) = Net::SNMP->session( %{$sw->{snmp_param_session}} ); 544 532 print "$error \n" if $error; 545 533 … … 623 611 my @line = @{$KLASK_CFG->{network}{$net}{'ip-subnet'}}; 624 612 for my $cmd (@line) { 625 for my $method (keys %{$cmd}) {613 for my $method (keys %{$cmd}) { 626 614 $cidrlist->add_any($cmd->{$method}) if $method eq 'add'; 627 615 } … … 994 982 $db_switch_chained_port{$sw_connect} .= "$port_connect:"; 995 983 } 996 for my $sw (@SWITCH_LIST) {984 for my $sw (@SWITCH_LIST) { 997 985 push @{$sw->{portignore}}, $db_switch_output_port{$sw->{hostname}} if exists $db_switch_output_port{$sw->{hostname}}; 998 986 if ( exists $db_switch_chained_port{$sw->{hostname}} ) { … … 1668 1656 } 1669 1657 1670 my $sw = $SWITCH_DB{$sw_name};1671 my %session = ( -hostname => $sw->{hostname} );1672 $session{-version} = $sw->{version} || 1;1673 $session{-port} = $sw->{snmpport} || $DEFAULT{snmpport} || 161;1674 if (exists $sw->{version} and $sw->{version} eq '3') {1675 $session{-username} = $sw->{username} || 'snmpadmin';1676 }1677 else {1678 $session{-community} = $sw->{community} || $DEFAULT{community} || 'public';1679 }1680 1681 1658 my $research1 = $OID_NUMBER{searchPort1} . mac_address_hex_to_dec($mac_address); 1682 1659 my $research2 = $OID_NUMBER{searchPort2} .'.'. 0 . mac_address_hex_to_dec($mac_address); … … 1684 1661 print "Klask search OID $research2 on switch $sw_name\n"; 1685 1662 1686 my ($session, $error) = Net::SNMP->session( %session ); 1663 my $sw = $SWITCH_DB{$sw_name}; 1664 my ($session, $error) = Net::SNMP->session( %{$sw->{snmp_param_session}} ); 1687 1665 print "$error \n" if $error; 1688 1666 … … 1730 1708 } 1731 1709 1710 my $search = $OID_NUMBER{'vlanPortDefault'} . ".$switch_port"; 1711 1732 1712 my $sw = $SWITCH_DB{$sw_name}; 1733 my %session = ( -hostname => $sw->{hostname} ); 1734 $session{-version} = $sw->{version} || 1; 1735 $session{-port} = $sw->{snmpport} || $DEFAULT{snmpport} || 161; 1736 if (exists $sw->{version} and $sw->{version} eq '3') { 1737 $session{-username} = $sw->{username} || 'snmpadmin'; 1738 } 1739 else { 1740 $session{-community} = $sw->{community} || $DEFAULT{community} || 'public'; 1741 } 1742 1743 my $search = $OID_NUMBER{'vlanPortDefault'} . ".$switch_port"; 1744 1745 my ($session, $error) = Net::SNMP->session( %session ); 1713 my ($session, $error) = Net::SNMP->session( %{$sw->{snmp_param_session}} ); 1746 1714 print "$error \n" if $error; 1747 1715 … … 1787 1755 1788 1756 my $sw = $SWITCH_DB{$sw_name}; 1789 my %session = ( -hostname => $sw->{hostname} ); 1790 $session{-version} = $sw->{version} || 1; 1791 $session{-port} = $sw->{snmpport} || $DEFAULT{snmpport} || 161; 1792 if (exists $sw->{version} and $sw->{version} eq '3') { 1793 $session{-username} = $sw->{username} || 'snmpadmin'; 1794 } 1795 else { 1796 $session{-community} = $sw->{community} || $DEFAULT{community} || 'public'; 1797 } 1798 1799 my ($session, $error) = Net::SNMP->session( %session ); 1757 my ($session, $error) = Net::SNMP->session( %{$sw->{snmp_param_session}} ); 1800 1758 print "$error \n" if $error; 1801 1759 … … 1824 1782 } 1825 1783 1784 my $search_vlan_name = $OID_NUMBER{vlanName} . ".$vlan_id"; 1785 1826 1786 my $sw = $SWITCH_DB{$sw_name}; 1827 my %session = ( -hostname => $sw->{hostname} ); 1828 $session{-version} = $sw->{version} || 1; 1829 $session{-port} = $sw->{snmpport} || $DEFAULT{snmpport} || 161; 1830 if (exists $sw->{version} and $sw->{version} eq '3') { 1831 $session{-username} = $sw->{username} || 'snmpadmin'; 1832 } 1833 else { 1834 $session{-community} = $sw->{community} || $DEFAULT{community} || 'public'; 1835 } 1836 1837 my $search_vlan_name = $OID_NUMBER{vlanName} . ".$vlan_id"; 1838 1839 my ($session, $error) = Net::SNMP->session( %session ); 1787 my ($session, $error) = Net::SNMP->session( %{$sw->{snmp_param_session}} ); 1840 1788 print "$error \n" if $error; 1841 1789 … … 2059 2007 } 2060 2008 2009 my $search_portstatus = $OID_NUMBER{'portUpDown'} .'.'. $port; 2010 print "Info: switch $switch_name port $port SNMP OID $search_portstatus\n" if $verbose; 2011 2061 2012 my $sw = $SWITCH_DB{$switch_name}; 2062 2013 my ($session, $error) = Net::SNMP->session( %{$sw->{snmp_param_session}} ); 2063 2014 print "$error \n" if $error; 2064 2015 2065 my $oid_portstatus = $OID_NUMBER{'portUpDown'} .'.'. $port;2066 print "Info: switch $switch_name port $port SNMP OID $oid_portstatus\n" if $verbose;2067 2016 my $result = $session->get_request( 2068 -varbindlist => [$ oid_portstatus]2017 -varbindlist => [$search_portstatus] 2069 2018 ); 2070 2019 if (defined $result) { 2071 print "$PORT_UPDOWN{$result->{$ oid_portstatus}}\n";2020 print "$PORT_UPDOWN{$result->{$search_portstatus}}\n"; 2072 2021 } 2073 2022 … … 2102 2051 } 2103 2052 2104 my $sw = $SWITCH_DB{$sw_name};2105 my %session = ( -hostname => $sw->{hostname} );2106 $session{-version} = $sw->{version} || 1;2107 $session{-port} = $sw->{snmpport} || $DEFAULT{snmpport} || 161;2108 if (exists $sw->{version} and $sw->{version} eq '3') {2109 $session{-username} = $sw->{username} || 'snmpadmin';2110 }2111 else {2112 $session{-community} = $sw->{community} || $DEFAULT{community} || 'public';2113 }2114 2115 2053 my $research1 = $OID_NUMBER{searchPort1} . mac_address_hex_to_dec($mac_address); 2116 2054 my $research2 = $OID_NUMBER{searchPort2} .'.'. $vlan_id . mac_address_hex_to_dec($mac_address); … … 2118 2056 print "Klask search OID $research2 on switch $sw_name\n" if $verbose; 2119 2057 2120 my ($session, $error) = Net::SNMP->session( %session ); 2058 my $sw = $SWITCH_DB{$sw_name}; 2059 my ($session, $error) = Net::SNMP->session( %{$sw->{snmp_param_session}} ); 2121 2060 print "$error \n" if $error; 2122 2061 … … 2195 2134 my @list_all_switch = (); 2196 2135 my @list_switch_ipv4 = (); 2197 for my $sw (@SWITCH_LIST) {2136 for my $sw (@SWITCH_LIST) { 2198 2137 push @list_all_switch, $sw->{hostname}; 2199 2138 }
Note: See TracChangeset
for help on using the changeset viewer.