Changeset 277


Ignore:
Timestamp:
Sep 23, 2017, 10:42:06 AM (7 years ago)
Author:
g7moreau
Message:
  • rename $oid_search variable
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/klask

    r276 r277  
    504504      }
    505505
    506    my $research1 = $OID_NUMBER{'searchPort1'} . mac_address_hex2dec($mac_address);
    507    my $research2 = $OID_NUMBER{'searchPort2'} .'.'. $vlan_id . mac_address_hex2dec($mac_address);
     506   my $oid_search_port1 = $OID_NUMBER{'searchPort1'} . mac_address_hex2dec($mac_address);
     507   my $oid_search_port2 = $OID_NUMBER{'searchPort2'} .'.'. $vlan_id . mac_address_hex2dec($mac_address);
    508508
    509509   LOOP_ON_SWITCH:
     
    513513
    514514      my $result = $session->get_request(
    515          -varbindlist => [$research1]
     515         -varbindlist => [$oid_search_port1]
    516516         );
    517517      if (not defined $result) {
    518518         $result = $session->get_request(
    519             -varbindlist => [$research2]
     519            -varbindlist => [$oid_search_port2]
    520520            );
    521          $result->{$research1} = $result->{$research2} if defined $result;
    522          }
    523 
    524       if (not (defined $result and $result->{$research1} ne 'noSuchInstance')) {
     521         $result->{$oid_search_port1} = $result->{$oid_search_port2} if defined $result;
     522         }
     523
     524      if (not (defined $result and $result->{$oid_search_port1} ne 'noSuchInstance')) {
    525525         $session->close;
    526526         next LOOP_ON_SWITCH;
    527527         }
    528528
    529       my $swport_id = $result->{$research1};
     529      my $swport_id = $result->{$oid_search_port1};
    530530      my $swport_hr = snmp_get_switchport_id2hr($session, $swport_id);
    531531
     
    565565   return $ret if $mac_address eq 'unknow';
    566566
    567    my $research1 = $OID_NUMBER{'searchPort1'} . mac_address_hex2dec($mac_address);
    568    my $research2 = $OID_NUMBER{'searchPort2'} .'.'. $vlan_id . mac_address_hex2dec($mac_address);
     567   my $oid_search_port1 = $OID_NUMBER{'searchPort1'} . mac_address_hex2dec($mac_address);
     568   my $oid_search_port2 = $OID_NUMBER{'searchPort2'} .'.'. $vlan_id . mac_address_hex2dec($mac_address);
    569569   LOOP_ON_ALL_SWITCH:
    570570   for my $sw (@SWITCH_LIST) {
     
    573573
    574574      my $result = $session->get_request(
    575          -varbindlist => [$research1]
     575         -varbindlist => [$oid_search_port1]
    576576         );
    577577      if (not defined $result) {
    578578         $result = $session->get_request(
    579             -varbindlist => [$research2]
     579            -varbindlist => [$oid_search_port2]
    580580            );
    581          $result->{$research1} = $result->{$research2} if defined $result;
    582          }
    583 
    584       if (defined $result and $result->{$research1} ne 'noSuchInstance') {
    585          my $swport_id = $result->{$research1};
     581         $result->{$oid_search_port1} = $result->{$oid_search_port2} if defined $result;
     582         }
     583
     584      if (defined $result and $result->{$oid_search_port1} ne 'noSuchInstance') {
     585         my $swport_id = $result->{$oid_search_port1};
    586586         my $swport_hr = snmp_get_switchport_id2hr($session, $swport_id);
    587587
     
    723723   # First get the index, second get the name (port_hr)
    724724
    725    my $research_ix = $OID_NUMBER{'ifIndex'} .'.'. $swport_id;
     725   my $oid_search_ix = $OID_NUMBER{'ifIndex'} .'.'. $swport_id;
    726726   my $result_ix = $snmp_session->get_request(
    727       -varbindlist => [$research_ix]
     727      -varbindlist => [$oid_search_ix]
    728728      );
    729729
    730730   my $swport_ix = $swport_id;
    731    $swport_ix = $result_ix->{$research_ix} if defined $result_ix;
     731   $swport_ix = $result_ix->{$oid_search_ix} if defined $result_ix;
    732732
    733733   return snmp_get_switchport_ix2hr($snmp_session, $swport_ix);
     
    738738   my ($snmp_session, $swport_ix) = @_;
    739739
    740    my $research_hr = $OID_NUMBER{'ifName'} .'.'. $swport_ix;
     740   my $oid_search_hr = $OID_NUMBER{'ifName'} .'.'. $swport_ix;
    741741   my $result_hr = $snmp_session->get_request(
    742       -varbindlist => [$research_hr]
     742      -varbindlist => [$oid_search_hr]
    743743      );
    744744   my $swport_hr = $swport_ix;
    745    $swport_hr = normalize_port_human_readable($result_hr->{$research_hr}) if defined $result_hr;
     745   $swport_hr = normalize_port_human_readable($result_hr->{$oid_search_hr}) if defined $result_hr;
    746746
    747747   # Aggregator port
    748748   if ($swport_hr =~ m/^(Trk|Br|Po)/) {
    749       my $research_index = $OID_NUMBER{'ifAggregator'}; # base OID
    750       my @args = ( -varbindlist =>  [$research_index]);
     749      my $oid_search_index = $OID_NUMBER{'ifAggregator'}; # base OID
     750      my @args = ( -varbindlist =>  [$oid_search_index]);
    751751      LOOP_ON_OID_PORT:
    752752      while ( defined $snmp_session->get_next_request(@args) ) {
    753753         my ($oid_current) = $snmp_session->var_bind_names;
    754          last LOOP_ON_OID_PORT if  not Net::SNMP::oid_base_match($research_index, $oid_current);
     754         last LOOP_ON_OID_PORT if  not Net::SNMP::oid_base_match($oid_search_index, $oid_current);
    755755
    756756         # IEEE8023-LAG-MIB::dot3adAggPortSelectedAggID.28 = INTEGER: 337
     
    785785   return $swport_id if $swport_id =~ m/^\d+$/;
    786786
    787    my $research_ix = $OID_NUMBER{'ifIndex'}; # base OID
    788    my @args = ( -varbindlist =>  [$research_ix]);
     787   my $oid_search_ix = $OID_NUMBER{'ifIndex'}; # base OID
     788   my @args = ( -varbindlist =>  [$oid_search_ix]);
    789789   LOOP_ON_OID_PORT:
    790790   while ( defined $snmp_session->get_next_request(@args) ) {
    791791      my ($oid_current) = $snmp_session->var_bind_names;
    792       last LOOP_ON_OID_PORT if  not Net::SNMP::oid_base_match($research_ix, $oid_current);
     792      last LOOP_ON_OID_PORT if  not Net::SNMP::oid_base_match($oid_search_ix, $oid_current);
    793793     
    794794      my $port_ifIndex = $snmp_session->var_bind_list->{$oid_current};
     
    799799      @args = (-varbindlist => [$oid_current]);
    800800     
    801       my $oid_ifName = $OID_NUMBER{'ifName'} .'.'. $port_ifIndex;
    802       my $result = $snmp_session->get_request(-varbindlist => [$oid_ifName]);
     801      my $oid_search_ifName = $OID_NUMBER{'ifName'} .'.'. $port_ifIndex;
     802      my $result = $snmp_session->get_request(-varbindlist => [$oid_search_ifName]);
    803803      next LOOP_ON_OID_PORT if not defined $result;
    804804     
    805       my $current_port_hr = normalize_port_human_readable($result->{$oid_ifName});
    806       printf "PORT2: $oid_ifName => $current_port_hr\n" if $verbose;
     805      my $current_port_hr = normalize_port_human_readable($result->{$oid_search_ifName});
     806      printf "PORT2: $oid_search_ifName => $current_port_hr\n" if $verbose;
    807807      if ($current_port_hr eq $swport_hr) {
    808808         print "PORT3: $current_port_hr <-> $port_ix\n" if $verbose;
     
    823823   my %vlandb = (); # Hash vlan number => vlan name
    824824
    825    my $research_index = $OID_NUMBER{'vlanName'}; # base OID
    826    my @args = ( -varbindlist =>  [$research_index]);
     825   my $oid_search_index = $OID_NUMBER{'vlanName'}; # base OID
     826   my @args = ( -varbindlist =>  [$oid_search_index]);
    827827   LOOP_ON_VLAN:
    828828   while ( defined $snmp_session->get_next_request(@args) ) {
    829829      my ($oid_current) = $snmp_session->var_bind_names;
    830       last LOOP_ON_VLAN if not Net::SNMP::oid_base_match($research_index, $oid_current);
     830      last LOOP_ON_VLAN if not Net::SNMP::oid_base_match($oid_search_index, $oid_current);
    831831
    832832      my $vlan_name = $snmp_session->var_bind_list->{$oid_current};
     
    18351835         }
    18361836
    1837       my $search = $OID_NUMBER{'NApoeState'} . ".$switch_port"; # Only NEXANS switch and low port number
     1837      my $oid_search = $OID_NUMBER{'NApoeState'} . ".$switch_port"; # Only NEXANS switch and low port number
    18381838
    18391839      my $sw = $SWITCH_DB{$sw_name};
     
    18421842
    18431843      my $result = $session->set_request(
    1844          -varbindlist => [$search, INTEGER, 8], # Only NEXANS
     1844         -varbindlist => [$oid_search, INTEGER, 8], # Only NEXANS
    18451845         );
    18461846      print $session->error()."\n" if $session->error_status();
     
    18731873         }
    18741874
    1875       my $search = $OID_NUMBER{'NApoeState'} . ".$switch_port"; # Only NEXANS switch and low port number
     1875      my $oid_search = $OID_NUMBER{'NApoeState'} . ".$switch_port"; # Only NEXANS switch and low port number
    18761876
    18771877      my $sw = $SWITCH_DB{$sw_name};
     
    18801880
    18811881      my $result = $session->set_request(
    1882          -varbindlist => [$search, INTEGER, 2], # Only NEXANS
     1882         -varbindlist => [$oid_search, INTEGER, 2], # Only NEXANS
    18831883         );
    18841884      print $session->error()."\n" if $session->error_status();
     
    19111911         }
    19121912
    1913       my $search = $OID_NUMBER{'NApoeState'} . ".$switch_port"; # Only NEXANS switch and low port number
     1913      my $oid_search = $OID_NUMBER{'NApoeState'} . ".$switch_port"; # Only NEXANS switch and low port number
    19141914
    19151915      my $sw = $SWITCH_DB{$sw_name};
     
    19181918
    19191919      my $result = $session->get_request(
    1920          -varbindlist => [$search],
     1920         -varbindlist => [$oid_search],
    19211921         );
    19221922
    1923       if (defined $result and $result->{$search} ne 'noSuchInstance') {
    1924          my $poe_status = $result->{$search} || 'empty';
     1923      if (defined $result and $result->{$oid_search} ne 'noSuchInstance') {
     1924         my $poe_status = $result->{$oid_search} || 'empty';
    19251925         $poe_status =~ s/8/enable/;
    19261926         $poe_status =~ s/2/disable/;
     
    19531953         }
    19541954
    1955       my $research1 = $OID_NUMBER{'searchPort1'} . mac_address_hex2dec($mac_address);
    1956       my $research2 = $OID_NUMBER{'searchPort2'} .'.'. 0 . mac_address_hex2dec($mac_address);
    1957       print "Klask search OID $research1 on switch $sw_name\n";
    1958       print "Klask search OID $research2 on switch $sw_name\n";
     1955      my $oid_search_port1 = $OID_NUMBER{'searchPort1'} . mac_address_hex2dec($mac_address);
     1956      my $oid_search_port2 = $OID_NUMBER{'searchPort2'} .'.'. 0 . mac_address_hex2dec($mac_address);
     1957      print "Klask search OID $oid_search_port1 on switch $sw_name\n";
     1958      print "Klask search OID $oid_search_port2 on switch $sw_name\n";
    19591959
    19601960      my $sw = $SWITCH_DB{$sw_name};
     
    19631963
    19641964      my $result = $session->get_request(
    1965          -varbindlist => [$research1]
     1965         -varbindlist => [$oid_search_port1]
    19661966         );
    19671967      if (not defined $result) {
    19681968         $result = $session->get_request(
    1969             -varbindlist => [$research2]
     1969            -varbindlist => [$oid_search_port2]
    19701970            );
    1971          $result->{$research1} = $result->{$research2} if defined $result;
    1972          }
    1973 
    1974       if (defined $result and $result->{$research1} ne 'noSuchInstance') {
    1975          my $swport = $result->{$research1};
     1971         $result->{$oid_search_port1} = $result->{$oid_search_port2} if defined $result;
     1972         }
     1973
     1974      if (defined $result and $result->{$oid_search_port1} ne 'noSuchInstance') {
     1975         my $swport = $result->{$oid_search_port1};
    19761976         print "Klask find MAC $mac_address on switch $sw_name port $swport\n";
    19771977         }
     
    20062006         }
    20072007
    2008       my $search = $OID_NUMBER{'vlanPortDefault'} . ".$switch_port";
     2008      my $oid_search = $OID_NUMBER{'vlanPortDefault'} . ".$switch_port";
    20092009
    20102010      my $sw = $SWITCH_DB{$sw_name};
     
    20132013
    20142014      my $result = $session->get_request(
    2015          -varbindlist => [$search],
     2015         -varbindlist => [$oid_search],
    20162016         );
    20172017
    2018       if (defined $result and $result->{$search} ne 'noSuchInstance') {
    2019          my $vlan_id = $result->{$search} || 'empty';
     2018      if (defined $result and $result->{$oid_search} ne 'noSuchInstance') {
     2019         my $vlan_id = $result->{$oid_search} || 'empty';
    20202020         print "Klask VLAN Id $vlan_id on switch $sw_name on port $switch_port\n";
    20212021         }
     
    20832083         }
    20842084
    2085       my $search_vlan_name = $OID_NUMBER{'vlanName'} . ".$vlan_id";
     2085      my $oid_search_vlan_name = $OID_NUMBER{'vlanName'} . ".$vlan_id";
    20862086
    20872087      my $sw = $SWITCH_DB{$sw_name};
     
    20902090
    20912091      my $result = $session->get_request(
    2092          -varbindlist => [$search_vlan_name]
     2092         -varbindlist => [$oid_search_vlan_name]
    20932093         );
    20942094
    2095       if (defined $result and $result->{$search_vlan_name} ne 'noSuchInstance') {
    2096          my $vlan_name = $result->{$search_vlan_name} || 'empty';
     2095      if (defined $result and $result->{$oid_search_vlan_name} ne 'noSuchInstance') {
     2096         my $vlan_name = $result->{$oid_search_vlan_name} || 'empty';
    20972097         print "Klask find VLAN $vlan_id on switch $sw_name with name $vlan_name\n";
    20982098         }
     
    23332333   die "Error : Port $port_hr does not exist on switch $switch_name\n" if not $port_id =~ m/^\d+$/;
    23342334
    2335    my $search_portstatus = $OID_NUMBER{'portUpDown'} .'.'. $port_id;
    2336    print "Info: switch $switch_name port $port_hr SNMP OID $search_portstatus\n" if $verbose;
     2335   my $oid_search_portstatus = $OID_NUMBER{'portUpDown'} .'.'. $port_id;
     2336   print "Info: switch $switch_name port $port_hr SNMP OID $oid_search_portstatus\n" if $verbose;
    23372337
    23382338   my $result = $session->set_request(
    2339       -varbindlist => [$search_portstatus, INTEGER, 1],
     2339      -varbindlist => [$oid_search_portstatus, INTEGER, 1],
    23402340      );
    23412341   print $session->error()."\n" if $session->error_status();
     
    23782378   die "Error : Port $port_hr does not exist on switch $switch_name\n" if not $port_id =~ m/^\d+$/;
    23792379
    2380    my $search_portstatus = $OID_NUMBER{'portUpDown'} .'.'. $port_id;
    2381    print "Info: switch $switch_name port $port_hr SNMP OID $search_portstatus\n" if $verbose;
     2380   my $oid_search_portstatus = $OID_NUMBER{'portUpDown'} .'.'. $port_id;
     2381   print "Info: switch $switch_name port $port_hr SNMP OID $oid_search_portstatus\n" if $verbose;
    23822382
    23832383   my $result = $session->set_request(
    2384       -varbindlist => [$search_portstatus, INTEGER, 2],
     2384      -varbindlist => [$oid_search_portstatus, INTEGER, 2],
    23852385      );
    23862386   print $session->error()."\n" if $session->error_status();
     
    24212421   die "Error : Port $port_hr does not exist on switch $switch_name\n" if not $port_id =~ m/^\d+$/;
    24222422
    2423    my $search_portstatus = $OID_NUMBER{'portUpDown'} .'.'. $port_id;
    2424    print "Info: switch $switch_name port $port_hr ($port_id) SNMP OID $search_portstatus\n" if $verbose;
     2423   my $oid_search_portstatus = $OID_NUMBER{'portUpDown'} .'.'. $port_id;
     2424   print "Info: switch $switch_name port $port_hr ($port_id) SNMP OID $oid_search_portstatus\n" if $verbose;
    24252425
    24262426   my $result = $session->get_request(
    2427       -varbindlist => [$search_portstatus]
     2427      -varbindlist => [$oid_search_portstatus]
    24282428      );
    24292429   print $session->error()."\n" if $session->error_status();
    24302430   if (defined $result) {
    2431       print "$PORT_UPDOWN{$result->{$search_portstatus}}\n";
     2431      print "$PORT_UPDOWN{$result->{$oid_search_portstatus}}\n";
    24322432      }
    24332433
     
    24652465         }
    24662466
    2467       my $research1 = $OID_NUMBER{'searchPort1'} . mac_address_hex2dec($mac_address);
    2468       my $research2 = $OID_NUMBER{'searchPort2'} .'.'. $vlan_id . mac_address_hex2dec($mac_address);
    2469       print "Klask search OID $research1 on switch $sw_name\n" if $verbose;
    2470       print "Klask search OID $research2 on switch $sw_name\n" if $verbose;
     2467      my $oid_search_port1 = $OID_NUMBER{'searchPort1'} . mac_address_hex2dec($mac_address);
     2468      my $oid_search_port2 = $OID_NUMBER{'searchPort2'} .'.'. $vlan_id . mac_address_hex2dec($mac_address);
     2469      print "Klask search OID $oid_search_port1 on switch $sw_name\n" if $verbose;
     2470      print "Klask search OID $oid_search_port2 on switch $sw_name\n" if $verbose;
    24712471
    24722472      my $sw = $SWITCH_DB{$sw_name};
     
    24752475
    24762476      my $result = $session->get_request(
    2477          -varbindlist => [$research1]
     2477         -varbindlist => [$oid_search_port1]
    24782478         );
    24792479      if (not defined $result) {
    24802480         $result = $session->get_request(
    2481             -varbindlist => [$research2]
     2481            -varbindlist => [$oid_search_port2]
    24822482            );
    2483          $result->{$research1} = $result->{$research2} if defined $result;
    2484          }
    2485 
    2486       if (defined $result and $result->{$research1} ne 'noSuchInstance') {
    2487          my $swport_id = $result->{$research1};
     2483         $result->{$oid_search_port1} = $result->{$oid_search_port2} if defined $result;
     2484         }
     2485
     2486      if (defined $result and $result->{$oid_search_port1} ne 'noSuchInstance') {
     2487         my $swport_id = $result->{$oid_search_port1};
    24882488         my $swport_hr = snmp_get_switchport_id2hr($session, $swport_id);
    24892489         print "Klask find MAC $mac_address on switch $sw_name port $swport_hr\n";
Note: See TracChangeset for help on using the changeset viewer.