Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: To unpack or not to unpack

by larryl (Scribe)
on Mar 14, 2001 at 22:54 UTC ( #64455=note: print w/replies, xml ) Need Help??

in reply to To unpack or not to unpack

It's not clear from your code what format you're using for $target (the get() functions accepts a bunch of different input formats) - it might be easiest to use an SNMP::Varbind object as the input for get(). An SNMP::Varbind object is a blessed reference to an array with 5 elements:
- object name (e.g. "sysdesc" or "."
- dotted-decimal instance ID (or "0" for scalar objects)
- value
- value type (e.g. "IPADDR", "COUNTER", etc.)
- timestamp

You can set the name of the object, and get() will populate the rest of the info, which you can then test to figure out what format the return value is in. Assuming your input target is a string like "sysDescr" or ".", you should be able to do something like:

my $var = new SNMP::Varbind( [ $target ] ); my $value = $session->get($var) || warn "SNMP ERROR: $session->{ErrorStr}"; print "name: ", $var->name, "\n"; print "type: ", $var->type, "\n"; if ( $var->type eq "IPADDR" ) { ... unpack $var->val here ... } elsif ( $var->type eq "COUNTER" ) { ... unpack $var->val here ... } elsif ...

The SNMP man page will list all the valid variable types that you might need to deal with.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://64455]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2017-02-19 22:18 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (293 votes). Check out past polls.