Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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 => '172.25.0.5', Community => 'testcommunity', port => 161) or die "Session: $!\015\012"; my $ram = $session->get_request("1.3.6.1.2.1.25.2.2.0") + or die "get_request ram: $!\015\012"; my $uptime = $session->get_request("1.3.6.1.2.1.25.1.1.0") +or die "get_request uptime: $!\015\012"; my $drive1 = $session->get_request("1.3.6.1.2.1.25.2.3.1.6.1") + or die "get_request drive1: $!\015\012"; my $processes = $session->get_request("1.3.6.1.2.1.25.1.6.0") + or die "get_request processes: $!\015\12"; $session->close; print "RAM: ".$ram->{"1.3.6.1.2.1.25.2.2.0"}."\015\12"; print "Uptime: ".$uptime->{"1.3.6.1.2.1.25.1.1.0"}."\015\012"; print "Drive 1: ".$drive1->{"1.3.6.1.2.1.25.2.3.1.6.1"}."\015\012"; print "Processes: ".$processes->{"1.3.6.1.2.1.25.1.6.0"}."\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 = { '1.3.6.1.2.1.25.2.2.0' => '' }; $VAR2 = { '1.3.6.1.2.1.25.1.1.0' => '' }; $VAR3 = { '1.3.6.1.2.1.25.2.3.1.6.1' => '' }; $VAR4 = { '1.3.6.1.2.1.25.1.6.0' => '' };

        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 (Prior) 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 (Hermit) 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 http://www.snmp-informant.com/

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

Log In?
Username:
Password:

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
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2014-08-23 05:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (172 votes), past polls