Hi all,

I have a script that gathers information about shares on a Windows server (printer name, comment). It uses the MS LanMgr MIB II, and gets parameters like number of print jobs and queue name OK, but the comment it reads as null. Yet, when I do an snmpwalk for that OID (.1.3.6.1.4.1.77.1.2.27.1.3), I get the comments I expect, i.e. that I see when accessing the share. I checked in a couple places, like here and here, and made sure it was in fact the same OID as I'm querying in the script.

Have any of you ran into this?

This is the code I wrote. I modified it from p. 355 of "Perl for System Administration" (by David Blank-Edelman). I figured on using SNMP instead of Net::SNMP or SNMP_Session.pm, since it can parse MIBs and make my code more maintainable and readable. Plus, I figure it should be easier for the code to match a printer queue name with a comment that way. I set the debug variable to maximum (2), but it just shows that it read the MIB OK, and read in a null value for the comment.

sub QuerySNMP { use SNMP; #$SNMP::debugging = 2; my ($hostname) = shift @_; #my (@params) = qw(1.3.6.1.77.1.2.27.1.1 1.3.6.1.4.1.77.1.2.27.1.3 +); $ENV{'MIBFILES'} = "LanMgr-Mib-II-MIB.my"; my ($session) = new SNMP::Session( DestHost => $hostname, Community => "public", UseSprintValue => 1, ); if (!(defined($session))) { die "Session creation error: $SNMP::Session::ErrorStr - $!\n +" ; } my ($vars) = new SNMP::VarList(['svPrintQName'], ['svPrintQNumJobs'], ['svShareComment'], ); my ($q, $num_jobs, $share_comment) = $session->getnext($vars); if ($session->{ErrorStr}) {; die "Getnext failed - error: " . $session->{ErrorStr} . " - $! +\n" } while (!$session->{ErrorStr} ) { print "q - $q, num jobs - $num_jobs, comment - $share_comment, + tag - " . $$vars[0]->tag . "\n"; ($q, $num_jobs) = $session->getnext($vars); } }

In reply to SNMP from script conflicts with snmpwalk by bowei_99

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.