|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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: -------------- - PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 02 14:00:01 2025 UTC |
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) --------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?