Indexed SNMP queries do not work with php-snmp

Post support questions that directly relate to Linux/Unix operating systems.

Moderators: Developers, Moderators

Post Reply
rollodp
Posts: 3
Joined: Wed Dec 21, 2005 9:42 am

Indexed SNMP queries do not work with php-snmp

Post by rollodp »

I'm running Cacti 0.8.6g on Fedora Core 4. I am unable to perform indexed snmp queries.

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");
        }
?>
Create exectest.php:

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");
        }
?>
http://host/cacti/snmpwalktest.php gives:

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 
but http://host/cacti/exectest.php gives:

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:
Note there is an empty response from @snmprealwalk from the exec()ed snmpwalktest.php

Am I barking up the wrong tree, or is there a problem with php-snmp here?
User avatar
rony
Developer/Forum Admin
Posts: 6022
Joined: Mon Nov 17, 2003 6:35 pm
Location: Michigan, USA
Contact:

Post by rony »

What version of php?
[size=117][i][b]Tony Roman[/b][/i][/size]
[size=84][i]Experience is what causes a person to make new mistakes instead of old ones.[/i][/size]
[size=84][i]There are only 3 way to complete a project: Good, Fast or Cheap, pick two.[/i][/size]
[size=84][i]With age comes wisdom, what you choose to do with it determines whether or not you are wise.[/i][/size]
rollodp
Posts: 3
Joined: Wed Dec 21, 2005 9:42 am

PHP Version

Post by rollodp »

Sorry, forgot to say...

$> yum info php
[snip]
Installed Packages
Name : php
Arch : i386
Version: 5.0.4
Release: 10.5
Size : 5.9 M
Repo : installed
[snip]
rollodp
Posts: 3
Joined: Wed Dec 21, 2005 9:42 am

Installed 0.8.6h and this started working

Post by rollodp »

I just installed 0.8.6h on a fresh install of FC4 and it started working ok. Dunno why the above was causing problems but at least it works now.
Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests