Changeset 206 for trunk/klask


Ignore:
Timestamp:
Feb 16, 2017, 7:39:58 PM (7 years ago)
Author:
g7moreau
Message:
  • Rewrite cmd_status
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/klask

    r205 r206  
    155155   ifIndex         => '1.3.6.1.2.1.17.1.4.1.2',       # dot1dBasePortIfIndex - Interface index redirection
    156156   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
     160Readonly my %PORT_UPDOWN => (
     161   1 => 'enable',
     162   2 => 'disable',
    157163   );
    158164
     
    162168Readonly my $RE_FLOAT_HOSTNAME => qr{ ^float }xms;
    163169
    164 
    165170################
    166 # principal
     171# main program
    167172################
    168173
     
    178183
    179184exit;
     185
     186################
     187# subroutine
     188################
    180189
    181190sub test_running_environnement {
     
    20192028
    20202029sub 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";
    20252066   return;
    20262067   }
Note: See TracChangeset for help on using the changeset viewer.