Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : SNMP Functions : snmpwalk

snmpwalk

Fetch all the SNMP objects from an agent (PHP 4, PHP 5)
array snmpwalk ( string hostname, string community, string object_id [, int timeout [, int retries]] )

snmpwalk() function is used to read all the values from an SNMP agent specified by the hostname.

Parameters

hostname

The SNMP agent.

community

The read community.

object_id

If NULL, object_id is taken as the root of the SNMP objects tree and all objects under that tree are returned as an array.

If object_id is specified, all the SNMP objects below that object_id are returned.

timeout
retries

Return Values

Returns an array of SNMP object values starting from the object_id as root or FALSE on error.

Examples

Example 2267. snmpwalk() Example

<?php
$a
= snmpwalk("127.0.0.1", "public", "");

foreach (
$a as $val) {
   echo
"$val\n";
}

?>


Above function call would return all the SNMP objects from the SNMP agent running on localhost. One can step through the values with a loop

See Also
snmpwalkoid()

Code Examples / Notes » snmpwalk

steve

Timeout is in MICRO seconds.
1,000,000 &micros = 1 s


layer2

Something to care about in dealing with snmpwalk:
While walking the MIB, snmpwalk puts info that gets into an array, and that is correct.
The trouble happened when snmpwalk needs to collect information from instances that contains subinstances (i.e. walking .1.2.3.4.5 and having instances like 1.1, 1.2, 1.3): in this case it gets info and passes into an array, but when walking the array, each value is preceeded by 'Counter32: '.
I've tested this in many ways and it always happened the same way.


lars troen

Note that there's different behaviuor in php snmpwalk and ucd snmpwalk. If you try to walk an oid that has one value not under a subkey of the walked oid, ucd snmpwalk will return the value while php's snmpwalk will not.

anders

It would be nice to be able to specify what snmp version to use ( 1,2c,3 )
For now, I'ts hardcoded in ext/snmp/snmp.c
change session.version from 1 to 2c or 3 if you need for now..
i.e
session.version = SNMP_VERSION_1;
to:
session.version = SNMP_VERSION_2c;


bobby dot clark

I had to use an object_id like these.
'SNMPv2-MIB::system.sysDescr.0'
'IF-MIB::interfaces.ifTable.ifEntry.ifAdminStatus'
<?php
$host = '192.168.1.1';
$community = 'public';
$object_id = 'IF-MIB::interfaces.ifTables.ifEntry.ifAdminStatus';
$sysdesc = snmpwalk($host, $community', $object_id);
print_r($sysdesc);
?>


http://mike.eire.ca

I found on Windows (PHP 5) an empty string did not return anything, it just timed out.  I had to use null instead:
<?php
$a = snmpwalk("127.0.0.1", "public", null);
?>


billf

for the poster wondering what the
timeout field was measured in:
from the ucd-snmp header file snmp_api.h:
   long    timeout;
   /* Number of uS until first timeout
   then exponential backoff */


john

Ah. That's why all of our SNMP stuff was timing out anytime there was any load on the system. Sigh. A waste of two weeks trying to debug snmp....
Even the snmpcmd manpage doesn't give a
unit for timeout.


jmartinson at_nospam info234.com

A quick router device view:
<?
include "header.html";
$host = "auscr1";
$community = "tellme";
                   
$sysDescr = snmpget("$host","$community","system.sysDescr.0");
$ifDescr = snmpwalk("$host","$community","interfaces.ifTable.ifEntry.ifDescr");
$ifIndex = snmpwalk("$host","$community","interfaces.ifTable.ifEntry.ifIndex");
$ifAdminStatus = snmpwalk("$host","$community","interfaces.ifTable.ifEntry.ifAdminStatus");
$ifOperStatus = snmpwalk("$host","$community","interfaces.ifTable.ifEntry.ifOperStatus");
$ifLastChange = snmpwalk("$host","$community","interfaces.ifTable.ifEntry.ifLastChange");
                                         
print "<table border=1 bgcolor=#ffffff><tr><td>$host</td></tr></table>
";
print "<table border=1 bgcolor=#ffffff><tr><td>$sysDescr</td></tr></table>
";
print "<table border=1 bgcolor=#ffffff>";
print "<tr>
       <td>ifIndex</td>
       <td>ifDescr</td>
       <td>ifAdminStatus</td>
       <td>ifOperStatus</td>
       <td>ifLastChange</td>
       </tr>";
           
for ($i=0; $i<count($ifIndex); $i++) {
       print "<tr>";
       print "<td>$ifIndex[$i]</td>";
       print "<td>$ifDescr[$i]</td>";
       print "<td>$ifAdminStatus[$i]</td>";
       print "<td>$ifOperStatus[$i]</td>";
       print "<td>$ifLastChange[$i]</td>";
       print "</tr>";
}            
print "</table>";
?>


Change Language


Follow Navioo On Twitter
snmp_get_quick_print
snmp_get_valueretrieval
snmp_read_mib
snmp_set_enum_print
snmp_set_oid_numeric_print
snmp_set_oid_output_format
snmp_set_quick_print
snmp_set_valueretrieval
snmpget
snmpgetnext
snmprealwalk
snmpset
snmpwalk
snmpwalkoid
eXTReMe Tracker