-
Notifications
You must be signed in to change notification settings - Fork 16
Description
I have begun working on using this class, and it works great. However I am running into trouble when invalid information is passed to the class.
I specifically am testing an invalid IP address, as well as invalid community names. Currently I am getting fatal errors in PHP for both. This is against both PHP7.4, as well as PHP8.2 and am having a hell of a time getting the try catch block to work as you designed.
I have been attempting to alter the throw so it does not spew these errors but have not been having any luck there or in making a __construct() within the ConnectionException to attempt to grab the error. I do see the error information when I do a print_r and it returns the object, but suspect that I am not getting all the way to the \Exception class for some reason..
Any suggestions or guidance on how to fix this would be appreciated.. ( Still learning the more complex areas of PHP, and it is biting me in the rear end)
chubbard@lnms01:/opt/nmsApi/testing/freedsx$ /usr/bin/php7.4 ./testDisc.php
PHP Fatal error: Uncaught FreeDSx\Snmp\Exception\ConnectionException in /opt/nmsApi/vendor/freedsx/snmp/src/FreeDSx/Snmp/Protocol/ClientProtocolHandler.php:152
Stack trace:
#0 /opt/nmsApi/vendor/freedsx/snmp/src/FreeDSx/Snmp/Protocol/ClientProtocolHandler.php(122): FreeDSx\Snmp\Protocol\ClientProtocolHandler->sendRequestGetResponse()
#1 /opt/nmsApi/vendor/freedsx/snmp/src/FreeDSx/Snmp/SnmpClient.php(233): FreeDSx\Snmp\Protocol\ClientProtocolHandler->handle()
#2 /opt/nmsApi/vendor/freedsx/snmp/src/FreeDSx/Snmp/SnmpClient.php(113): FreeDSx\Snmp\SnmpClient->send()
#3 /opt/nmsApi/vendor/freedsx/snmp/src/FreeDSx/Snmp/SnmpClient.php(126): FreeDSx\Snmp\SnmpClient->get()
#4 /opt/nmsApi/vendor/freedsx/snmp/src/FreeDSx/Snmp/SnmpClient.php(139): FreeDSx\Snmp\SnmpClient->getOid()
#5 /opt/nmsApi/testing/freedsx/testDisc.php(15): FreeDSx\Snmp\SnmpClient->getValue()
#6 {main}
thrown in /opt/nmsApi/vendor/freedsx/snmp/src/FreeDSx/Snmp/Protocol/ClientProtocolHandler.php on line 152
chubbard@nms01:/opt/nmsApi/testing/freedsx$ /usr/bin/php8.2 ./testDisc.php
PHP Fatal error: Uncaught FreeDSx\Snmp\Exception\ConnectionException in /opt/nmsApi/vendor/freedsx/snmp/src/FreeDSx/Snmp/Protocol/ClientProtocolHandler.php:152
Stack trace:
#0 /opt/nmsApi/vendor/freedsx/snmp/src/FreeDSx/Snmp/Protocol/ClientProtocolHandler.php(122): FreeDSx\Snmp\Protocol\ClientProtocolHandler->sendRequestGetResponse()
#1 /opt/nmsApi/vendor/freedsx/snmp/src/FreeDSx/Snmp/SnmpClient.php(233): FreeDSx\Snmp\Protocol\ClientProtocolHandler->handle()
#2 /opt/nmsApi/vendor/freedsx/snmp/src/FreeDSx/Snmp/SnmpClient.php(113): FreeDSx\Snmp\SnmpClient->send()
#3 /opt/nmsApi/vendor/freedsx/snmp/src/FreeDSx/Snmp/SnmpClient.php(126): FreeDSx\Snmp\SnmpClient->get()
#4 /opt/nmsApi/vendor/freedsx/snmp/src/FreeDSx/Snmp/SnmpClient.php(139): FreeDSx\Snmp\SnmpClient->getOid()
#5 /opt/nmsApi/testing/freedsx/testDisc.php(15): FreeDSx\Snmp\SnmpClient->getValue()
#6 {main}
thrown in /opt/nmsApi/vendor/freedsx/snmp/src/FreeDSx/Snmp/Protocol/ClientProtocolHandler.php on line 152
This is what I am attempting to run:
cat testDisc.php
<?php
require __DIR__ . '/../../vendor/autoload.php';
use \FreeDSx\Snmp\SnmpClient;
$snmp = new SnmpClient([
'host' => '192.168.15.589',
'version' => 2,
'community' => 'public2',
'timeout_connect' => 1,
'timeout_read' => 1,
]);
# Get a specific OID value as a string...
$data= $snmp->getValue('1.3.6.1.2.1.1.1.0');
echo $data . "\n\n";
?>