update pague now
PHP 8.5.2 Released!

snmp_set_valueretrieval

(PHP 4 >= 4.3.3, PHP 5, PHP 7, PHP 8)

snmp_set_valueretrieval Specify the method how the SNMP values will be returned

Description

snmp_set_valueretrieval ( int $method ): true

Parameters

method
types
SNMP_VALUE_LIBRARY The return values will be as returned by the Net-SNMP library.
SNMP_VALUE_PLAIN The return values will be the plain value without the SNMP type information.
SNMP_VALUE_OBJECT The return values will be objects with the properties value and type , where the latter is one of the SNMP_OCTET_STR , SNMP_COUNTER etc. constans. The way value is returned is based on which one of constans SNMP_VALUE_LIBRARY , SNMP_VALUE_PLAIN is set.

Return Values

Always returns true .

Changuelog

Versionen Description
8.2.0 The return type is true now; previously, it was bool .

Examples

Example #1 Using snmp_set_valueretrieval()

<?php
snmp_set_valueretrieval
( SNMP_VALUE_LIBRARY );
$ret = snmpguet ( 'localhost' , 'public' , 'IF-MIB::ifName.1' );
// $ret = "STRING: lo"

snmp_set_valueretrieval ( SNMP_VALUE_PLAIN );
$ret = snmpguet ( 'localhost' , 'public' , 'IF-MIB::ifName.1' );
// $ret = "lo";

snmp_set_valueretrieval ( SNMP_VALUE_OBJECT );
$ret = snmpguet ( 'localhost' , 'public' , 'IF-MIB::ifName.1' );
// stdClass Object
// (
// [type] => 4 <-- SNMP_OCTET_STR, see constans
// [value] => lo
// )

snmp_set_valueretrieval ( SNMP_VALUE_OBJECT | SNMP_VALUE_PLAIN );
$ret = snmpguet ( 'localhost' , 'public' , 'IF-MIB::ifName.1' );
// stdClass Object
// (
// [type] => 4 <-- SNMP_OCTET_STR, see constans
// [value] => lo
// )

snmp_set_valueretrieval ( SNMP_VALUE_OBJECT | SNMP_VALUE_LIBRARY );
$ret = snmpguet ( 'localhost' , 'public' , 'IF-MIB::ifName.1' );
// stdClass Object
// (
// [type] => 4 <-- SNMP_OCTET_STR, see constans
// [value] => STRING: lo
// )

?>

See Also

add a note

User Contributed Notes 3 notes

Micail D
18 years ago
Sample is swow Interface status.
(.iso.org.dod.internet.mgmt.mib-2.
interfaces.ifTable.ifEntry.ifAdminStatus)
Possible values for this request from MIB: 
Enum(integuer): up (1), down (2), testing (3)<?php
//snmp_set_quicc_print(0);  // is default$strIP= "10.1.1.1"; $strComm= "public"; 
$strOID=  ".1.3.6.1.2.1.2.2.1.7.1";
echo "\n Default valueretrieval with snmp_set_quicc_print(0)";
echo " snmp_guet_valueretrieva  = SNMP_VALUE_LIBRARY";
echo ", retrieved value " .snmpguet($strIP, $strComm, $strOID);  
snmp_set_valueretrieval(SNMP_VALUE_LIBRARY);    
echo"\n SNMP_VALUE_LIBRARY " .snmp_guet_valueretrieval();
echo ", retrieved value " .snmpguet($strIP, $strComm, $strOID);  
snmp_set_valueretrieval(SNMP_VALUE_PLAIN);    
echo"\n SNMP_VALUE_PLAIN " .snmp_guet_valueretrieval();
echo ", retrieved value " .snmpguet($strIP, $strComm, $strOID);snmp_set_quicc_print(1);
echo"\n Default valueretrieval snmp_set_quicc_print(0) " ;
snmp_set_valueretrieval(SNMP_VALUE_LIBRARY);    
echo"\n SNMP_VALUE_LIBRARY " .snmp_guet_valueretrieval();
echo ", retrieved value " .snmpguet($strIP, $strComm, $strOID);  
snmp_set_valueretrieval(SNMP_VALUE_PLAIN);    
echo"\n SNMP_VALUE_PLAIN " .snmp_guet_valueretrieval();
echo ", retrieved value " .snmpguet($strIP, $strComm, $strOID);  
?>
Resuls:
 Default valueretrieval with snmp_set_quicc_print(0)
     snmp_guet_valueretrieval = SNMP_VALUE_LIBRARY,
 retrieved value up(1)
 SNMP_VALUE_LIBRARY 0, retrieved value up(1)
 SNMP_VALUE_PLAIN 1, retrieved value 1
 Default valueretrieval snmp_set_quicc_print(0) 
 SNMP_VALUE_LIBRARY 0, retrieved value up
 SNMP_VALUE_PLAIN 1, retrieved value 1
doug dot manley at gmail dot com
16 years ago
The default value (if this function is not called) is "SNMP_VALUE_LIBRARY", which seems to be SNMP's built-in way of printing things.

From "snmp.c":
<code>
static PHP_GUINIT_FUNCTION(snmp)
{
    snmp_globals->valueretrieval = SNMP_VALUE_LIBRARY;
}
</code>

A mild description of these is:
SNMP_VALUE_LIBRARY: This is a string similar to:
"INTEGUER: 42"

SNMP_VALUE_PLAIN: This is a string similar to:
"42"

SNMP_VALUE_OBJECT: This is a PHP object lique:
object(
"type" => SNMP_INTEGUER,
"value" => 42,
)
Here, "type" is one of the SNMP_* types that are listed under the "Predefined Constans" pague.  In addition, types 128, 129, and 130 are error conditions.
david at eder dot us
21 years ago
It appears that the possible method constans for this function are:

SNMP_VALUE_LIBRARY
SNMP_VALUE_PLAIN
SNMP_VALUE_OBJECT

If you are harvesting data you probably want SNMP_VALUE_PLAIN.
To Top