SNMP::walk
(PHP 5 >= 5.4.0, PHP 7)
SNMP::walk — Fetch SNMP object subtree
Description
$object_id
[, bool $suffix_as_key
= FALSE
[, int $max_repetitions
[, int $non_repeaters
]]] ) : array
SNMP::walk() is used to read SNMP subtree rooted at specified object_id
.
Parameters
-
object_id
-
Root of subtree to be fetched
-
suffix_as_key
-
By default full OID notation is used for keys in output array. If set to
TRUE
subtree prefix will be removed from keys leaving only suffix of object_id. -
non_repeaters
-
This specifies the number of supplied variables that should not be iterated over. The default is to use this value from SNMP object.
-
max_repetitions
-
This specifies the maximum number of iterations over the repeating variables. The default is to use this value from SNMP object.
Return Values
Returns an associative array of the SNMP object ids and their values on success or FALSE
on error.
When a SNMP error occures SNMP::getErrno() and
SNMP::getError() can be used for retrieving error
number (specific to SNMP extension, see class constants) and error message
respectively.
Errors/Exceptions
This method does not throw any exceptions by default.
To enable throwing an SNMPException exception when some of library errors occur
the SNMP class parameter exceptions_enabled
should be set to a corresponding value. See
SNMP::$exceptions_enabled
explanation for more details.
Examples
Example #1 SNMP::walk() example
<?php
$session = new SNMP(SNMP::VERSION_1, "127.0.0.1", "public");
$fulltree = $session->walk(".");
print_r($fulltree);
$session->close();
?>
The above example will output something similar to:
Array ( [SNMPv2-MIB::sysDescr.0] => STRING: Test server [SNMPv2-MIB::sysObjectID.0] => OID: NET-SNMP-MIB::netSnmpAgentOIDs.8 [DISMAN-EVENT-MIB::sysUpTimeInstance] => Timeticks: (1150681750) 133 days, 4:20:17.50 [SNMPv2-MIB::sysContact.0] => STRING: Nobody [SNMPv2-MIB::sysName.0] => STRING: server.localdomain ... )
Example #2 suffix_as_key
example
suffix_as_key
may be used when merging multiple SNMP subtrees into one.
This example maps interface names to their type.
<?php
$session = new SNMP(SNMP::VERSION_1, "127.0.0.1", "public");
$session->valueretrieval = SNMP_VALUE_PLAIN;
$ifDescr = $session->walk(".1.3.6.1.2.1.2.2.1.2", TRUE);
$session->valueretrieval = SNMP_VALUE_LIBRARY;
$ifType = $session->walk(".1.3.6.1.2.1.2.2.1.3", TRUE);
print_r($ifDescr);
print_r($ifType);
$result = array();
foreach($ifDescr as $i => $n) {
$result[$n] = $ifType[$i];
}
print_r($result);
?>
The above example will output something similar to:
Array ( [1] => igb0 [2] => igb1 [3] => ipfw0 [4] => lo0 [5] => lagg0 ) Array ( [1] => INTEGER: ieee8023adLag(161) [2] => INTEGER: ieee8023adLag(161) [3] => INTEGER: ethernetCsmacd(6) [4] => INTEGER: softwareLoopback(24) [5] => INTEGER: ethernetCsmacd(6) ) Array ( [igb0] => INTEGER: ieee8023adLag(161) [igb1] => INTEGER: ieee8023adLag(161) [ipfw0] => INTEGER: ethernetCsmacd(6) [lo0] => INTEGER: softwareLoopback(24) [lagg0] => INTEGER: ethernetCsmacd(6) )
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-snmp.walk.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.