php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #40816 Perform multiple OID operations in transaction manner
Submitted: 2007-03-15 11:05 UTC Modified: 2011-08-31 19:58 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: ch at westend dot com Assigned: lytboris (profile)
Status: Closed Package: SNMP related
PHP Version: 5.2.1 OS: linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ch at westend dot com
New email:
PHP Version: OS:

 

 [2007-03-15 11:05 UTC] ch at westend dot com
Description:
------------
Hello

Please make a PHP pendant to /usr/bin/snmptranslate. It's handy
to check if all MIBs are installed so that the program does not
crash somewhere after already having set the first X OIDs and then
encountering one untranslatable.

bye,

-christian-

Reproduce code:
---------------
-

Expected result:
----------------
-

Actual result:
--------------
-

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-02-21 21:11 UTC] jani@php.net
-Summary: I want a "snmptranslate" function +Summary: Add "snmptranslate" function -Package: Feature/Change Request +Package: SNMP related
 [2011-08-27 08:54 UTC] lytboris@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: lytboris
 [2011-08-27 08:54 UTC] lytboris@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.4-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/

Please try another approach: all methods that performs remote agent query raise $object->errno == SNMP::ERRNO_OID_PARSING_ERROR even before query itself, indicating that some of OID (and/or type for set method) was not parsed correctly.

Since OO API allows to set multiple OID on single method call this should help.
Mind that OID parsing is made in chunks with length of $object->max_oids.
Thus if you supply array of OIDs that is bigger than $object->max_oids and bogus OID will be in the end of array, this error will be raised *after* processing (e.g. making query) the first part.
 [2011-08-30 09:21 UTC] ch at westend dot com
The idea sounds good but it does not seem to work. The "Invalid object identifier" is thrown only as PHP Warning, not set in SNMP->error:


 $ cat test.php 
 <?php
        $snmp = new SNMP(SNMP::VERSION_1, 'localhost', 'public', 0, 0);
        $oid1 = 'IF-MIB::ifAlias.1';
        $oid2 = 'DOES-NOT-EXIST-MIB::FOO';
        $oid3 = 'NOTIFICATION-LOG-MIB::nlmConfigGlobalEntryLimit.0';
        $snmp->get(array($oid1, $oid2, $oid3));
        printf("-------\n%s (%d)\n--------\n", $snmp->getError(), $snmp->errno);




 $ ../php-src-5.4/sapi/cli/php -d include_path=.:/usr/share/php  test.php 
 Warning: SNMP::get(): Invalid object identifier: DOES-NOT-EXIST-MIB::FOO in  /home/chammers/workspace/php_test/test.php on line 8
 -------
  (0)
 --------
 [2011-08-30 09:21 UTC] ch at westend dot com
-Status: Feedback +Status: Assigned
 [2011-08-30 09:42 UTC] lytboris@php.net
Please check that you have ERRNO_OID_PARSING_ERROR in snmp extension sources. This constant appeared on 27th of august.
 [2011-08-30 09:42 UTC] lytboris@php.net
-Status: Assigned +Status: Feedback
 [2011-08-30 09:52 UTC] ch at westend dot com
-Status: Feedback +Status: Assigned
 [2011-08-30 09:52 UTC] ch at westend dot com
As of SVN revision 315762 from now, the constant only appears in the tests, not in the class source. Running the tests yield to:

Fatal error: Undefined class constant 'ERRNO_OID_PARSING_ERROR' in /home/chammers/workspace/php-src-5.4/ext/snmp/tests/snmp-object-errno-errstr.php on line 45

Maybe it's not yet committet?
 [2011-08-30 14:30 UTC] lytboris@php.net
-Status: Assigned +Status: Feedback
 [2011-08-30 14:30 UTC] lytboris@php.net
Indeed. Commited sources into PHP_5_4 branch.
 [2011-08-30 15:10 UTC] ch at westend dot com
-Status: Feedback +Status: Assigned
 [2011-08-30 15:10 UTC] ch at westend dot com
Now the following works..

  @$snmp->get(array($oid1, $oid2));
  if ($snmp->getErrno() == SNMP::ERRNO_OID_PARSING_ERROR) {
    throw new Exception($snmp->getError());
  }

... but why is there only a warning? Calling get() with a OID that does not even parses should throw an Exception? Especially as when using OOP, one does not expect having to call getErrno() after every call as we did in the last millenium or even worse don't catch this error.

Can you wrapt this into a nice SnmpOidParsingException?
 [2011-08-30 15:18 UTC] lytboris@php.net
-Status: Assigned +Status: Feedback
 [2011-08-30 15:18 UTC] lytboris@php.net
I have read a bunch of threads on php-dev about extensions throwing exceptions and the last thing I remember that extension should not throw any exception except object creation if there is no way to disable them.

Anyway, if to throw exceptions, library will throw an exception for each error, not only parsing error.
 [2011-08-30 22:16 UTC] ch@php.net
Well, throwing exceptions everywhere is exactly what I'd with for but to discuss this I opened #55542. This one can be closed as we now have a way to check for the presence of a MIB (more or less convenient).
 [2011-08-31 08:28 UTC] lytboris@php.net
Automatic comment from SVN on behalf of lytboris
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=315862
Log: more tuning based on discussion in FR #40816:
 * parse all OIDs earlier, detect all wrong OIDs before any query
   is made (GET-operations)
 * introduce ERRNO_MULTIPLE_SET_QUERIES:
    warn if request contains more OIDs than max_oids and SET operation
    (and type&amp;value checks) will be done in chunks.
fix set method when request contains more OIDs than max_oids (2nd and
 subsequent chunk were ignored)
 [2011-08-31 08:36 UTC] lytboris@php.net
Automatic comment from SVN on behalf of lytboris
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=315865
Log: more tuning based on discussion in FR #40816:
 * parse all OIDs earlier, detect all wrong OIDs before any query
   is made (GET-operations)
 * introduce ERRNO_MULTIPLE_SET_QUERIES:
    warn if request contains more OIDs than max_oids and SET operation
    (and type&amp;value checks) will be done in chunks.
fix set method when request contains more OIDs than max_oids (2nd and
 subsequent chunk were ignored)
 [2011-08-31 08:40 UTC] lytboris@php.net
-Summary: Add "snmptranslate" function +Summary: Perform multiple OID operations in transaction manner -Status: Feedback +Status: Open
 [2011-08-31 08:40 UTC] lytboris@php.net
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
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

Commits 315862 & 315865 forces OID check before any query is made. Though set method will check type&value in chunked mode. If SET query should be done in multiple chunks (OID array supplied is bigger that max_oids) a warning will be raised.
 [2011-08-31 08:40 UTC] lytboris@php.net
-Status: Assigned +Status: To be documented
 [2011-08-31 08:40 UTC] lytboris@php.net
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
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 [2011-08-31 19:58 UTC] lytboris@php.net
-Status: To be documented +Status: Open
 [2011-08-31 19:58 UTC] lytboris@php.net
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
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 [2011-08-31 19:58 UTC] lytboris@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 07 22:01:27 2024 UTC