Merge pull request #2840 from adaniels21487/issue-1851

Cisco CBQOS
This commit is contained in:
Neil Lathwood
2016-01-29 10:21:34 +00:00
9 changed files with 685 additions and 0 deletions

View File

@@ -1268,4 +1268,70 @@ function register_mibs($device, $mibs, $included_by)
}
echo "\n";
} // register_mibs
/**
* SNMPWalk_array_num - performs a numeric SNMPWalk and returns an array containing $count indexes
* One Index:
* From: 1.3.6.1.4.1.9.9.166.1.15.1.1.27.18.655360 = 0
* To: $array['1.3.6.1.4.1.9.9.166.1.15.1.1.27.18']['655360'] = 0
* Two Indexes:
* From: 1.3.6.1.4.1.9.9.166.1.15.1.1.27.18.655360 = 0
* To: $array['1.3.6.1.4.1.9.9.166.1.15.1.1.27']['18']['655360'] = 0
* And so on...
* Think snmpwalk_cache_*_oid but for numeric data.
*
* Why is this useful?
* Some SNMP data contains a single index (eg. ifIndex in IF-MIB) and some is dual indexed
* (eg. PolicyIndex/ObjectsIndex in CISCO-CLASS-BASED-QOS-MIB).
* The resulting array allows us to easily access the top level index we want and iterate over the data from there.
*
* @param $device
* @param $OID
* @param int $indexes
* @internal param $string
* @return array
*/
function snmpwalk_array_num($device,$oid,$indexes=1) {
$array = array();
$string = snmp_walk($device, $oid, '-Osqn');
if ( $string === false) {
// False means: No Such Object.
return false;
}
if ($string == "") {
// Empty means SNMP timeout or some such.
return null;
}
// Let's turn the string into something we can work with.
foreach (explode("\n", $string) as $line) {
if ($line[0] == '.') {
// strip the leading . if it exists.
$line = substr($line,1);
}
list($key, $value) = explode(' ', $line, 2);
$prop_id = explode('.', $key);
$value = trim($value);
// if we have requested more levels that exist, set to the max.
if ($indexes > count($prop_id)) {
$indexes = count($prop_id)-1;
}
for ($i=0;$i<$indexes;$i++) {
// Pop the index off.
$index = array_pop($prop_id);
$value = array($index => $value);
}
// Rebuild our key
$key = implode('.',$prop_id);
// Add the entry to the master array
$array = array_replace_recursive($array,array($key => $value));
}
return $array;
}