How about a small script that doesn't include web output, logging etc?

Alex


Mark Gonzalez wrote:
#!/usr/local/bin/perl
# DOCSIS-SNR-snmp Modified for www
# 08/1/2005

$ENV{'MIBDIRS'} = '/usr/local/share/snmp/mibs';
$ENV{'MIBFILES'} =
'/usr/local/share/snmp/mibs/CISCO-DOCS-EXT-MIB.my:/usr/local/share/snmp/mibs
/cisco.mib';


local (*in) = @_ if @_;
local ($i, $loc, $key, $val);

# Read in text
if ($ENV{'REQUEST_METHOD'} eq "GET") {
  $in = $ENV{'QUERY_STRING'};
} elsif ($ENV{'REQUEST_METHOD'} eq "POST") {
  read(STDIN,$in,$ENV{'CONTENT_LENGTH'});
}

@in = split(/&/,$in);

foreach $i (0 .. $#in) {
  # Convert plus's to spaces
  $in[$i] =~ s/\+/ /g;

  # Split into key and value.
  ($key, $val) = split(/=/,$in[$i],2); # splits on the first =.

  # Convert %XX from hex numbers to alphanumeric
  $key =~ s/%(..)/pack("c",hex($1))/ge;
  $val =~ s/%(..)/pack("c",hex($1))/ge;

  # Associate key and value
  $in{$key} .= "\0" if (defined($in{$key})); # \0 is the multiple separator
  $in{$key} .= $val;

}
$DEVICENAME = $in{"ubr"};
$EMAC = $in{"ethaddr"};
$query = $in{"query"};
$MAC = $in{"cmaddr"};
$EPORT = "%Ethernet%";
$CMMAC = $in{"1cmaddr"};
$CMMAC2 = $in{"2cmaddr"};
$IP = $in{"ubr"};
$SD = $in{"sidn"};
$CMIP = $in{"cmips"};
$IIP = $in{"iips"};
$RIN = $in{"cin"};
$IP = "";
$UBR=$IP;
#open(STDERR, "/dev/null");

$SNMP::Util::Max_log_level = 'none';
use SNMP::Util_env;

# Initialize mib
&SNMP::initMib();
use SNMP::Util;

$community = "cablemon";
$rsh = "/usr/bin/rsh";
$VERSION = "Version 12.0(7)XR2";
$VERSION1 = "Version 12.1(2)T";
############################################################################
$VERSION = "Version 12.0(7)XR2";
 $VERSION1 = "Version 12.1(2)T";
 $VERSION2 = "Version 12.1(3)T";
 $SNR = "transmission.127.1.1.4.1.5";
 $INT = "interfaces.ifTable.ifEntry.ifDescr";
 $INTSTATUS = "interfaces.ifTable.ifEntry.ifOperStatus";
 $CMPERCENT = "enterprises.9.9.116.1.3.2.1.3";
$totalpercent = 0;
$snmp = new SNMP::Util(-device => $IP,
                           -community => $community,
                           -timeout => 5,
                           -retry => 0,
                           -poll => 'on',
                           -poll_timeout => 5,
                           -verbose => 'on',
                           -errmode => 'return',
                           -delimiter => ' ',
);
@percent_array = `/usr/local/bin/snmpbulkwalk -Oq -v 2c -c $community $IP
$CMPERCENT`;
        foreach $record (@percent_array) {
                @splitted = split(/ /,$record);
                $i= $i + $splitted[1];
                }
        if ($i ) { $avgonline = sprintf("%.2f",
(($i/100)/($#percent_array+1))); } else {
                $avgonline = "failed"; }


print "Content-type: text/html\n\n
        <html><body>
        <center><h3>Signal-to-Noise Ratio for ";
$SYSNAME = $snmp->get('v', "system.sysName.0");
$OSINFO = $snmp->get('v', "system.sysDescr.0");
@VERINFO = split(/\,/, $OSINFO);
print "$SYSNAME</h3>$VERINFO[0] -$VERINFO[1]</center><br>
        Average Online Percentage of All Modems - $avgonline
        <br><br><hr>
        <center><font color=blue>**SNR should be greater than 25
dB</font></center>";
[EMAIL PROTECTED] = `rsh -l apache $IP show cable modem summary`;

@results = $snmp->walk('nv',$SNR);
#`/usr/local/bin/snmpwalk -c $community $IP $SNR`;
if ((substr($VERINFO[1],1,18) ne $VERSION) or (substr($VERINFO[1],1,18) ne
$VERSION1) or (substr($VERINFO[1],1,18) ne $VERSION2))
  { @SHCONOUTPUT = `$rsh -l apache $IP show controller "| include SNR"`;
$i=0; }

#open(LOG, ">/tmp/outputc");
#print(LOG @cablesummary);
print "<table border=6 align=center>";
print " <td>
           <tr>

                  <td align=center width=170><b>Cable Upstream
Interface</FONT></b></td>
                  <td align=center width=170><b>SNR</FONT></b></td>
        </tr>";

$z=0;
$stop=scalar(@results);
while ($z < $stop)
{ @SNRVAR=split(/\./, $results[$z]);
    $INDEX = $SNRVAR[1];
    $PORT = $snmp->get('v', $INT, $INDEX);
    $PORTSTATUS = $snmp->get('v', $INTSTATUS, $INDEX);

        ## if Version is 12.0(7)XR2 Use the SNMP Value
      if (substr($VERINFO[1],1,18) eq $VERSION)
      {
         $VALUE=$results[$z+1]/10000;
       } elsif ((substr($VERINFO[1],1,18) eq $VERSION1) ||
(substr($VERINFO[1],1,18) eq $VERSION2)) #### if Version 12.1(2or3)T
      {
              $VALUE=$results[$z+1]/10;
       } else  ####### Use rsh to retrieve the values
        { $BLADE = substr($PORT,0,8);
          $UPSPORT = substr($PORT,-1,1);
@test = split(' ',$SHCONOUTPUT[$i]); $VALUE = $test[1];
          $i=$i+1;
         }
if ($VALUE < 25) { $FNTCLR = "red"; } else { $FNTCLR = "black"; } print "<tr>
                <td align=center width=100>$PORT</td>";
if ($PORTSTATUS == 1) { print "<td align=center width=150><font
color=$FNTCLR>$VALUE dB</font></td></tr>";
                 } else
                  { print "<td align=center width=150><font
color=silver>Admin Down</font></td></tr>";
                   }
$z=$z+2; }
print "</table>
                <hr></body></html>";
}

-----Original Message-----
From: Alex Burger [mailto:[EMAIL PROTECTED] Sent: Wednesday, August 17, 2005 5:09 PM
To: Mark Gonzalez
Cc: net-snmp-users@lists.sourceforge.net
Subject: Re: can anyone answer this?

Mark Gonzalez wrote:

error: set: unknown object ID at /usr/local/lib/perl5/site_perl/5.8.7/sun4-solaris/SNMP.pm line 600.

error:snmp_translate_obj:Unknown OID system.sysDescr


Can you provide some Perl code that produces that error?

Alex



-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Net-snmp-users mailing list
Net-snmp-users@lists.sourceforge.net
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users

Reply via email to