Changeset 206 for trunk/klask
- Timestamp:
- Feb 16, 2017, 7:39:58 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/klask
r205 r206 155 155 ifIndex => '1.3.6.1.2.1.17.1.4.1.2', # dot1dBasePortIfIndex - Interface index redirection 156 156 ifName => '1.3.6.1.2.1.31.1.1.1.1', # Interface name (give port number) 157 portUpDown => '1.3.6.1.2.1.2.2.1.7', # 1.3.6.1.2.1.2.2.1.7.NoPort = 1 (up) = 2 (down) 158 ); 159 160 Readonly my %PORT_UPDOWN => ( 161 1 => 'enable', 162 2 => 'disable', 157 163 ); 158 164 … … 162 168 Readonly my $RE_FLOAT_HOSTNAME => qr{ ^float }xms; 163 169 164 165 170 ################ 166 # principal171 # main program 167 172 ################ 168 173 … … 178 183 179 184 exit; 185 186 ################ 187 # subroutine 188 ################ 180 189 181 190 sub test_running_environnement { … … 2019 2028 2020 2029 sub cmd_status { 2021 my $switch = shift; 2022 my $port = shift; 2023 2024 system "snmpget -v 1 -c public $switch 1.3.6.1.2.1.2.2.1.7.$port"; 2030 @ARGV = @_; 2031 2032 my $verbose; 2033 2034 GetOptions( 2035 'verbose|v' => \$verbose, 2036 ); 2037 2038 my $switch_name = shift @ARGV || q{}; 2039 my $port = shift @ARGV || q{}; 2040 2041 my $sw = $SWITCH_DB{$switch_name}; 2042 my %session = ( -hostname => $sw->{hostname} ); 2043 $session{-version} = $sw->{version} || 1; 2044 $session{-port} = $sw->{snmpport} || $DEFAULT{snmpport} || 161; 2045 if (exists $sw->{version} and $sw->{version} eq '3') { 2046 $session{-username} = $sw->{username} || 'snmpadmin'; 2047 } 2048 else { 2049 $session{-community} = $sw->{community} || $DEFAULT{community} || 'public'; 2050 } 2051 $sw->{local_session} = \%session; 2052 2053 my ($session, $error) = Net::SNMP->session( %{$sw->{local_session}} ); 2054 print "$error \n" if $error; 2055 2056 my $oid_portstatus = $OID_NUMBER{'portUpDown'} .'.'. $port; 2057 print "Info: switch $switch_name port $port SNMP OID $oid_portstatus\n" if $verbose; 2058 my $result = $session->get_request( 2059 -varbindlist => [$oid_portstatus] 2060 ); 2061 if (defined $result) { 2062 print "$PORT_UPDOWN{$result->{$oid_portstatus}}\n"; 2063 } 2064 2065 #system "snmpget -v 1 -c public $switch_name 1.3.6.1.2.1.2.2.1.7.$port"; 2025 2066 return; 2026 2067 }
Note: See TracChangeset
for help on using the changeset viewer.