Changeset 208 for trunk/klask


Ignore:
Timestamp:
Feb 16, 2017, 7:58:44 PM (7 years ago)
Author:
g7moreau
Message:
  • Begin SNMP param mutualisation code
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/klask

    r207 r208  
    4343   $SWITCH_LEVEL{$sw->{hostname}} = $sw->{level} || $DEFAULT{switch_level}  || 2;
    4444   $SWITCH_DB{$sw->{hostname}} = $sw;
     45
     46   # SNMP parameter initialisation
     47   my %session = ( -hostname   => $sw->{hostname} );
     48   $session{-version} = $sw->{version}   || 1;
     49   $session{-port}    = $sw->{snmpport}  || $DEFAULT{snmpport}  || 161;
     50   if (exists $sw->{version} and $sw->{version} eq '3') {
     51      $session{-username} = $sw->{username} || 'snmpadmin';
     52      }
     53   else {
     54      $session{-community} = $sw->{community} || $DEFAULT{community} || 'public';
     55      }
     56   $sw->{snmp_param_session} = \%session;
    4557   }
    4658@SWITCH_LIST = reverse sort { $SWITCH_LEVEL{$a->{hostname}} <=> $SWITCH_LEVEL{$b->{hostname}} } @{$KLASK_CFG->{switch}};
     
    20482060
    20492061   my $sw = $SWITCH_DB{$switch_name};
    2050    my %session = ( -hostname   => $sw->{hostname} );
    2051       $session{-version} = $sw->{version}   || 1;
    2052       $session{-port}    = $sw->{snmpport}  || $DEFAULT{snmpport}  || 161;
    2053       if (exists $sw->{version} and $sw->{version} eq '3') {
    2054          $session{-username} = $sw->{username} || 'snmpadmin';
    2055          }
    2056       else {
    2057          $session{-community} = $sw->{community} || $DEFAULT{community} || 'public';
    2058          }
    2059    $sw->{local_session} = \%session;
    2060 
    2061    my ($session, $error) = Net::SNMP->session( %{$sw->{local_session}} );
     2062   my ($session, $error) = Net::SNMP->session( %{$sw->{snmp_param_session}} );
    20622063   print "$error \n" if $error;
    20632064
Note: See TracChangeset for help on using the changeset viewer.