Welcome to PCCS-Linux.COM Hello, and welcome to the PCCS-Linux Home Page.
Your last visit was !!!
Your Browser is running on Other
 
Create SNMP Functions

Writing PHP functions using the php snmp functions

<?php
// PHP SNMP funtions 

function systemSection($ipaddr) {
 global $community;

  // Get the most useful info 
  $sysdescr = @snmpget("$ipaddr","$community","system.sysDescr.0");
  $sysobjectid = @snmpget("$ipaddr","$community","system.sysObjectID.0");
  $sysuptime = @snmpget("$ipaddr","$community","system.sysUptime.0");
  $syscontact = @snmpget("$ipaddr","$community","system.sysContact.0");
  $sysname = @snmpget("$ipaddr","$community","system.sysName.0");
  $syslocation = @snmpget("$ipaddr","$community","system.sysLocation.0");
 
     print "<TABLE BORDER=0 CELLPADDING=2 CELLSPACING=0>";
     print "<TR><TD>sysDescr</TD><TD
COLSPAN=2>" . $sysdescr . "</TD></TR>";
     print "<TR><TD>sysObjectID</TD><TD
COLSPAN=2>" . $sysobjectid . "</TD></TR>"; 
     print "<TR><TD>sysUptime</TD><TD
COLSPAN=2>" . $sysuptime . "</TD></TR>"; 
     print "<TR><TD>sysContact</TD><TD
COLSPAN=2>" . $syscontact . "</TD></TR>"; 
     print "<TR><TD>sysName</TD><TD
COLSPAN=2>" . $sysname . "</TD></TR>"; 
     print "<TR><TD>sysLocation</TD><TD
COLSPAN=2>" . $syslocation .  "</TD></TR>"; 
     print "</TABLE>";
} // End of systemSection


function interfaceIfTable($ipaddr) {
 global $community;

   /* Get the interface index. create an array to get data */  
   /* interfaces.ifTable.ifEntry.ifIndex translated using snmptranslate */
   
  $interfaces = snmpwalk("$ipaddr","$community",".");

    print "<H3>Interface info for " .  $sysname . "</H3>";
    print "<P>";
    print "<TABLE BORDER=0 CELLPADDING=2 CELLSPACING=0>";
    print "<TR><TH>Interface</TH><TH>Interface
TYPE</TH>

<TH>InOctets</TH><TH>OutOctets</TH></TR>";

     for($i=0; $i < count($interfaces); $i++) {
       $inface =
snmpget("$ipaddr","$community","..$interfaces[$i]");
       $infacetype =
snmpget("$ipaddr","$community","..$interfaces[$i]");
       $inoctets =
snmpget("$ipaddr","$community",".0.$interfaces[$i]");
       $outoctets =
snmpget("$ipaddr","$community",".6.$interfaces[$i]");
       /* Clean up Interface strip Hex: */
       
       $inface = ereg_replace("Hex:","",$inface);
          print "<tr><td>" . $inface
. "</td><td>" . $infacetype . "</td>";
          print
"<td>" .$inoctets. "</td><td>" . $outoctets. "</td></tr>\n";
 
       }
       
    print "</TABLE>";  
}  // End of interfaceIfTable


function icmpSection($ipaddr) {
  global $community;

  $icmpInMsgs = snmpget("$ipaddr","$community","icmp.icmpInMsgs.0");
  $icmpOutMsgs = snmpget("$ipaddr","$community","icmp.icmpOutMsgs.0");
  $icmpInErrors = snmpget("$ipaddr","$community","icmp.icmpInErrors.0");
  $icmpOutErrors = snmpget("$ipaddr","$community","icmp.icmpOutErrors.0");
  $icmpInEchos = snmpget("$ipaddr","$community","icmp.icmpInEchos.0");
  $icmpOutEchos = snmpget("$ipaddr","$community","icmp.icmpOutEchos.0");

    print "<H3>ICMP info for " .  $sysname . "</H3>";
    print "<P>";
    print "<TABLE BORDER=0 CELLPADDING=2 CELLSPACING=0>";
    print
"<TR><TH>icmpInMsgs</TH><TH>icmpOutMsgs</TH></TR>";
    print "<tr><td>" . $icmpInMsgs
. "</td><td>" . $icmpOutMsgs . "</td></tr>\n";
    print
"<TR>icmpInErrors</TR><TR>icmpOutErrors</TR></TR>";
    print
"<tr><td>" .$icmpInErrors. "</td><td>" . $outoctets. "</td></tr>\n";
    print
"<TR>icmpInEchos</TR><TR>icmpOutEchos</TR></TR>";
    print
"<tr><td>" .$icmpInEchos. "</td><td>" . $icmpOutEchos. "</td></tr>\n";
    print "</TABLE>";

} // End imcpSection



?>


>> Comments/FeedBack


Page hits 70 last request on :04:36



This web site is prepared and maintained by Chauncey Thorn.
The information contained in this site was valid at the time of posting.
Chauncey Thorn, assumes no liability for damages incurred directly or indirectly as a result of errors, omissions or discrepancies.

Remember most of the content here are my notes...

All logos and trademarks in this site are property of their respective owner. All the rest © by PCCS-Linux.COM

PCCS-Linux.COM ::ource Advocate Articles catalogue
2000 2002