I've found there's an issue with using php-snmp inside a exec()ed php script that means the @snmprealwalk function returns an empty array. Invoking the script directly works as expected from http or from a command line as cactiuser or root.
This affects lib/snmp.php, cacti_snmp_walk() and means that all my indexed snmp data queries return zero rows.
To prove this I did:
Create cacti/snmpwalktest.php:
Code: Select all
<?php
/* invoke snmprealwalk */
$temp_array = @snmprealwalk("host:161", "public",".1.3.6.1.2.1.25.2.3.1.3", 8000, 3);
print("snmpresult size " . sizeof($temp_array) . "\n");
print("snmprealwalk result: $temp_array\n");
/* print the response from snmprealwalk */
for (@reset($temp_array); $i = @key($temp_array); next($temp_array)) {
$oid = ereg_replace("^\.", "", $i);
$val = $temp_array[$i];
print("$oid = $val \n");
}
?>
Code: Select all
<?php
$cmd = "echo hello";
print("Performing exec($cmd)\n");
exec($cmd,$out,$err);
print("Error code : $err\n");
print("Output:\n");
for($i=0; list($key, $value) = each($out); $i++) {
print("out[$i]: $value\n");
}
$cmd = "/usr/bin/php -q /var/www/html/cacti/snmpwalktest.php";
print("\nPerforming exec($cmd)\n");
exec($cmd,$out,$err);
print("Error code : $err\n");
print("Output:\n");
for($i=0; list($key, $value) = each($out); $i++) {
print("out[$i]: $value\n");
}
?>
Code: Select all
snmpresult size 5
snmprealwalk result: Array
HOST-RESOURCES-MIB::hrStorageDescr.1 = STRING: C:\ Label:Win2k3 Serial Number 28851fff
HOST-RESOURCES-MIB::hrStorageDescr.2 = STRING: D:\ Label:CVS Serial Number beece64f
HOST-RESOURCES-MIB::hrStorageDescr.3 = STRING: E:\ Label:Archives Serial Number 74c82d2f
HOST-RESOURCES-MIB::hrStorageDescr.4 = STRING: Virtual Memory
HOST-RESOURCES-MIB::hrStorageDescr.5 = STRING: Physical Memory
Code: Select all
Performing exec(echo hello)
Error code : 0
Output:
out[0]: hello
Performing exec(/usr/bin/php -q /var/www/html/cacti/snmpwalktest.php)
Error code : 0
Output:
out[0]: snmpresult size 1
out[1]: snmprealwalk result:
Am I barking up the wrong tree, or is there a problem with php-snmp here?