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
@@ -0,0 +1,75 @@
<?php
/*
* LibreNMS module to display Cisco Class-Based QoS Details
*
* Copyright (c) 2015 Aaron Daniels <aaron@daniels.id.au>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
require_once "../includes/component.php";
$component = new component();
$options['filter']['type'] = array('=','Cisco-CBQOS');
$components = $component->getComponents($device['device_id'],$options);
// We only care about our device id.
$components = $components[$device['device_id']];
// Determine a policy to show.
if (!isset($vars['policy'])) {
foreach ($components as $id => $array) {
if ( ($array['qos-type'] == 1) && ($array['ifindex'] == $port['ifIndex']) && ($array['parent'] == 0) ) {
// Found the first policy
$vars['policy'] = $id;
continue;
}
}
}
include "includes/graphs/common.inc.php";
$rrd_options .= " -l 0 -E ";
$rrd_options .= " COMMENT:'Class-Map Now Avg Max\\n'";
$rrd_additions = "";
$count = 0;
foreach ($components as $id => $array) {
if ( ($array['qos-type'] == 2) && ($array['parent'] == $components[$vars['policy']]['sp-obj']) && ($array['sp-id'] == $components[$vars['policy']]['sp-id'])) {
$rrd_filename = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename("port-".$array['ifindex']."-cbqos-".$array['sp-id']."-".$array['sp-obj'].".rrd");
if (file_exists($rrd_filename)) {
// Stack the area on the second and subsequent DS's
$stack = "";
if ($count != 0) {
$stack = ":STACK ";
}
// Grab a color from the array.
if ( isset($config['graph_colours']['mixed'][$count]) ) {
$color = $config['graph_colours']['mixed'][$count];
}
else {
$color = $config['graph_colours']['oranges'][$count-7];
}
$rrd_additions .= " DEF:DS" . $count . "=" . $rrd_filename . ":bufferdrops:AVERAGE ";
$rrd_additions .= " CDEF:MOD" . $count . "=DS" . $count . ",8,* ";
$rrd_additions .= " AREA:MOD" . $count . "#" . $color . ":'" . str_pad(substr($components[$id]['label'],0,15),15) . "'" . $stack;
$rrd_additions .= " GPRINT:MOD" . $count . ":LAST:%6.2lf%s ";
$rrd_additions .= " GPRINT:MOD" . $count . ":AVERAGE:%6.2lf%s ";
$rrd_additions .= " GPRINT:MOD" . $count . ":MAX:%6.2lf%s\\\l ";
$count++;
}
}
}
if ($rrd_additions == "") {
// We didn't add any data points.
}
else {
$rrd_options .= $rrd_additions;
}
@@ -0,0 +1,75 @@
<?php
/*
* LibreNMS module to display Cisco Class-Based QoS Details
*
* Copyright (c) 2015 Aaron Daniels <aaron@daniels.id.au>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
require_once "../includes/component.php";
$component = new component();
$options['filter']['type'] = array('=','Cisco-CBQOS');
$components = $component->getComponents($device['device_id'],$options);
// We only care about our device id.
$components = $components[$device['device_id']];
// Determine a policy to show.
if (!isset($vars['policy'])) {
foreach ($components as $id => $array) {
if ( ($array['qos-type'] == 1) && ($array['ifindex'] == $port['ifIndex']) && ($array['parent'] == 0) ) {
// Found the first policy
$vars['policy'] = $id;
continue;
}
}
}
include "includes/graphs/common.inc.php";
$rrd_options .= " -l 0 -E ";
$rrd_options .= " COMMENT:'Class-Map Now Avg Max\\n'";
$rrd_additions = "";
$count = 0;
foreach ($components as $id => $array) {
if ( ($array['qos-type'] == 2) && ($array['parent'] == $components[$vars['policy']]['sp-obj']) && ($array['sp-id'] == $components[$vars['policy']]['sp-id'])) {
$rrd_filename = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename("port-".$array['ifindex']."-cbqos-".$array['sp-id']."-".$array['sp-obj'].".rrd");
if (file_exists($rrd_filename)) {
// Stack the area on the second and subsequent DS's
$stack = "";
if ($count != 0) {
$stack = ":STACK ";
}
// Grab a color from the array.
if ( isset($config['graph_colours']['mixed'][$count]) ) {
$color = $config['graph_colours']['mixed'][$count];
}
else {
$color = $config['graph_colours']['oranges'][$count-7];
}
$rrd_additions .= " DEF:DS" . $count . "=" . $rrd_filename . ":qosdrops:AVERAGE ";
$rrd_additions .= " CDEF:MOD" . $count . "=DS" . $count . ",8,* ";
$rrd_additions .= " AREA:MOD" . $count . "#" . $color . ":'" . str_pad(substr($components[$id]['label'],0,15),15) . "'" . $stack;
$rrd_additions .= " GPRINT:MOD" . $count . ":LAST:%6.2lf%s ";
$rrd_additions .= " GPRINT:MOD" . $count . ":AVERAGE:%6.2lf%s ";
$rrd_additions .= " GPRINT:MOD" . $count . ":MAX:%6.2lf%s\\\l ";
$count++;
}
}
}
if ($rrd_additions == "") {
// We didn't add any data points.
}
else {
$rrd_options .= $rrd_additions;
}
@@ -0,0 +1,75 @@
<?php
/*
* LibreNMS module to display Cisco Class-Based QoS Details
*
* Copyright (c) 2015 Aaron Daniels <aaron@daniels.id.au>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
require_once "../includes/component.php";
$component = new component();
$options['filter']['type'] = array('=','Cisco-CBQOS');
$components = $component->getComponents($device['device_id'],$options);
// We only care about our device id.
$components = $components[$device['device_id']];
// Determine a policy to show.
if (!isset($vars['policy'])) {
foreach ($components as $id => $array) {
if ( ($array['qos-type'] == 1) && ($array['ifindex'] == $port['ifIndex']) && ($array['parent'] == 0) ) {
// Found the first policy
$vars['policy'] = $id;
continue;
}
}
}
include "includes/graphs/common.inc.php";
$rrd_options .= " -l 0 -E ";
$rrd_options .= " COMMENT:'Class-Map Now Avg Max\\n'";
$rrd_additions = "";
$count = 0;
foreach ($components as $id => $array) {
if ( ($array['qos-type'] == 2) && ($array['parent'] == $components[$vars['policy']]['sp-obj']) && ($array['sp-id'] == $components[$vars['policy']]['sp-id'])) {
$rrd_filename = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename("port-".$array['ifindex']."-cbqos-".$array['sp-id']."-".$array['sp-obj'].".rrd");
if (file_exists($rrd_filename)) {
// Stack the area on the second and subsequent DS's
$stack = "";
if ($count != 0) {
$stack = ":STACK ";
}
// Grab a color from the array.
if ( isset($config['graph_colours']['mixed'][$count]) ) {
$color = $config['graph_colours']['mixed'][$count];
}
else {
$color = $config['graph_colours']['oranges'][$count-7];
}
$rrd_additions .= " DEF:DS" . $count . "=" . $rrd_filename . ":postbits:AVERAGE ";
$rrd_additions .= " CDEF:MOD" . $count . "=DS" . $count . ",8,* ";
$rrd_additions .= " AREA:MOD" . $count . "#" . $color . ":'" . str_pad(substr($components[$id]['label'],0,15),15) . "'" . $stack;
$rrd_additions .= " GPRINT:MOD" . $count . ":LAST:%6.2lf%s ";
$rrd_additions .= " GPRINT:MOD" . $count . ":AVERAGE:%6.2lf%s ";
$rrd_additions .= " GPRINT:MOD" . $count . ":MAX:%6.2lf%s\\\l ";
$count++;
}
}
}
if ($rrd_additions == "") {
// We didn't add any data points.
}
else {
$rrd_options .= $rrd_additions;
}
+6
View File
@@ -87,6 +87,12 @@ if (dbFetchCell("SELECT COUNT(*) FROM `ports_vlans` WHERE `port_id` = '".$port['
$menu_options['vlans'] = 'VLANs';
}
// Are there any CBQoS rrd's for this ifIndex?
$cbqos = glob($config['rrd_dir'].'/'.$device['hostname'].'/port-'.$port['ifIndex'].'-cbqos-*.rrd');
if (!empty($cbqos)) {
$menu_options['cbqos'] = 'CBQoS';
}
$sep = '';
foreach ($menu_options as $option => $text) {
echo $sep;
+130
View File
@@ -0,0 +1,130 @@
<?php
/*
* LibreNMS module to display Cisco Class-Based QoS Details
*
* Copyright (c) 2015 Aaron Daniels <aaron@daniels.id.au>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
function find_child($components,$parent,$level) {
global $vars;
foreach($components as $id => $array) {
if ($array['qos-type'] == 3) {
continue;
}
if (($array['parent'] == $components[$parent]['sp-obj']) && ($array['sp-id'] == $components[$parent]['sp-id'])) {
echo "<ul>";
echo "<li>";
if ($array['qos-type'] == 1) {
// Its a policy, we need to make it a link.
echo('<a href="' . generate_url($vars, array('policy' => $id)) . '">' . $array['label'] . '</a>');
}
else {
// No policy, no link
echo $array['label'];
}
if (isset($array['match'])) {
echo ' ('.$array['match'].')';
}
find_child($components,$id,$level+1);
echo "</li>";
echo "</ul>";
}
}
}
$rrdarr = glob($config['rrd_dir'].'/'.$device['hostname'].'/port-'.$port['ifIndex'].'-cbqos-*.rrd');
if (!empty($rrdarr)) {
require_once "../includes/component.php";
$component = new component();
$options['filter']['type'] = array('=','Cisco-CBQOS');
$components = $component->getComponents($device['device_id'],$options);
// We only care about our device id.
$components = $components[$device['device_id']];
if (!isset($vars['policy'])) {
// not set, find the first parent and use it.
foreach ($components as $id => $array) {
if ( ($array['qos-type'] == 1) && ($array['ifindex'] == $port['ifIndex']) && ($array['parent'] == 0) ) {
// Found the first policy
$vars['policy'] = $id;
continue;
}
}
}
echo "\n\n";
// Display the ingress policy at the top of the page.
echo "<div class='col-md-6'><ul class='mktree' id='ingress'>";
echo '<div><strong><i class="fa fa-sign-in"></i>&nbsp;Ingress Policy:</strong></div>';
$found = false;
foreach ($components as $id => $array) {
if ( ($array['qos-type'] == 1) && ($array['ifindex'] == $port['ifIndex']) && ($array['direction'] == 1) && ($array['parent'] == 0) ) {
echo "<li class='liOpen'>";
echo('<a href="' . generate_url($vars, array('policy' => $id)) . '">' . $array['label'] . '</a>');
find_child($components,$id,1);
echo "</li>";
$found = true;
}
}
if (!$found) {
// No Ingress policies
echo '<div><i>No Policies</i></div>';
}
echo '</ul></div>';
// Display the egress policy at the top of the page.
echo "<div class='col-md-6'><ul class='mktree' id='egress'>";
echo '<div><strong><i class="fa fa-sign-out"></i>&nbsp;Egress Policy:</strong></div>';
$found = false;
foreach ($components as $id => $array) {
if ( ($array['qos-type'] == 1) && ($array['ifindex'] == $port['ifIndex']) && ($array['direction'] == 2) && ($array['parent'] == 0) ) {
echo "<li class='liOpen'>";
echo('<a href="' . generate_url($vars, array('policy' => $id)) . '">' . $array['label'] . '</a>');
find_child($components,$id,1);
echo "</li>";
$found = true;
}
}
if (!$found) {
// No Egress policies
echo '<div><i>No Policies</i></div>';
}
echo "</ul></div>\n\n";
// Let's make sure the policy we are trying to access actually exists.
foreach ($components as $id => $array) {
if ( ($array['qos-type'] == 1) && ($array['ifindex'] == $port['ifIndex']) && ($id == $vars['policy']) ) {
// The policy exists.
echo "<div class='col-md-12'>&nbsp;</div>\n\n";
// Display each graph row.
echo "<div class='col-md-12'>";
echo "<div class='graphhead'>Traffic by CBQoS Class - ".$components[$vars['policy']]['label']."</div>";
$graph_array['policy'] = $vars['policy'];
$graph_type = 'port_cbqos_traffic';
include 'includes/print-interface-graphs.inc.php';
echo "<div class='graphhead'>QoS Drops by CBQoS Class - ".$components[$vars['policy']]['label']."</div>";
$graph_array['policy'] = $vars['policy'];
$graph_type = 'port_cbqos_bufferdrops';
include 'includes/print-interface-graphs.inc.php';
echo "<div class='graphhead'>Buffer Drops by CBQoS Class - ".$components[$vars['policy']]['label']."</div>";
$graph_array['policy'] = $vars['policy'];
$graph_type = 'port_cbqos_qosdrops';
include 'includes/print-interface-graphs.inc.php';
echo "</div>\n\n";
}
}
}
+2
View File
@@ -710,6 +710,7 @@ $config['poller_modules']['applications'] = 1;
$config['poller_modules']['cisco-asa-firewall'] = 1;
$config['poller_modules']['mib'] = 0;
$config['poller_modules']['cisco-voice'] = 1;
$config['poller_modules']['cisco-cbqos'] = 1;
$config['poller_modules']['stp'] = 1;
// List of discovery modules. Need to be in this array to be
@@ -742,6 +743,7 @@ $config['discovery_modules']['toner'] = 1;
$config['discovery_modules']['ucd-diskio'] = 1;
$config['discovery_modules']['services'] = 1;
$config['discovery_modules']['charge'] = 1;
$config['discovery_modules']['cisco-cbqos'] = 0;
$config['discovery_modules']['stp'] = 1;
$config['modules_compat']['rfc1628']['liebert'] = 1;
+184
View File
@@ -0,0 +1,184 @@
<?php
/*
* LibreNMS module to capture Cisco Class-Based QoS Details
*
* Copyright (c) 2015 Aaron Daniels <aaron@daniels.id.au>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
if ($device['os_group'] == 'cisco') {
$module = 'Cisco-CBQOS';
echo $module.': ';
require_once 'includes/component.php';
$component = new component();
$components = $component->getComponents($device['device_id'],array('type'=>$module));
// We only care about our device id.
$components = $components[$device['device_id']];
// Begin our master array, all other values will be processed into this array.
$tblCBQOS = array();
// Let's gather some data..
$tblcbQosServicePolicy = snmpwalk_array_num($device, '.1.3.6.1.4.1.9.9.166.1.1');
$tblcbQosObjects = snmpwalk_array_num($device, '.1.3.6.1.4.1.9.9.166.1.5', 2);
$tblcbQosPolicyMapCfg = snmpwalk_array_num($device, '.1.3.6.1.4.1.9.9.166.1.6');
$tblcbQosClassMapCfg = snmpwalk_array_num($device, '.1.3.6.1.4.1.9.9.166.1.7');
$tblcbQosMatchStmtCfg = snmpwalk_array_num($device, '.1.3.6.1.4.1.9.9.166.1.8');
/*
* False == no object found - this is not an error, there is no QOS configured
* null == timeout or something else that caused an error, there may be QOS configured but we couldn't get it.
*/
if ( is_null($tblcbQosServicePolicy) || is_null($tblcbQosObjects) || is_null($tblcbQosPolicyMapCfg) || is_null($tblcbQosClassMapCfg) || is_null($tblcbQosMatchStmtCfg) ) {
// We have to error here or we will end up deleting all our QoS components.
echo "Error\n";
}
else {
// No Error, lets process things.
d_echo("QoS Objects Found:\n");
foreach ($tblcbQosObjects['1.3.6.1.4.1.9.9.166.1.5.1.1.2'] as $spid => $array) {
foreach ($array as $spobj => $index) {
$result = array();
// Produce a unique reproducible index for this entry.
$result['UID'] = hash('crc32', $spid."-".$spobj);
// Now that we have a valid identifiers, lets add some more data
$result['sp-id'] = $spid;
$result['sp-obj'] = $spobj;
// Add the Type, Policy-map, Class-map, etc.
$type = $tblcbQosObjects['1.3.6.1.4.1.9.9.166.1.5.1.1.3'][$spid][$spobj];
$result['qos-type'] = $type;
// Add the Parent, this lets us work out our hierarchy for display later.
$result['parent'] = $tblcbQosObjects['1.3.6.1.4.1.9.9.166.1.5.1.1.4'][$spid][$spobj];
$result['direction'] = $tblcbQosServicePolicy['1.3.6.1.4.1.9.9.166.1.1.1.1.3'][$spid];
$result['ifindex'] = $tblcbQosServicePolicy['1.3.6.1.4.1.9.9.166.1.1.1.1.4'][$spid];
// Gather different data depending on the type.
switch ($type) {
case 1:
// Policy-map, get data from that table.
d_echo("\nIndex: ".$index."\n");
d_echo(" UID: ".$result['UID']."\n");
d_echo(" SPID.SPOBJ: ".$result['sp-id'].".".$result['sp-obj']."\n");
d_echo(" If-Index: ".$result['ifindex']."\n");
d_echo(" Type: 1 - Policy-Map\n");
$result['label'] = $tblcbQosPolicyMapCfg['1.3.6.1.4.1.9.9.166.1.6.1.1.1'][$index];
if ($tblcbQosPolicyMapCfg['1.3.6.1.4.1.9.9.166.1.6.1.1.2'][$index] != "") {
$result['label'] .= " - ".$tblcbQosPolicyMapCfg['1.3.6.1.4.1.9.9.166.1.6.1.1.2'][$index];
}
d_echo(" Label: ".$result['label']."\n");
break;
case 2:
// Class-map, get data from that table.
d_echo("\nIndex: ".$index."\n");
d_echo(" UID: ".$result['UID']."\n");
d_echo(" SPID.SPOBJ: ".$result['sp-id'].".".$result['sp-obj']."\n");
d_echo(" If-Index: ".$result['ifindex']."\n");
d_echo(" Type: 2 - Class-Map\n");
$result['label'] = $tblcbQosClassMapCfg['1.3.6.1.4.1.9.9.166.1.7.1.1.1'][$index];
if($tblcbQosClassMapCfg['1.3.6.1.4.1.9.9.166.1.7.1.1.2'][$index] != "") {
$result['label'] .= " - ".$tblcbQosClassMapCfg['1.3.6.1.4.1.9.9.166.1.7.1.1.2'][$index];
}
d_echo(" Label: ".$result['label']."\n");
if ($tblcbQosClassMapCfg['1.3.6.1.4.1.9.9.166.1.7.1.1.3'][$index] == 2) {
$result['map-type'] = 'Match-All';
}
elseif ($tblcbQosClassMapCfg['1.3.6.1.4.1.9.9.166.1.7.1.1.3'][$index] == 3) {
$result['map-type'] = 'Match-Any';
}
else {
$result['map-type'] = 'None';
}
// Find a child, this will be a type 3
foreach ($tblcbQosObjects['1.3.6.1.4.1.9.9.166.1.5.1.1.4'][$spid] as $id => $value) {
if ($value == $result['sp-obj']) {
// We have our child, import the match
if ($tblcbQosObjects['1.3.6.1.4.1.9.9.166.1.5.1.1.3'][$spid][$id] == 3) {
$result['match'] = $result['map-type'].": ".$tblcbQosMatchStmtCfg['1.3.6.1.4.1.9.9.166.1.8.1.1.1'][$tblcbQosObjects['1.3.6.1.4.1.9.9.166.1.5.1.1.2'][$spid][$id]];
d_echo(" Match: ".$result['match']."\n");
}
}
}
break;
default:
continue 2;
}
$tblCBQOS[] = $result;
}
}
/*
* Ok, we have our 2 array's (Components and SNMP) now we need
* to compare and see what needs to be added/updated.
*
* Let's loop over the SNMP data to see if we need to ADD or UPDATE any components.
*/
foreach ($tblCBQOS as $key => $array) {
$component_key = false;
// Loop over our components to determine if the component exists, or we need to add it.
foreach ($components as $compid => $child) {
if ($child['UID'] === $array['UID']) {
$component_key = $compid;
}
}
if (!$component_key) {
// The component doesn't exist, we need to ADD it - ADD.
$new_component = $component->createComponent($device['device_id'],$module);
$component_key = key($new_component);
$components[$component_key] = array_merge($new_component[$component_key], $array);
echo "+";
}
else {
// The component does exist, merge the details in - UPDATE.
$components[$component_key] = array_merge($components[$component_key], $array);
echo ".";
}
}
/*
* Loop over the Component data to see if we need to DELETE any components.
*/
foreach ($components as $key => $array) {
// Guilty until proven innocent
$found = false;
foreach ($tblCBQOS as $k => $v) {
if ($array['UID'] == $v['UID']) {
// Yay, we found it...
$found = true;
}
}
if ($found === false) {
// The component has not been found. we should delete it.
echo "-";
$component->deleteComponent($key);
}
}
// Write the Components back to the DB.
$component->setComponentPrefs($device['device_id'],$components);
echo "\n";
} // End if not error
}
+72
View File
@@ -0,0 +1,72 @@
<?php
/*
* LibreNMS module to capture Cisco Class-Based QoS Details
*
* Copyright (c) 2015 Aaron Daniels <aaron@daniels.id.au>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
if ($device['os_group'] == "cisco") {
$module = 'Cisco-CBQOS';
require_once 'includes/component.php';
$component = new component();
$options['filter']['type'] = array('=',$module);
$options['filter']['disabled'] = array('=',0);
$options['filter']['ignore'] = array('=',0);
$components = $component->getComponents($device['device_id'],$options);
// We only care about our device id.
$components = $components[$device['device_id']];
// Only collect SNMP data if we have enabled components
if (count($components > 0)) {
// Let's gather the stats..
$tblcbQosClassMapStats = snmpwalk_array_num($device, '.1.3.6.1.4.1.9.9.166.1.15.1.1', 2);
// Loop through the components and extract the data.
foreach ($components as $key => $array) {
$type = $array['qos-type'];
// Get data from the class table.
if ($type == 2) {
// Let's make sure the rrd is setup for this class.
$filename = "port-".$array['ifindex']."-cbqos-".$array['sp-id']."-".$array['sp-obj'].".rrd";
$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename ($filename);
if (!file_exists ($rrd_filename)) {
rrdtool_create ($rrd_filename, " DS:postbits:COUNTER:600:0:U DS:bufferdrops:COUNTER:600:0:U DS:qosdrops:COUNTER:600:0:U" . $config['rrd_rra']);
}
// Let's print some debugging info.
d_echo("\n\nComponent: ".$key."\n");
d_echo(" Class-Map: ".$array['label']."\n");
d_echo(" SPID.SPOBJ: ".$array['sp-id'].".".$array['sp-obj']."\n");
d_echo(" PostBytes: 1.3.6.1.4.1.9.9.166.1.15.1.1.10.".$array['sp-id'].".".$array['sp-obj']." = ".$tblcbQosClassMapStats['1.3.6.1.4.1.9.9.166.1.15.1.1.10'][$array['sp-id']][$array['sp-obj']]."\n");
d_echo(" BufferDrops: 1.3.6.1.4.1.9.9.166.1.15.1.1.21.".$array['sp-id'].".".$array['sp-obj']." = ".$tblcbQosClassMapStats['1.3.6.1.4.1.9.9.166.1.15.1.1.21'][$array['sp-id']][$array['sp-obj']]."\n");
d_echo(" QOSDrops: 1.3.6.1.4.1.9.9.166.1.15.1.1.17.".$array['sp-id'].".".$array['sp-obj']." = ".$tblcbQosClassMapStats['1.3.6.1.4.1.9.9.166.1.15.1.1.17'][$array['sp-id']][$array['sp-obj']]."\n");
$rrd['postbytes'] = $tblcbQosClassMapStats['1.3.6.1.4.1.9.9.166.1.15.1.1.10'][$array['sp-id']][$array['sp-obj']];
$rrd['bufferdrops'] = $tblcbQosClassMapStats['1.3.6.1.4.1.9.9.166.1.15.1.1.21'][$array['sp-id']][$array['sp-obj']];
$rrd['qosdrops'] = $tblcbQosClassMapStats['1.3.6.1.4.1.9.9.166.1.15.1.1.17'][$array['sp-id']][$array['sp-obj']];
// Update rrd
rrdtool_update ($rrd_filename, $rrd);
// Clean-up after yourself!
unset($filename, $rrd_filename);
}
} // End foreach components
echo $module." ";
} // end if count components
// Clean-up after yourself!
unset($type, $components, $component, $options, $module);
}
+66
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;
}