ikkeniet has asked for the wisdom of the Perl Monks concerning the following question:

If have a piece of simple code that connects to a Cisco switch and returns the value for the in & out bytes. Problem is that it works fine when using standard 32 bit counters but when trying to use it against a Gigabit switch the value is always 64 assuming it is a Counter64 type. How can I get the value from a 64 bit counter. Here is my code:
my ($session, $error) = Net::SNMP->session( -hostname => shift || $SNMP_host, -community => shift || $SNMP_community, -port => shift || $SNMP_port, ); my $result = $session->get_request( -varbindlist => [".1.3.6.1.2.1.2.2.1.10.1"] ); my $temp=$result->{".1.3.6.1.2.1.2.2.1.10.1"} ;
In normal counters $temp returns the value, but with a Gigabit switch it seems to be of type Counter64 and the value of $temp is always 64. I am sure I am missing something pretty easy but I just keep breaking my head on it.

Replies are listed 'Best First'.
Re: Perl NET::SNMP - Counter64
by fullermd (Vicar) on Aug 25, 2009 at 11:05 UTC

    I don't have any real knowledge of what could be going on. But I'd try Data::Dumper'ing $result just to see if there were any hints there.

Re: Perl NET::SNMP - Counter64
by Sewi (Friar) on Aug 25, 2009 at 12:42 UTC
    I'm using
    ->get_table( Callback => [\&Process_Data,$id], baseoid => '1.3.6.1.2.1.31.1.1.1.x');
    ...where x is 1 for the ifname, 6 for the in-bytes-counter64 and 10 for the out-bytes-counter64. You _may_ be using the wrong OID.
    You may also want to add "version => 2" to your ->session - call.

    You should split the data fetching and processing into two scripts. You'll need "use bigint;" for Perl-calculations with 64bit numbers, but Net::SNMP fails here if I use bigint in the same script. The whole SNMP reply is handled as a string by my script and written using "CONVERT(UNSIGNED BIGINT,'12345')" (for Sybase SQL).