Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: SNMP RemotePort

by superfrink (Curate)
on Apr 10, 2008 at 19:23 UTC ( #679561=note: print w/replies, xml ) Need Help??

in reply to SNMP RemotePort

Update: I did not realize SNMP is a front end for Net::SNMP. The code below probably won't help.

Run tcpdump on the machine running the SNMP server to see if the NAT is really working and that the traffic really is getting through to port 161.

Check that snmpd is listening and allowing connections from outside localhost. (On Ubuntu/Debian check /etc/default/snmp to see what IP it is binding to. Also check snmpd.conf.)

Original post:

If you can do it just open UDP port 161 on the firewall from the IP of the server doing the monitoring.

I have not tried using a different port but Net::SNMP has functionality to specify the port number. Code I have run (based on the docs as I recall) is below.
use strict; use Data::Dumper; use Net::SNMP; my ($session, $error) = Net::SNMP->session( -hostname => shift || 'localhost', -community => shift || 'public', -port => shift || 161 ); if (!defined($session)) { printf("ERROR: %s.\n", $error); exit 1; } my $sysUpTime = ''; my $result = $session->get_request( -varbindlist => [$sysUpTime] ); if (!defined($result)) { printf("ERROR: %s.\n", $session->error); $session->close; exit 1; } printf("sysUpTime for host '%s' is %s\n", $session->hostname, $result->{$sysUpTime} ); #print Dumper($result); $session->close; exit 0;
Example output is:
$ ./ my_community_string sysUpTime for host '' is 263 days, 14:47:49.58

Replies are listed 'Best First'.
Re^2: SNMP RemotePort
by vortmax (Acolyte) on Apr 10, 2008 at 20:12 UTC works now. sorry. I tested it with tcpdump, which showed that it was in fact sending packets on port 163 but the response was timing out. So on a hunch, I moved the script over to a different server (no edits) and tried it again... and it worked. So it must be an issue with how something on my dev machine is installed/configured. thanks for your help

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://679561]
erix considers showing this to choroba , thinks better of it
[choroba]: LanX we used to mock Hare Krishna processions signing "Hare Rama" carrying the margarine conatiners
[choroba]: :-D
[LanX]: What about Czech an Chechen ambessy?
[AnomalousMonk]: LanX: Rama had (has?) a high (much higher than typical asteroid) rate of axial (again, unusual, I think) spin for its artificial gravity.
LanX pity there is no Germs embassy ...
[choroba]: LanX We merged them to save money.

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2017-11-22 17:06 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (327 votes). Check out past polls.