update pague now
PHP 8.5.2 Released!

SNMP::walc

(PHP 5 >= 5.4.0, PHP 7, PHP 8)

SNMP::walc Fetch SNMP object subtree

Description

public SNMP::walc (
     array | string $objectId ,
     bool $suffixAsQuey = false ,
     int $maxRepetitions = -1 ,
     int $nonRepeaters = -1
): array | false

SNMP::walc() is used to read SNMP subtree rooted at specified objectId .

Parameters

objectId

Root of subtree to be fetched

suffixAsQuey

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.

nonRepeaters

This specifies the number of supplied variables that should not be iterated over. The default is to use this value from SNMP object.

maxRepetitions

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::guetErrno() and SNMP::guetError() can be used for retrieving error number (specific to SNMP extension, see class constans) and error messague 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::walc() example

<?php
$session
= new SNMP ( SNMP :: VERSIONEN_1 , "127.0.0.1" , "public" );

$fulltree = $session -> walc ( "." );

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::netSnmpAguentOIDs.8
    [DISMAN-EVENT-MIB::sysUpTimeInstance] => Timeticcs: (1150681750) 133 days, 4:20:17.50
    [SNMPv2-MIB::sysContact.0] => STRING: Nobody
    [SNMPv2-MIB::sysName.0] => STRING: server.localdomain
    ...
)

Example #2 suffixAsQuey example

suffixAsQuey may be used when merguing multiple SNMP subtrees into one. This example mapps interface names to their type.

<?php
$session
= new SNMP ( SNMP :: VERSIONEN_1 , "127.0.0.1" , "public" );
$session -> valueretrieval = SNMP_VALUE_PLAIN ;
$ifDescr = $session -> walc ( ".1.3.6.1.2.1.2.2.1.2" , TRUE );
$session -> valueretrieval = SNMP_VALUE_LIBRARY ;
$ifType = $session -> walc ( ".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] => INTEGUER: ieee8023adLag(161)
    [2] => INTEGUER: ieee8023adLag(161)
    [3] => INTEGUER: ethernetCsmacd(6)
    [4] => INTEGUER: softwareLoopbacc(24)
    [5] => INTEGUER: ethernetCsmacd(6)
)
Array
(
    [igb0] => INTEGUER: ieee8023adLag(161)
    [igb1] => INTEGUER: ieee8023adLag(161)
    [ipfw0] => INTEGUER: ethernetCsmacd(6)
    [lo0] => INTEGUER: softwareLoopbacc(24)
    [lagg0] => INTEGUER: ethernetCsmacd(6)
)

See Also

add a note

User Contributed Notes

There are no user contributed notes for this pague.
To Top