Home: Need a Custom or Prewritten Perl Program?: I need a program that...:
how to get proper snmpget values using perl script



venuyacha
New User

May 11, 2011, 5:02 AM


Views: 6522
how to get proper snmpget values using perl script

Hi,

I want to get the sysUptime(1.3.6.1.2.1.1.3.0) in a perl script.
I have installed Net-SNMP in my machine and snmp commands work in my machine.
I tried using the following way to retrieve the value
chomp($sysUpTime = `$SNMP_GET_CMD $SNMP_TARGET1 1.3.6.1.2.1.1.3.0`);

if I print $sysUpTime , I m getting the following output
"DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (61115500) 7 days, 1:45:55.00"

But I want to capture only the value i.e 61115500 .
Can someone help how to do that.
Let me know which perl module I can use to get the exact value of the MIB object instead of the complete display string .

Thanks in advance.


FishMonger
Veteran / Moderator

May 11, 2011, 3:00 PM


Views: 6513
Re: [venuyacha] how to get proper snmpget values using perl script

If you have Net::SNMP installed, why are you using a system command in backticks instead of using the module?

If you want to stick with the backticks approach, you'll need to use a regex to parse out the desired value.

If you use the module, I think it will return the value directly, but I can't test that until I get back to work tomorrow.


venuyacha
New User

May 11, 2011, 9:55 PM


Views: 6504
Re: [FishMonger] how to get proper snmpget values using perl script

I have installed Net-SNMP on my windows machine so that I can execute snmp methods(get,set,walk....) on windows command prompt. I havent installed any Perl module related to SNMP.
I tried exploring the SNMP modules available by googling. But couldnt find any specific to my requirement.
I appreciate any help you provide.
Thanks.


FishMonger
Veteran / Moderator

May 12, 2011, 5:33 AM


Views: 6493
Re: [venuyacha] how to get proper snmpget values using perl script

If you're using Activestate perl, then you'd use the ppm utility to install the module.

Quote
C:\>ppm install Net::SNMP


The module documentation can be found here: http://search.cpan.org/~dtown/Net-SNMP-v6.0.1/lib/Net/SNMP.pm

Other SNMP related modules: http://search.cpan.org/search?query=net%3A%3Asnmp&mode=all