possible cacti_snmp_get() bug with built-in snmp support

Post general support questions here that do not specifically fall into the Linux or Windows categories.

Moderators: Developers, Moderators

Post Reply
bradfritz
Posts: 1
Joined: Tue May 14, 2002 5:55 pm

possible cacti_snmp_get() bug with built-in snmp support

Post by bradfritz »

First let me say cacti is a *great* tool. Ian and others, thank you for developing and
sharing it.

I am running v0.6.8 from the catci-0.6.8-1 debian package and I have found what appears
to be a bug in cacti_snmp_get(). When using the built-in php snmp support (via the
php4-snmp-4.1.2-4 debian package), I get the following error from cmd.php while
trying to gather byte/second values:

ERROR: expected 1 data source readings (got 0) from =:...

The culprit is rrdtool commands formated like so:

rrdtool update /usr/share/cacti/rra/traf_aa_bb_cc_dd_3_in.rrd \
--template traf_aa_bb_cc_dd_N:interfaces.ifTable.ifEntry.ifInOctets.3 = 115197272

(Notice the out-of-place "interfaces.ifTable.ifEntry.ifInOctets.3 = ".)

I was able to fix the problem by moving
$snmp_value = trim(ereg_replace("(.*=)", "", $snmp_value));

outside its else block so that it is applied regardless of the value in
$config["php_snmp_support"].

I scanned through the message board and saw similar reports of built-in snmp
support not working, but none seemed to point to the same bug. My apologies
if I'm reporting a problem that's already been discussed.

--Brad
raX
Lead Developer
Posts: 2243
Joined: Sat Oct 13, 2001 7:00 pm
Location: Carlisle, PA
Contact:

Post by raX »

This is a good point you make, it would make sense to apply this regexp regardless of what type of SNMP support you are using. I never knew there was a '=' character in the output of builtin support. Now I know (each implimentation seems to want to do it their own way :-?).

Anyhow, I'll be sure to make that change.

-Ian
User avatar
Jazzee
Posts: 12
Joined: Wed Jul 31, 2002 2:56 pm
Location: Calgary, AB

possible cacti_snmp_get() bug with built-in snmp support

Post by Jazzee »

Hello Ian,

I am running 0.6.8 and have recently moved to cacti's internal snmp. I have been monitoring 2 Cisco 6509s and 25 Cisco 3524s. As soon as I move to internal SNMP I received the error message:

ERROR: expected 1 data source readings (got 0) from =:...

So I added the following code just before the "remove ALL quotes" comment in the condition statement if ($config["php_snmp_support"] == true) and it appears to be working correctly now:

$snmp_value = trim(ereg_replace("(.*=)","",$snmp_value));

Not sure if you were aware of this or not.

Jaz
anthony.warren
Posts: 31
Joined: Fri Nov 22, 2002 10:50 am
Location: Rochester, UK

Post by anthony.warren »

Could you please post you snmp_functions.php file because I am unsure where to make these changes.
User avatar
Jazzee
Posts: 12
Joined: Wed Jul 31, 2002 2:56 pm
Location: Calgary, AB

code for cacti_snmp_get function

Post by Jazzee »

function cacti_snmp_get($hostname, $community, $oid, $force_type, $force_version) {
include ('include/config.php');
include_once ('include/functions.php');

if ($config["php_snmp_support"] == true) {
/* make sure snmp* is verbose so we can see what types of data
we are getting back */
snmp_set_quick_print(0);

$snmp_value = snmpget($hostname, $community, $oid);
$snmp_value = preg_replace("/^[^=]*= /","",$snmp_value);

/* sometimes a string is presenting in hex; not ASCII (ex. win32), in
this case, convert the hex to ASCII */
if ($force_type == "hex") {
$snmp_value = convert_mac_address(trim(eregi_replace("hex:", "", $snmp_value)));
}else{
if (eregi("(.*)(hex:)(.*)", $snmp_value)) {
/* grab the actual hex string */
$snmp_value = trim(ereg_replace("(.*)(Hex:)(.*)", "\\3", $snmp_value));

/* strip all formatting and convert the string */
$snmp_value = hex2bin(ereg_replace("[^A-Fa-f0-9]", "", $snmp_value));
}
}
$snmp_value = trim(ereg_replace("(.*=)","",$snmp_value));
/* remove ALL quotes */
$snmp_value = str_replace("\"", "", $snmp_value);
}else{
$snmp_value = exec($config["path_snmpget"]["value"] . " $force_version $hostname '$community' $oid");
$snmp_value = trim(ereg_replace("(.*=)", "", $snmp_value));
}


$snmp_value = trim(eregi_replace("(hex|counter(32|64)|gauge|gauge(32|64)|float|ipaddress):", "", $snmp_value));

return $snmp_value;
}
---
"You're one of them, aren't you?" "No. I'm something else."
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests