Cacti / cacti

Cacti ™
http://www.cacti.net
GNU General Public License v2.0
1.65k stars 406 forks source link

Unnecessary warnings appear when host name is not resolved #4267

Closed xmacan closed 3 years ago

xmacan commented 3 years ago

In console -> devices -> device -> I got warning (in section SNMP Information): Warning: SNMP::__construct(): php_network_getaddresses: getaddrinfo failed: Name does not resolve in /usr/local/share/cacti/lib/snmp.php on line 75 System SNMP error - SNMP::get(): Could not open snmp connection: Unknown host (mail.wrong-name.xz) (Invalid argument)

It is happen in the case: 1) wrong hostname 2) PHP SNMP enabled

Without PHP SNMP, I got correctly- Host SNMP error

I guess that the error message should be the same.

Cacti 1.2.17, FreeBSD 12.1, PHP 7.4.8

netniV commented 3 years ago

Let me know if this works for you....

--- a/lib/snmp.php
+++ b/lib/snmp.php
@@ -72,7 +72,7 @@ function cacti_snmp_session($hostname, $community, $version, $auth_user = '', $a
        $timeout_us = (int) ($timeout_ms * 1000);

        try {
-               $session = new SNMP($version, $hostname . ':' . $port, ($version == 3 ? $auth_user : $community), $timeout_us, $retries);
+               $session = @new SNMP($version, $hostname . ':' . $port, ($version == 3 ? $auth_user : $community), $timeout_us, $retries);
        } catch (Exception $e) {
                return false;
        }
xmacan commented 3 years ago

better, now I see only: SNMP Information System SNMP error - SNMP::get(): Could not open snmp connection: Unknown host (mail.wrong-name.xz) (Invalid argument)

netniV commented 3 years ago

Is that good enough or should we work on it more?

xmacan commented 3 years ago

I guess that it is enough. PHP warning is gone and message Could not open snmp connection: Unknown host is sufficient