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

In reply to SNMP using perl/cgi by msk_0984

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.