Ability to use MIB text-value definitions

Anything that you think should be in Cacti.

Moderators: Developers, Moderators

Post Reply
_Paul
Posts: 2
Joined: Fri Jun 18, 2004 11:29 am

Ability to use MIB text-value definitions

Post by _Paul »

I recently picked up the Compaq(HP) Temperature templates from www.eatworms.org.uk. They highlighted an issue where the MIB does contain good correlation between an integer type and text descriptors, in this case for sensor locale...

Code: Select all

    cpqHeTemperatureLocale OBJECT-TYPE
        SYNTAX  INTEGER {
            other(1),
            unknown(2),
            system(3),
            systemBoard(4),
            ioBoard(5),
            cpu(6),
            memory(7),
            storage(8),
            removableMedia(9),
            powerSupply(10),
            ambient(11),
            chassis(12),
            bridgeCard(13)
            }
However, there's no way for cacti_snmp_walk() to see this text if it is returned by a walk since it is either trimmed away via regex (UCD/SNMP-NET) or worse not provided natively when using PHP's internal SNMP support. I worked around this by adding a new array element to $snmp_array called []["mibvalue"] then by switching to UCD mode which at least gets the labels in its output. Now in cacti_snmp_walk I do this after populating ["oid"] and ["value"]...

Code: Select all

$snmp_array[$i]["mibvalue"] = format_raw_snmp_string($temp_array[$i]);
Here's the stripped down function that returns the goods from snmpwalk.

Code: Select all

