Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

snmp script with perl

by MacScissor (Acolyte)
on Dec 06, 2012 at 15:34 UTC ( #1007607=perlquestion: print w/ replies, xml ) Need Help??
MacScissor has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks! I have the following script:
#!/usr/bin/perl use strict; use warnings; use Net::SNMP; my ($session, $error) = Net::SNMP->session(Hostname => '', Community => 'testcommunity', port => 161) or die "Session: $!\015\012"; my $ram = $session->get_request("") + or die "get_request ram: $!\015\012"; my $uptime = $session->get_request("") +or die "get_request uptime: $!\015\012"; my $drive1 = $session->get_request("") + or die "get_request drive1: $!\015\012"; my $processes = $session->get_request("") + or die "get_request processes: $!\015\12"; $session->close; print "RAM: ".$ram->{""}."\015\12"; print "Uptime: ".$uptime->{""}."\015\012"; print "Drive 1: ".$drive1->{""}."\015\012"; print "Processes: ".$processes->{""}."\015\012";
The script is executed under linux, the target host is a windows machine. There are no errors, but the output is just
RAM: Uptime: Drive 1: Processes:
When I try the same script under windows (with target host "localhost") the values are returned correctly. Where is my mistake? Thanks in advance!

Comment on snmp script with perl
Select or Download Code
Re: snmp script with perl
by greengaroo (Hermit) on Dec 06, 2012 at 15:38 UTC

    Try use Data::Dumper; then do print Dumper $ram, $uptime, $drive1, $processes;

    Try that first to see if your structures have any content at all, maybe this will help.

    Testing never proves the absence of faults, it only shows their presence.
      Hello and thanks for your reply! I added the lines to the code, now the output is
      Aktive Prozesse: $VAR1 = { '' => '' }; $VAR2 = { '' => '' }; $VAR3 = { '' => '' }; $VAR4 = { '' => '' };

        OK your hashref values are empty so that explains why your output is empty. Also if you print the string "\015\12", remember that special characters such as \0 and \1 are interpreted in double quotes, so if you really want to print that string, put it in single quotes.

        Testing never proves the absence of faults, it only shows their presence.
Re: snmp script with perl
by blue_cowdawg (Monsignor) on Dec 06, 2012 at 15:54 UTC

    Check the community settings and ACL settings for the snmpd on the target host. I've seen that trip folks up before.

    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
Re: snmp script with perl
by RichardK (Priest) on Dec 06, 2012 at 16:08 UTC

    have you got the same version of Net::SNMP on both machines ?

    Your get_request() call doesn't look like the one in the Net::SNMP pod, so maybe some version problem?

    Does error() return anything useful?

    updated! I really meant get_request not get_session, sorry about that.

Re: snmp script with perl
by FloydATC (Chaplain) on Dec 06, 2012 at 19:26 UTC
    Use the snmpwalk tool to verify that the SNMP daemon returns anything for those OIDs. The standard SNMP daemon shipped with Windows is missing a lot of important metrics. Consider installing another one, like

    -- Time flies when you don't know what you're doing

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1007607]
Approved by blue_cowdawg
Front-paged by blue_cowdawg
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2014-11-27 23:37 GMT
Find Nodes?
    Voting Booth?

    My preferred Perl binaries come from:

    Results (190 votes), past polls