Jump to content

Error catching with snmpget


rhyspaterson

Recommended Posts

Hey Guys,

 

$query = snmpget($host, $community, $oid, $timeout, $retry);

 

Code works fine for devices that respond. However, when they don't, i get the following error:

 

PHP Warning: snmpget() [function.snmpget]: No response from (insert device name here)

 

The PHP manual says snmpget will return false when it fails. I have tried to catch it as below:

 

$query = snmpget($host, $community, $oid, $timeout, $retry);
if ($query == FALSE}{
   echo "Device is not responding!";
   exit();
}

 

I have also tried this horrendous code:

 

if (snmp2_get($host, $community, $oid, $timeout, $retry) == FALSE){
   echo "Device is not responding!";
   exit();
}

 

But i still get the original 'no response' error that PHP throws me. I have tried using NULL and TRY/CATCH but no luck. Could anyone kick me in the right direction?

 

Cheers!

 

Link to comment
https://forums.phpfreaks.com/topic/107399-error-catching-with-snmpget/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.