--- cacti-0.8.6c/lib/snmp.php 2005-03-27 16:03:27.000000000 -0500 +++ cacti-0.8.6c-new/lib/snmp.php 2005-03-27 16:00:26.000000000 -0500 @@ -26,6 +26,9 @@ define("REGEXP_SNMP_TRIM", "(hex|counter(32|64)|gauge|gauge(32|64)|float|ipaddress|string|integer):"); +define("SNMP_METHOD_PHP", 1); +define("SNMP_METHOD_BINARY", 2); + /* we must use an apostrophe to escape community names under Unix in case the user uses characters that the shell might interpret. the ucd-snmp binaries on Windows flip out when you do this, but are perfectly happy with a quotation mark. */ @@ -41,18 +44,17 @@ $retries = read_config_option("snmp_retries"); if ($retries == "") $retries = 3; - /* always use SNMP version 1 for UI stuff */ - if ($environ == SNMP_WEBUI) { - $version = "1"; - } - - if (($config["php_snmp_support"] == true) && ($version == "1")) { + if (snmp_get_method($version) == SNMP_METHOD_PHP) { /* make sure snmp* is verbose so we can see what types of data we are getting back */ snmp_set_quick_print(0); + if ($version == "1") { $snmp_value = @snmpget("$hostname:$port", $community, $oid, ($timeout * 1000), $retries); - }else{ + }else { + $snmp_value = @snmp2_get("$hostname:$port", $community, $oid, ($timeout * 1000), $retries); + } + }else { /* ucd/net snmp want the timeout in seconds */ $timeout = ceil($timeout / 1000); @@ -97,13 +99,12 @@ $retries = read_config_option("snmp_retries"); if ($retries == "") $retries = 3; - /* always use SNMP version 1 for UI stuff */ - if ($environ == SNMP_WEBUI) { - $version = "1"; - } - - if (($config["php_snmp_support"] == true) && ($version == "1")) { + if (snmp_get_method($version) == SNMP_METHOD_PHP) { + if ($version == "1") { $temp_array = @snmpwalkoid("$hostname:$port", $community, $oid, ($timeout * 1000), $retries); + } else { + $temp_array = @snmp2_walk("$hostname:$port", $community, $oid, ($timeout * 1000), $retries); + } $o = 0; for (@reset($temp_array); $i = @key($temp_array); next($temp_array)) { @@ -183,4 +184,22 @@ return trim($string); } +function snmp_get_method($version = 1) { + if ((function_exists("snmpget")) && ($version == 1)) { + return SNMP_METHOD_PHP; + }else if ((function_exists("snmp2_get")) && ($version == 2)) { + return SNMP_METHOD_PHP; + }else if ((($version == 2) || ($version == 3)) && (file_exists(read_config_option("path_snmpget")))) { + return SNMP_METHOD_BINARY; + }else if (function_exists("snmpget")) { + /* last resort (hopefully it isn't a 64-bit result) */ + return SNMP_METHOD_PHP; + }else if (file_exists(read_config_option("path_snmpget"))) { + return SNMP_METHOD_BINARY; + }else{ + /* looks like snmp is broken */ + return SNMP_METHOD_BINARY; + } +} + ?> \ No newline at end of file