function format_raw_snmp_string($string) {
	/* strip off all leading junk (the oid and stuff) */
	$string = trim(ereg_replace(".*= ", "", $string));

	return trim($string);
}
To make MIBs expand (required for the locale strings to show up in the walk) I also needed to add the "-m all" option to my snmpwalk. I just appended that to the SNMPWALK path under Cacti settings via the console. Now the output of SNMPWALKs look something like this... (note the cool locale IDs that aren't just numbers but things like "CPU" and "powerSupply".

Code: Select all

enterprises.compaq.cpqHealth.cpqHeComponent.cpqHeThermal.cpqHeTemperatureTable.cpqHeTemperatureEntry.cpqHeTemperatureChassis.0.1 = 0
enterprises.compaq.cpqHealth.cpqHeComponent.cpqHeThermal.cpqHeTemperatureTable.cpqHeTemperatureEntry.cpqHeTemperatureChassis.0.2 = 0
enterprises.compaq.cpqHealth.cpqHeComponent.cpqHeThermal.cpqHeTemperatureTable.cpqHeTemperatureEntry.cpqHeTemperatureChassis.0.3 = 0
enterprises.compaq.cpqHealth.cpqHeComponent.cpqHeThermal.cpqHeTemperatureTable.cpqHeTemperatureEntry.cpqHeTemperatureChassis.0.4 = 0
enterprises.compaq.cpqHealth.cpqHeComponent.cpqHeThermal.cpqHeTemperatureTable.cpqHeTemperatureEntry.cpqHeTemperatureIndex.0.1 = 1
enterprises.compaq.cpqHealth.cpqHeComponent.cpqHeThermal.cpqHeTemperatureTable.cpqHeTemperatureEntry.cpqHeTemperatureIndex.0.2 = 2
enterprises.compaq.cpqHealth.cpqHeComponent.cpqHeThermal.cpqHeTemperatureTable.cpqHeTemperatureEntry.cpqHeTemperatureIndex.0.3 = 3
enterprises.compaq.cpqHealth.cpqHeComponent.cpqHeThermal.cpqHeTemperatureTable.cpqHeTemperatureEntry.cpqHeTemperatureIndex.0.4 = 4
enterprises.compaq.cpqHealth.cpqHeComponent.cpqHeThermal.cpqHeTemperatureTable.cpqHeTemperatureEntry.cpqHeTemperatureLocale.0.1 = cpu(6)
enterprises.compaq.cpqHealth.cpqHeComponent.cpqHeThermal.cpqHeTemperatureTable.cpqHeTemperatureEntry.cpqHeTemperatureLocale.0.2 = cpu(6)
enterprises.compaq.cpqHealth.cpqHeComponent.cpqHeThermal.cpqHeTemperatureTable.cpqHeTemperatureEntry.cpqHeTemperatureLocale.0.3 = ioBoard(5)
enterprises.compaq.cpqHealth.cpqHeComponent.cpqHeThermal.cpqHeTemperatureTable.cpqHeTemperatureEntry.cpqHeTemperatureLocale.0.4 = cpu(6)
enterprises.compaq.cpqHealth.cpqHeComponent.cpqHeThermal.cpqHeTemperatureTable.cpqHeTemperatureEntry.cpqHeTemperatureCelsius.0.1 = 31
enterprises.compaq.cpqHealth.cpqHeComponent.cpqHeThermal.cpqHeTemperatureTable.cpqHeTemperatureEntry.cpqHeTemperatureCelsius.0.2 = 29
enterprises.compaq.cpqHealth.cpqHeComponent.cpqHeThermal.cpqHeTemperatureTable.cpqHeTemperatureEntry.cpqHeTemperatureCelsius.0.3 = 36
enterprises.compaq.cpqHealth.cpqHeComponent.cpqHeThermal.cpqHeTemperatureTable.cpqHeTemperatureEntry.cpqHeTemperatureCelsius.0.4 = 30
enterprises.compaq.cpqHealth.cpqHeComponent.cpqHeThermal.cpqHeTemperatureTable.cpqHeTemperatureEntry.cpqHeTemperatureThreshold.0.1 = 58
enterprises.compaq.cpqHealth.cpqHeComponent.cpqHeThermal.cpqHeTemperatureTable.cpqHeTemperatureEntry.cpqHeTemperatureThreshold.0.2 = 70
enterprises.compaq.cpqHealth.cpqHeComponent.cpqHeThermal.cpqHeTemperatureTable.cpqHeTemperatureEntry.cpqHeTemperatureThreshold.0.3 = 62
enterprises.compaq.cpqHealth.cpqHeComponent.cpqHeThermal.cpqHeTemperatureTable.cpqHeTemperatureEntry.cpqHeTemperatureThreshold.0.4 = 70
enterprises.compaq.cpqHealth.cpqHeComponent.cpqHeThermal.cpqHeTemperatureTable.cpqHeTemperatureEntry.cpqHeTemperatureCondition.0.1 = ok(2)
enterprises.compaq.cpqHealth.cpqHeComponent.cpqHeThermal.cpqHeTemperatureTable.cpqHeTemperatureEntry.cpqHeTemperatureCondition.0.2 = ok(2)
enterprises.compaq.cpqHealth.cpqHeComponent.cpqHeThermal.cpqHeTemperatureTable.cpqHeTemperatureEntry.cpqHeTemperatureCondition.0.3 = ok(2)
enterprises.compaq.cpqHealth.cpqHeComponent.cpqHeThermal.cpqHeTemperatureTable.cpqHeTemperatureEntry.cpqHeTemperatureCondition.0.4 = ok(2)
enterprises.compaq.cpqHealth.cpqHeComponent.cpqHeThermal.cpqHeTemperatureTable.cpqHeTemperatureEntry.cpqHeTemperatureThresholdType.0.1 = caution(9)
enterprises.compaq.cpqHealth.cpqHeComponent.cpqHeThermal.cpqHeTemperatureTable.cpqHeTemperatureEntry.cpqHeTemperatureThresholdType.0.2 = caution(9)
enterprises.compaq.cpqHealth.cpqHeComponent.cpqHeThermal.cpqHeTemperatureTable.cpqHeTemperatureEntry.cpqHeTemperatureThresholdType.0.3 = caution(9)
enterprises.compaq.cpqHealth.cpqHeComponent.cpqHeThermal.cpqHeTemperatureTable.cpqHeTemperatureEntry.cpqHeTemperatureThresholdType.0.4 = caution(9)


Finally, in lib/data_query.php function query_snmp_host() had to be modified to support a new "source" tag type called "mibvalue". This code looks like...

Code: Select all

elseif ($field_array["source"] == "mibvalue") {
				for ($i=0;($i<sizeof($snmp_data));$i++) {
					$snmp_index = ereg_replace('.*\.([0-9]+)$', "\\1", $snmp_data[$i]["oid"]);
					$oid = $field_array["oid"] . ".$snmp_index";
					
					debug_log_insert("data_query", "Found item [$field_name='" . $snmp_data[$i]["mibvalue"]. "'] index: $snmp_index [from mibvalue]");
					
					db_execute("replace into host_snmp_cache 
						(host_id,snmp_query_id,field_name,field_value,snmp_index,oid)
						values ($host_id,$snmp_query_id,'$field_name','" . $snmp_data[$i]["mibvalue"] . "',$snmp_index,'$oid')");
				}
Now my XML file is modified so that the locale field uses the new source type...

Code: Select all

- <cpqHeTemperatureLocale>
  <name>Location</name> 
  <method>walk</method> 
  <source>mibvalue</source> 
  <direction>input</direction> 
  <oid>.1.3.6.1.4.1.232.6.2.6.8.1.3.0</oid> 
  </cpqHeTemperatureLocale>
The result is that my CPU graphs now have titles that reflect the sensor locations in a human-readable form.

I don't know if you would want to extend this type of value since it doesn't work with all 3 methods of SNMP walking. I just find it useful.

_Paul
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests