|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #54502 Add support for the "BITS" datatype
Submitted: 2011-04-10 15:34 UTC Modified: 2011-08-05 08:48 UTC
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: Assigned: lytboris (profile)
Status: Closed Package: SNMP related
PHP Version: trunk-SVN-2011-04-10 (SVN) OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
5 - 4 = ?
Subscribe to this entry?

 [2011-04-10 15:34 UTC]
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
mteEventActions OBJECT-TYPE
  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 = new SNMP(SNMP_VERSION_2C, 'localhost', 'private');
        $x = $snmp->get("DISMAN-EVENT-MIB::mteEventActions.\"_snmpd\".'_linkDown'");
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:

* 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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-07-17 09:18 UTC]
-Assigned To: +Assigned To: lytboris
 [2011-07-17 09:18 UTC]
There is support for BITS datatype actually when SNMP_VALUE_LIBRARY is enabled for value processing. When you enable other SNMP_VALUE_* modes no value processing is performed and output from remote SNMP agent is passed through SNMP library.
 [2011-07-17 13:18 UTC]
Automatic comment from SVN on behalf of lytboris
Log: fix FR #54502: allow user to change OID value output mode when SNMP_VALUE_OBJECT is used.
 [2011-07-17 13:25 UTC]
-Status: Assigned +Status: Feedback
 [2011-07-17 13:25 UTC]
Please try using this snapshot:

For Windows:

Now you can combine SNMP_VALUE_OBJECT with one of SNMP_VALUE_PLAIN or SNMP_VALUE_LIBRARY to alter 'value' output mode.
As for
>The value is not even numerical, it has to be converted to 0x80 using bin2hex()!
This is normal, because this is exactly what php-snmp receives from remote SNMP agent.
 [2011-07-17 13:26 UTC]
Automatic comment from SVN on behalf of lytboris
Log: fix FR #54502: allow user to change OID value output mode when SNMP_VALUE_OBJECT is used.
 [2011-07-29 00:27 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];
 [2011-08-05 08:48 UTC]
-Status: Feedback +Status: Closed
 [2011-08-05 08:48 UTC]
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at

 For Windows:
Thank you for the report, and for helping us make PHP better.

It seems that parseBitName should not go into php-snmp library, at least it works only for "BITS: " string. Not sure that general parsing function will be sufficient for all users though, not taking into account the fact that this function will be complicated.

As an example of such complicated function you may take a look on format_snmp_string() function in Cacti's repo lib/snmp.php [ ].
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jul 23 20:01:31 2024 UTC