how will I change the code the 1st code according to the 2nd one? 1st code -
sub snmpGet(@)
-
{
-
# Assign arguments
-
my ($deviceName)=$_[0]; # Device name to read from
-
my ($community)=$_[1]; # SNMP Community String
-
my ($timeout)=$_[2]; # Timeout value for SNMP-GET request
-
my ($type)=$_[3]; # SNMP Object Type
-
my ($oid)=$_[4]; # SNMP Object ID
-
my ($version)=$_[5]; # SNMP Version
-
my ($port)=$_[6]; # Port
-
-
# Local variables
-
my ($result); # Output from SNMP-GET
-
-
-
# Set default version and port
-
if ($version) { $version='-v ' . $version; } else { $version=''; }
-
if ($port) { $port='-p ' . $port; } else { $port=''; }
-
-
# Check parameters
-
unless ($deviceName && $community && $timeout && $type && $oid)
-
{
-
# Missing parameter
-
rxnnmsLogError("${snmpErrorPrefix}snmpGet:missing parameter:snmpGet($deviceName,$community,$timeout,$type,$oid");
-
return;
-
}
-
-
# Check for valid type
-
unless ($type eq $snmpIntegerType || $type eq $snmpIPAddressType ||
-
$type eq $snmpOctetStringType || $type eq $snmpGauge32Type ||
-
$type eq $snmpCounter64Type || $type eq $snmpTimeTicksType)
-
{
-
rxnnmsLogError("${snmpErrorPrefix}snmpGet:invalid type:$type");
-
return;
-
}
-
-
# Generate the SNMP-GET using syntax of underlying SNMP implementation.
-
rxnnmsLogTrace("$snmpget $version $port -c $community -t $timeout $deviceName $oid");
-
$result=`$snmpget $version $port -c $community -t $timeout $deviceName $oid 2>&1`;
-
-
# Trace output of snmpget command
-
chomp($result);
-
rxnnmsLogTrace("$snmpget $oid to $deviceName returned: $result");
-
-
# If $type is 'integer' and $result contains 'INTEGER' or 'Unsigned' then SNMP-GET ran
-
# successfully, so return $result, etc. Otherwise return '$snmpErrorPrefix$result'
-
# (bad status).
-
-
if (($type=$snmpIntegerType && $result=~/INTEGER/) ||
-
($type=$snmpIntegerType && $result=~/Unsigned/) ||
-
($type=$snmpIPAddressType && $result=~/IpAddress/) ||
-
($type=$snmpOctetStringType && $result=~/DISPLAY STRING/) ||
-
($type=$snmpOctetStringType && $result=~/OCTET STRING/) ||
-
($type=$snmpGauge32Type && $result=~/Gauge32/) ||
-
($type=$snmpCounter64Type && $result=~/Counter64/) ||
-
($type=$snmpTimeTicksType && $result=~/Timeticks/))
-
{
-
# SNMP-GET successful. Return output.
-
rxnnmsLogTrace("$snmpget $oid from $deviceName was successful");
-
return($result);
-
}
-
else
-
{
-
# SNMP-GET failed. Return error.
-
rxnnmsLogTrace("$snmpget $oid from $deviceName failed: $result");
-
return("$snmpErrorPrefix$result");
-
}
-
-
} # End of snmpGet
-
2nd code -
sub snmpget ($@) {
-
my($host, @vars) = @_;
-
my(@enoid, $var, $response, $bindings, $binding, $value, $oid, @retvals);
-
my $session;
-
-
$session = &snmpopen($host, 0, \@vars);
-
if (!defined($session)) {
-
carp "SNMPGET Problem for $host\n"
-
unless ($SNMP_Session::suppress_warnings > 1);
-
return undef;
-
}
-
-
@enoid = &toOID(@vars);
-
return undef unless defined $enoid[0];
-
-
if ($session->get_request_response(@enoid)) {
-
$response = $session->pdu_buffer;
-
($bindings) = $session->decode_get_response($response);
-
while ($bindings) {
-
($binding, $bindings) = decode_sequence($bindings);
-
($oid, $value) = decode_by_template($binding, "%O%@");
-
my $tempo = pretty_print($value);
-
push @retvals, $tempo;
-
}
-
return(@retvals);
-
}
-
$var = join(' ', @vars);
-
carp "SNMPGET Problem for $var on $host\n"
-
unless ($SNMP_Session::suppress_warnings > 1);
-
return undef;
-
}
-
7 3509
First, you need to please use code tags around any code you post into the forums. There is a sample in the "Reply Guidelines" next to your reply window.
Also, you need to please better explain what it is you are looking for or to do as I don't know what you want.
Regards,
Jeff (Moderator)
NOTE:: I have deleted your second AND third posts as they are duplicates of this one. Just because you have a short timeline and what you are working on is urgent, please know that that urgency does not translate into an urgency for us. We are all volunteers here and are not under your same time crunch. Please DO NOT double post your questions just because you do not get an answer as quick as you expect.
I don't even understand what the question/problem is, so there is no way to begin to answer it.
hi,
First of all the 2nd and third posts were different codes from the 1st post.They were not the same codes.I value your and mine time.
The 1st code is from a HP OV CommonSnmp.pm.The 2nd code is from snmp_util.pm.
I just wanted the 1st code to be transparent to the second code. i.e. the parameters that are passed by the 1st code must be same as the 2nd code. Also the operations of the 1st code to be same as the 2nd code. So that when I use CommonSnmp.pm it works alike like snmp_util.pm.
Also the 2nd code has called the subroutines like snmpopen & toOID.the definations are as follows: - sub snmpopen ($$$) {
-
my($host, $type, $vars) = @_;
-
my($nhost, $port, $community, $lhost, $lport, $nlhost);
-
my($timeout, $retries, $backoff, $version);
-
my $v4onlystr;
-
-
$type = 0 if (!defined($type));
-
$community = "public";
-
$nlhost = "";
-
-
($community, $host) = ($1, $2) if ($host =~ /^(.*)@([^@]+)$/);
-
-
# We can't split on the : character because a numeric IPv6
-
# address contains a variable number of :'s
-
my $opts;
-
if( ($host =~ /^(\[.*\]):(.*)$/) || ($host =~ /^(\[.*\])$/) ) {
-
# Numeric IPv6 address between []
-
($host, $opts) = ($1, $2);
-
} else {
-
# Hostname or numeric IPv4 address
-
($host, $opts) = split(':', $host, 2);
-
}
-
($port, $timeout, $retries, $backoff, $version, $v4onlystr) = split(':', $opts, 6)
-
if(defined($opts) && (length $opts > 0) );
-
-
undef($version) if (defined($version) && length($version) <= 0);
-
$v4onlystr = "" unless defined $v4onlystr;
-
$version = '1' unless defined $version;
-
if (defined($port) && ($port =~ /^([^!]*)!(.*)$/)) {
-
($port, $lhost) = ($1, $2);
-
$nlhost = $lhost;
-
($lhost, $lport) = ($1, $2) if ($lhost =~ /^(.*)!(.*)$/);
-
undef($lhost) if (defined($lhost) && (length($lhost) <= 0));
-
undef($lport) if (defined($lport) && (length($lport) <= 0));
-
}
-
undef($port) if (defined($port) && length($port) <= 0);
-
$port = 162 if ($type == 1 && !defined($port));
-
$nhost = "$community\@$host";
-
$nhost .= ":" . $port if (defined($port));
-
-
if ((!defined($SNMP_util::Session))
-
|| ($SNMP_util::Host ne $nhost)
-
|| ($SNMP_util::Version ne $version)
-
|| ($SNMP_util::LHost ne $nlhost)
-
|| ($SNMP_util::IPv4only ne $v4onlystr)) {
-
if (defined($SNMP_util::Session)) {
-
$SNMP_util::Session->close();
-
undef $SNMP_util::Session;
-
undef $SNMP_util::Host;
-
undef $SNMP_util::Version;
-
undef $SNMP_util::LHost;
-
undef $SNMP_util::IPv4only;
-
}
-
$SNMP_util::Session = ($version =~ /^2c?$/i)
-
? SNMPv2c_Session->open($host, $community, $port, undef,
-
$lport, undef, $lhost, ($v4onlystr eq 'v4only') ? 1:0 )
-
: SNMP_Session->open($host, $community, $port, undef,
-
$lport, undef, $lhost, ($v4onlystr eq 'v4only') ? 1:0 );
-
($SNMP_util::Host = $nhost, $SNMP_util::Version = $version,
-
$SNMP_util::LHost = $nlhost, $SNMP_util::IPv4only = $v4onlystr) if defined($SNMP_util::Session);
-
}
-
-
if (defined($SNMP_util::Session)) {
-
if (ref $vars->[0] eq 'HASH') {
-
my $opts = shift @$vars;
-
foreach $type (keys %$opts) {
-
if ($type eq 'return_array_refs') {
-
$SNMP_util::Return_array_refs = $opts->{$type};
-
}
-
else {
-
if (exists $SNMP_util::Session->{$type}) {
-
if ($type eq 'timeout') {
-
$SNMP_util::Session->set_timeout($opts->{$type});
-
} elsif ($type eq 'retries') {
-
$SNMP_util::Session->set_retries($opts->{$type});
-
} elsif ($type eq 'backoff') {
-
$SNMP_util::Session->set_backoff($opts->{$type});
-
} else {
-
$SNMP_util::Session->{$type} = $opts->{$type};
-
}
-
} else {
-
carp "SNMPopen Unknown SNMP Option Key '$type'\n"
-
unless ($SNMP_Session::suppress_warnings > 1);
-
}
-
}
-
}
-
}
-
$SNMP_util::Session->set_timeout($timeout)
-
if (defined($timeout) && (length($timeout) > 0));
-
$SNMP_util::Session->set_retries($retries)
-
if (defined($retries) && (length($retries) > 0));
-
$SNMP_util::Session->set_backoff($backoff)
-
if (defined($backoff) && (length($backoff) > 0));
-
}
-
return $SNMP_util::Session;
-
}
-
- sub toOID(@) {
-
my(@vars) = @_;
-
my($oid, $var, $tmp, $tmpv, @retvar);
-
-
undef @retvar;
-
foreach $var (@vars) {
-
($oid, $tmp) = &Check_OID($var);
-
if (!$oid && $SNMP_util::CacheLoaded == 0) {
-
$tmp = $SNMP_Session::suppress_warnings;
-
$SNMP_Session::suppress_warnings = 1000;
-
-
&snmpLoad_OID_Cache($SNMP_util::CacheFile);
-
-
$SNMP_util::CacheLoaded = 1;
-
$SNMP_Session::suppress_warnings = $tmp;
-
-
($oid, $tmp) = &Check_OID($var);
-
}
-
while (!$oid && $#SNMP_util::MIB_Files >= 0) {
-
$tmp = $SNMP_Session::suppress_warnings;
-
$SNMP_Session::suppress_warnings = 1000;
-
-
snmpMIB_to_OID(shift(@SNMP_util::MIB_Files));
-
-
$SNMP_Session::suppress_warnings = $tmp;
-
-
($oid, $tmp) = &Check_OID($var);
-
if ($oid) {
-
open(CACHE, ">>$SNMP_util::CacheFile");
-
print CACHE "$tmp\t$oid\n";
-
close(CACHE);
-
}
-
}
-
if ($oid) {
-
$var =~ s/^$tmp/$oid/;
-
} else {
-
carp "Unknown SNMP var $var\n"
-
unless ($SNMP_Session::suppress_warnings > 1);
-
next;
-
}
-
while ($var =~ /\"([^\"]*)\"/) {
-
$tmp = sprintf("%d.%s", length($1), join(".", map(ord, split(//, $1))));
-
$var =~ s/\"$1\"/$tmp/;
-
}
-
print "toOID: $var\n" if $SNMP_util::Debug;
-
$tmp = encode_oid_with_errmsg($var);
-
return undef unless defined $tmp;
-
push(@retvar, $tmp);
-
}
-
return @retvar;
-
}
-
Sorry mate, I have no idea.
toOID subroutine has depemdencies on the following subroutines Check_OID : - sub Check_OID ($) {
-
my($var) = @_;
-
my($tmp, $tmpv, $oid);
-
-
if ($var =~ /^(([a-zA-Z][a-zA-Z\d\-]*\.)*([a-zA-Z][a-zA-Z\d\-]*))/)
-
{
-
$tmp = $&;
-
$tmpv = $tmp;
-
for (;;) {
-
last if defined($SNMP_util::OIDS{$tmpv});
-
last if !($tmpv =~ s/^[^\.]*\.//);
-
}
-
$oid = $SNMP_util::OIDS{$tmpv};
-
if ($oid) {
-
return ($oid, $tmp);
-
} else {
-
return undef;
-
}
-
}
-
return ($var, $var);
-
}
-
Moon1:
I have asked you nicely to please use code tags in a previous post AND I have even sent you a PM (private message) relating to your lack of code tags use. This is your last warning, use code tags or I will be forced to ban you for 1 week for failure to comply with site guidelines AND not listening to the suggestions of Moderator(s).
Regards, Moderator Sign in to post your reply or Sign up for a free account.
Similar topics
by: Matthew Bell |
last post by:
Hi,
I'm looking for a high-performance SNMP manager toolkit (SNMPv1 / v2,
GET / GETNEXT / GETBULK) I can use with Python on Windows2K/XP. I
wonder if anyone has got any suggestions? Commercial...
|
by: dan byers |
last post by:
hey everyone, i'm working on a system to monitor devices through SNMP.
i'm using the Net::SNMP modules by D.Town.
i try to load the snmp session request with a set of OIDs to make the system...
|
by: Kevin Ingram |
last post by:
Is it possible to connect to devices and read SNMP data with ASP? I did a
search and all I could find was utilities for sale to do it, wondered if it
can be done using straight ASP.
We are using...
|
by: Danny |
last post by:
I need an asp command to strip out from a string all extra punctuation such
as apostrophe, comma, period, spaces dashes, etc etc and just leave the
letters.
Can anybody give me some ideas?
...
|
by: mony |
last post by:
I am looking a VB.NET example on how to reference the SNMP API information.
I am unable to add references to SNMPAPI.LIB or SNMPAPI.DLL.
My goal is to write a 100% VB.NET example (no C or C#...
|
by: TiToine |
last post by:
Hi,
I'am using the SnmpMgrOpen() api function.
#######################################################################
LPSNMP_MGR_SESSION SnmpMgrOpen(
LPSTR lpAgentAddress, // name and...
|
by: Schroeder, AJ |
last post by:
Hello group,
I performed binary installs of Net-SNMP and PHP 4.4.4 on my Windows XP
laptop so that I can do some offline development/testing away from my Linux
server. Anyway, I attempted to do...
|
by: kr99 |
last post by:
I am trying to run a scrpt and I get an error indicating that the Perl Net::SNMP module may not be loaded.
#perl udpInOut.pl localhost 161 public 1
"Can't locate object method "session" via...
|
by: Dirk Van de moortel |
last post by:
{
OOPS, posted this to moderated group perl.cpan.discuss as
well, so it can take a while to get through, if it gets through at all
Otherwise sorry for duplicate posting
}
We need to set up a...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |