SNMP_Session

 view release on metacpan or  search on metacpan

Net_SNMP_util.pm  view on Meta::CPAN

      return @empty;
    }
  }
  return ($var, $var);
}

sub snmpwalk_flg ($$@) {
  my($host, $hash_sub, @vars) = @_;
  my($session, %args, @enoid, @poid, $toid, $oid, $got);
  my($val, $ret, %soid, %nsoid, @retvals, $tmp);
  my(%rethash, $h_ref, @tmprefs);
  my($stop);

  $h_ref = (ref $vars[$#vars] eq "HASH") ? pop(@vars) : \%rethash;

  $session = &snmpopen($host, 0, \@vars);
  if (!defined($session)) {
    carp "SNMPWALK Problem for $host"
      unless ($Net_SNMP_util::SuppressWarnings > 1);
    if (defined($hash_sub)) {
      return ($h_ref) if ($SNMP_util::Return_hash_refs);

Net_SNMP_util.pm  view on Meta::CPAN

  if (defined($hash_sub) and ($RevNeeded)) {
      %revOIDS = reverse %Net_SNMP_util::OIDS;
      $RevNeeded = 0;
  }

  #
  # Create temporary array of refs to return values
  #
  foreach $oid (0..$#enoid)  {
    my $tmparray = [];
    $tmprefs[$oid] = $tmparray;
    $nsoid{$oid} = $oid;
  }

  $got = 0;
  @poid = @enoid;

  if ($Net_SNMP_util::Version > 1 and $Net_SNMP_util::MaxRepetitions > 0) {
    $args{'-maxrepetitions'} = $Net_SNMP_util::MaxRepetitions;
  }
  if ($Net_SNMP_util::Version > 2) {

Net_SNMP_util.pm  view on Meta::CPAN

	      $inst = substr($oid, length($tmpo)+1);
	    }
	    #
	    # call hash_sub
	    #
	    &$hash_sub($h_ref, $host, $qoid, $tmpo, $inst, $ret->{$oid}, $upo);
	  } else {
	    my $tmpo;
	    my $tmpv = $ret->{$oid};
	    $tmpo = substr($oid, length($toid)+1);
	    push @{$tmprefs[$tmp]}, "$tmpo:$tmpv";
	  }
	} else {
	  $stop = 1 if ($#enoid == 0);
	}
      }
    }
    undef @poid;
    @poid = values %nsoid if (!$stop);
  }
  if ($got) {
    if (defined($hash_sub)) {
	return ($h_ref) if ($Net_SNMP_util::ReturnHashRefs);
    	return (%$h_ref);
    } elsif ($Net_SNMP_util::Return_array_refs)  {
      return (@tmprefs);
    } else {
      do {
	$got = 0;
	foreach $toid (0..$#enoid) {
	  next if (scalar(@{$tmprefs[$toid]}) <= 0);
	  $got = 1;
	  $oid = shift(@{$tmprefs[$toid]});
	  if ($#enoid > 0) {
	    ($oid, $val) = split(':', $oid, 2);
	    $oid = $enoid[$toid] . '.' . $oid;
	    push(@retvals, "$oid:$val");
	  } else {
	    push(@retvals, $oid);
	  }
	}
      } while($got);
      return (@retvals);

lib/SNMP_util.pm  view on Meta::CPAN

# Walk the MIB, putting everything you find into hashes.
#
sub snmpwalkhash($$@) {
#  my($host, $hash_sub, @vars) = @_;
  return(&snmpwalk_flg( @_ ));
}

sub snmpwalk_flg ($$@) {
  my($host, $hash_sub, @vars) = @_;
  my(@enoid, $var, $response, $bindings, $binding);
  my($value, $upoid, $oid, @retvals, @retvaltmprefs);
  my($got, @nnoid, $noid, $ok, $ix, @avars);
  my $session;
  my(%soid);
  my(%done, %rethash, $h_ref);

  $h_ref = (ref $vars[$#vars] eq "HASH") ? pop(@vars) : \%rethash;

  $session = &snmpopen($host, 0, \@vars);
  if (!defined($session)) {
    carp "SNMPWALK Problem for $host\n"

lib/SNMP_util.pm  view on Meta::CPAN

   
  @avars = @vars;

  # IlvJa
  #
  # Create temporary array of refs to return vals.

  if ($SNMP_util::Return_array_refs) {
    for($ix = 0;$ix < scalar @vars; $ix++) {
      my $tmparray = [];
      $retvaltmprefs[$ix] = $tmparray;
      $retvals[$ix] = $tmparray;
    }
  }


  while(($SNMP_util::Version ne '1' and $session->{'use_getbulk'})
    ? $session->getbulk_request_response(0,
					  $session->default_max_repetitions(),
					  @nnoid)
    : $session->getnext_request_response(@nnoid))

lib/SNMP_util.pm  view on Meta::CPAN

	$upoid = $noid;
      } else {
	# IlvJa
	#
	# The walk for variable $vars[$ix] has been finished as
	# $nnoid[$ix] no longer is in the $avar[$ix] OID tree.
	# So we exclude this variable from further requests.

	$avars[$ix] = "";
	$nnoid[$ix] = "";
	$retvaltmprefs[$ix] = undef if $SNMP_util::Return_array_refs;
      }
      if ($ok) {
	my $tmp = encode_oid_with_errmsg ($tempo);
	if (!defined $tmp) {
	  if (defined($hash_sub)) {
	    return ($h_ref) if ($SNMP_util::Return_hash_refs);
	    return (%$h_ref);
	  } else {
	    @retvals = ();
	    return (@retvals);
	  }
	}
	if (exists($done{$tmp})) {	# GIL, Ilvja
	  #
	  # We've detected a loop for $nnoid[$ix], so mark it as finished.
	  # Exclude this variable from further requests.
	  #
	  $avars[$ix] = "";
	  $nnoid[$ix] = "";
	  $retvaltmprefs[$ix] = undef if $SNMP_util::Return_array_refs;
	  next;
	}
	$nnoid[$ix] = $tmp;   # Keep on walking. (IlvJa)
	my $tempv = pretty_print($value);
	if (defined($hash_sub)) {
	  #
	  # extract name of the oid, if possible, the rest becomes the instance
	  #
	  my $inst = "";
	  my $upo = $upoid;

lib/SNMP_util.pm  view on Meta::CPAN

	    $var = pretty_print($oid);
	  }
	  #
	  # call hash_sub
	  #
	  &$hash_sub($h_ref, $host, $var, $tempo, $inst,
			$tempv, $upo);
	} else {
	  if ($SNMP_util::Return_array_refs) {
	    $tempo=~s/^$upoid\.//;
	    push @{$retvaltmprefs[$ix]}, "$tempo:$tempv";
	  } else {
	    $tempo=~s/^$upoid\.// if ($#enoid <= 0);
	    push @retvals, "$tempo:$tempv";
	  }
	}
	$done{$tmp} = 1;	# GIL
      }
      $ix = ++$ix % (scalar @avars);
    }

    # Ok, @nnoid should contain the remaining variables for the
    # next request.  Some or all entries in @nnoid might be the empty
    # string.  If the nth element in @nnoid is "" that means that
    # the walk related to the nth variable in the last request has been
    # completed and we should not include that var in subsequent reqs.

    # Clean up both @nnoid and @avars so "" elements are removed.
    @nnoid = grep (($_), @nnoid);
    @avars = grep (($_), @avars);
    @retvaltmprefs = grep (($_), @retvaltmprefs);

    last if ($#nnoid < 0);   # @nnoid empty means we are done walking.
  }
  if (!$got) {
    $var = join(' ', @vars);
    carp "SNMPWALK Problem for $var on $host\n"
      unless ($SNMP_Session::suppress_warnings > 1);
    @retvals = ();
  }
  if (defined($hash_sub)) {



( run in 0.882 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )