http://www.perlmonks.org?node_id=567172

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

Hi monks

i am writing a perl /cgi program to implement the concept of SNMP Get request and the cgi page which takes IP address, Community, OID values ...once user clicks submit button then u have to show the result of that particular OID but when i am trying the create a session object i am getting an error snmp session cannot be created. i am new to SNMP and i think i am missing out some thing very fundamental i have tried it out in different ways and in a normal snmp program i could create the session easily and get the OIDs information so i need ur help. my code is

#!/usr/bin/perl ## CGI /Perl Prog to get the OID and ## using get _req getting the reqested data use strict; use Net::SNMP; use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser warningsToBrowser); ## Used to see i +f any errors in fix it out my ($IP,$Cmty,$Oid); my $ob = new CGI; print $ob->header; print $ob->start_html(-title=>"SNMP Get_Request" ); print "<Center>"; print $ob->h2("<i><u>SNMP Get Requested Information</u></i>"); print $ob->hr; if ( $ob->param() ) { $IP = $ob->param('ip'); chomp($IP); $Cmty = $ob->param('community'); chomp($Cmty); $Oid = $ob->param('oid'); chomp($Oid); print $ob->b("INFO"); print $ob->em(" IP : $IP Community: $Cmty Oid : $Oid <br> "); my $sesobj = &createSession($ob,$IP,$Cmty); print $ob->em("Session Obj : $sesobj"); } else { print $ob->start_form(-name=>"get_req",-method=>"POST", -action=>"http://localhost/cgi-bin/cgiprog +/snmp/get_req.cgi"); print $ob->em("IP Address "); print $ob->textfield(-name=>"ip"); print $ob->br($ob->br); print $ob->em("Community "); print $ob->textfield(-name=>"community"); print $ob->br($ob->br); print $ob->em("Object ID "); print "&nbsp &nbsp"; print $ob->textfield(-name=>"oid"); print $ob->br($ob->br); print " &nbsp &nbsp &nbsp &nbsp "; print $ob->submit(-name=>"Submit", -value=>"Submit" ); print " &nbsp &nbsp &nbsp &nbsp "; print $ob->reset; } print $ob->end_form; print $ob->end_html; sub createSession() { my ($object, $ip, $cmty) = @_; ## print $object->em("IP : $ip <br> Cmty : $cmty <br> " ); ## Che +cking whether val r obtained here or not chomp($ip); chomp($cmty); my ($session, $error) = Net::SNMP->session(-hostname => $ip, -community=> $cmty, -port => '161' ); if (!defined ($session)) { print ("Err Creation Session Obj: $session->error "); exit 1; } else { print "Session created "; } }
I am getting the error

Error :Creation Of Session Object ->error

Thanks In Advance

Work Hard Party Harderrr!!
Sushil Kumar