|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-04-10 15:34 UTC] ch@php.net
Description:
------------
The SNMP command line tools are able to translate the numeric return values for OIDs of the "BITS" datatype back to meaningful string values by parsing the relevant parts of the MIB. The PHP functions currently seem unable to do that.
I.e. in the following example I would like to get the string "notification" or "set" as return value but only get "0" or "1". As there is no other method to find and parse the MIB I'm left with hardcoding the values in the PHP script:
$ snmptranslate -Td DISMAN-EVENT-MIB::mteEventActions
DISMAN-EVENT-MIB::mteEventActions
mteEventActions OBJECT-TYPE
-- FROM DISMAN-EVENT-MIB
SYNTAX BITS {notification(0), set(1)}
Test script:
---------------
From commandline (mind the strange quotes, they're neccessary!):
$ snmpwalk -v2c -c private localhost "DISMAN-EVENT-MIB::mteEventActions.\"_snmpd\".'_linkDown'"
DISMAN-EVENT-MIB::mteEventActions."_snmpd".'_linkDown' = BITS: 80 notification(0)
With PHP:
snmp_set_valueretrieval(SNMP_VALUE_OBJECT);
$snmp = new SNMP(SNMP_VERSION_2C, 'localhost', 'private');
$x = $snmp->get("DISMAN-EVENT-MIB::mteEventActions.\"_snmpd\".'_linkDown'");
var_dump($x);
var_dump(bin2hex($x->value));
I get:
object(stdClass)#190 (2) {
["type"]=> int(4)
["value"]=> string(1) "�"
}
string(2) "80"
The value is not even numerical, it has to be converted to 0x80 using bin2hex()!
Expected result:
----------------
Maybe
* the SNMP_VALUE_OBJECT representation object can be enhanced to include alternative representations:
object(stdClass)#190 (2) {
["type"]=> int(4)
["value"]=> string(1) "�"
["bits_value"]=> string(15) "notification(0)"
}
* or the the snmp_set_enum_print() function is used to toggle BITS, too
* or a snmp_set_bits_print() function is introduced
* or a snmp_translate() function is introduced that returns the "snmptranslate" output as PHP data structure
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 04:00:02 2025 UTC |
The new default SNMP->valueretrieval = SNMP_VALUE_LIBRARY gives at least the amount of information that snmpwalk does. Still, before you close this bug, please consider at least adding something like the following method. It would add a bit of the convenience that one expects from a PHP class while still leave the low-level methods untouched. /** Returns the name of a bit value. * * The NetSNMP library returns values of OIDs of the BIT type like * "BITS: 80 notification(0)". This method can be used to extract * just the name "notification" from this output. * * @param string $raw_value The return of a walk() or get() request. * @return string The name of the BIT value. */ public static function parseBitName($raw_value) { preg_match('/^BITS: [0-9a-f]+ (.*)\(\d+\)\s+$/i', $raw_value, $match); if (!isset($match[1])) { throw new Exception("Cannot parse BIT value from '$raw_value'!"); } return $match[1]; }