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

I have recently installed Fedora 8 on a new server for doing some scripting, and moved a few scripts to it from another server (Fedora 4). Its a cgi-bin script that queries standard information off of devices. On the new server, when I run the script, I get an error, that I don't know how to fix, perhaps someone here can shed some light into it. I know the code has worked flawlessly on several OS Platforms... so I think its something moreso to do with an OS issue, but its worth a shot.
sub Read_DOCSIS_SNMP { my %DOCSISResults = (); my ($OIDName, $MACTableResult) = ""; my ($Session, $Error ) = Net::SNMP->session( -hostname => $IPAddress, -community => $ReadCommunityString, -retries => 3, -timeout => 5, -mtu => 1544, -nonblocking => 0x1 ); if (!defined($Session) ) { &ErrorOut("Error starting SNMP Session [DEBUG 1]: $Err +or"); } $Session->get_request( -callback => [\&DOCSIS_Call +back, \%DOCSISResults], -varbindlist => [$SystemDescri +ption, $SystemUptime, $MACAddress, $BootFile, $NumberOfInter +faces, $DSFrequency, $DSPowerLevel, $DSModulationType, $DSSNR, $USFre +quency, $USPowerLevel, $USChannelWidth, $USChannelID, $UnerroredCode +words, $CorrectedCodewords, $UncorrectableCodewords, $Microreflecti +ons, $InterfaceResets, $LostSyncs, $InvalidMaps, +$InvalidUCDs, $T1Timeouts, $T2Timeouts, $T3Timeouts, $T4Timeouts, $ +InvalidRangeRsp, $InvalidRegRsp, $SerialNumber, $SystemName, $ +SystemLocation] ); foreach $OIDName (keys %MACTableOIDs) { $MACTableResult = $Session->get_table( -callback => [ \&MACTable_Callback, $MACTableOIDs{$OIDName +}, $OIDName, \%MACTableResults, ], -baseoid => $MACTableOIDs{$OIDName +}, ); } if (!$MACTableResult) { &ErrorOut("SNMP Error while performing MAC tab +le Callback routine: $Error"); } snmp_dispatcher(); $Session->close(); if (!defined($ModemResults{DSPowerLevel})) { &ErrorOut("Unable to communicate with device, or it's +not a cable modem."); } }
ERROR:: ERROR! Error starting SNMP Session DEBUG 1: Failed to open UDP/IPv4 socket: Permission denied

Replies are listed 'Best First'.
Re: Perl NET::SNMP
by pc88mxer (Vicar) on Apr 29, 2008 at 18:21 UTC
    This is an odd problem. The specific code which seems to be failing (returning undef) is this routine in Net::SNMP::Transport::UDP:
    sub _socket_create { IO::Socket->new->socket(PF_INET, SOCK_DGRAM, (getprotobyname('udp')) +[2]); }
    and _socket_create is called by this fragment in Net::SNMP::Transport:
    if (!defined($this->{_socket} = $this->_socket_create)) { $this->_perror('Failed to open %s socket', $this->type); return wantarray ? (undef, $this->{_error}) : undef }
    If you can verify that this is indeed the case it would really help. I can't think right now of a reason why it should fail unless the user the CGI script is running under is unable to create sockets. Is that a possibility?
      Hi,

      I don't use the Fedora for a while, but my suspect is the SELinux. Check the log file of the SELinux.

        /sigh, sometimes you forget the simplist things.. I was positive I had corrected this and never even bothered to look back. Thanks for the help
Re: Perl NET::SNMP
by mr_mischief (Monsignor) on Apr 29, 2008 at 22:32 UTC
    What version of Net::SNMP are you using? RPMFind has it as an RPM package at version 5.4.1-6fc8 as the latest version, but there's an earlier version listed. The newest I found on CPAN is 5.2.0, though.

    I know this is an odd question, but do you have IPv4 enabled on your new server, or only IPv6? Another odd one for you -- can your web server open a UDP socket under either? Is there an application-level firewall involved?

    When I rigged up the missing parts of your program quickly, I got the message about not being able to communicate with the device. That's expected, since I pointed it to a device with no SNMP server running. I didn't get any errors about permission denied or any other session-related errors. I'm running 5.10.0 with Net::SNMP 5.2.0 on Mandriva 2008.