mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Fixed Cisco MAC accounting discovery, polling and HTML templates. (#10158)
* Fix Cisco MAC acounting discovery, polling and HTML templates. * Remove empty code. * Provide test data for cisco-mac-accounting module. * Added module test dependency.
This commit is contained in:
committed by
Tony Murray
parent
4387ab052e
commit
2dc05ee501
@@ -57,6 +57,7 @@ class ModuleTestHelper
|
||||
'vlans' => ['ports', 'vlans'],
|
||||
'vrf' => ['ports', 'vrf'],
|
||||
'nac' => ['ports', 'nac'],
|
||||
'cisco-mac-accounting' => ['ports', 'cisco-mac-accounting'],
|
||||
];
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ if ($device['os_group'] == 'cisco') {
|
||||
list($oid) = explode(' ', $data);
|
||||
$oid = str_replace('.1.3.6.1.4.1.9.9.84.1.2.1.1.4.', '', $oid);
|
||||
list($if, $direction, $a_a, $a_b, $a_c, $a_d, $a_e, $a_f) = explode('.', $oid);
|
||||
$oid = "$a_a.$a_b.$a_c.$a_d.$a_e.$a_f";
|
||||
unset($interface);
|
||||
$interface = dbFetchRow('SELECT * FROM `ports` WHERE `device_id` = ? AND `ifIndex` = ?', array($device['device_id'], $if));
|
||||
$ah_a = zeropad(dechex($a_a));
|
||||
@@ -16,27 +15,15 @@ if ($device['os_group'] == 'cisco') {
|
||||
$ah_d = zeropad(dechex($a_d));
|
||||
$ah_e = zeropad(dechex($a_e));
|
||||
$ah_f = zeropad(dechex($a_f));
|
||||
$mac = "$ah_a:$ah_b:$ah_c:$ah_d:$ah_e:$ah_f";
|
||||
$mac_cisco = "$ah_a$ah_b.$ah_c$ah_d.$ah_e$ah_f";
|
||||
$mac_cisco = $mac_table[$if][$mac]['ciscomac'];
|
||||
$clean_mac = $mac_table[$if][$mac]['cleanmac'];
|
||||
$ip = $mac_table[$if][$mac]['ip'];
|
||||
if ($ip && $interface) {
|
||||
$new_mac = str_replace(':', '', $mac);
|
||||
// echo($interface['ifDescr'] . " ($if) -> $mac ($oid) -> $ip");
|
||||
if (dbFetchCell('SELECT COUNT(*) from mac_accounting WHERE port_id = ? AND mac = ?', array($interface['port_id'], $clean_mac))) {
|
||||
// $sql = "UPDATE `mac_accounting` SET `mac` = '$clean_mac' WHERE port_id = '".$interface['port_id']."' AND `mac` = '$clean_mac'";
|
||||
// mysql_query($sql);
|
||||
// if (mysql_affected_rows()) { echo(" UPDATED!"); }
|
||||
// echo($sql);
|
||||
$mac = "$ah_a$ah_b$ah_c$ah_d$ah_e$ah_f";
|
||||
|
||||
if ($interface) {
|
||||
if (dbFetchCell('SELECT COUNT(*) from mac_accounting WHERE port_id = ? AND mac = ?', array($interface['port_id'], $mac))) {
|
||||
echo '.';
|
||||
} else {
|
||||
// echo(" Not Exists!");
|
||||
dbInsert(array('port_id' => $interface['port_id'], 'mac' => $clean_mac), 'mac_accounting');
|
||||
dbInsert(array('port_id' => $interface['port_id'], 'mac' => $mac), 'mac_accounting');
|
||||
echo '+';
|
||||
}
|
||||
|
||||
// echo("\n");
|
||||
}
|
||||
}//end foreach
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ if ($stat == 'pkts') {
|
||||
} elseif ($sort == 'out') {
|
||||
$sort = 'cipMacHCSwitchedPkts_output_rate';
|
||||
} else {
|
||||
$sort = 'bps';
|
||||
$sort = 'bps_in';
|
||||
}
|
||||
} elseif ($stat == 'bits') {
|
||||
$units = 'bps';
|
||||
@@ -40,7 +40,7 @@ if ($stat == 'pkts') {
|
||||
} elseif ($sort == 'out') {
|
||||
$sort = 'cipMacHCSwitchedBytes_output_rate';
|
||||
} else {
|
||||
$sort = 'bps';
|
||||
$sort = 'bps_in';
|
||||
}
|
||||
}//end if
|
||||
|
||||
@@ -107,10 +107,10 @@ foreach ($accs as $acc) {
|
||||
$rrd_options .= ' VDEF:tot'.$this_id.'=octets'.$this_id.',TOTAL';
|
||||
$rrd_options .= ' AREA:inB'.$this_id.'#'.$colour.":'".$descr."':STACK";
|
||||
if ($rrd_optionsb) {
|
||||
$stack = 'STACK';
|
||||
$stack = ':STACK';
|
||||
}
|
||||
|
||||
$rrd_optionsb .= ' AREA:outB'.$this_id.'#'.$colour."::$stack";
|
||||
$rrd_optionsb .= ' AREA:outB'.$this_id.'#'.$colour.":''$stack";
|
||||
$rrd_options .= ' GPRINT:inB'.$this_id.":LAST:%6.2lf%s$units";
|
||||
$rrd_options .= ' GPRINT:inB'.$this_id.":MAX:%6.2lf%s$units";
|
||||
$rrd_options .= ' GPRINT:totin'.$this_id.":%6.2lf%s$unit";
|
||||
|
||||
@@ -47,32 +47,32 @@ if ($vars['subview'] == 'top10') {
|
||||
<div style='margin: 0px 10px 5px 0px; padding:5px; background: #e5e5e5;'>
|
||||
<span class=device-head>Day</span><br />
|
||||
|
||||
<a href='".generate_url($link_array, array('view' => 'macaccounting', 'subview' => 'top10', 'graph' => $vars['graph'], 'sort' => $vars['sort'], 'period' => 'day'))."'>
|
||||
<a href='".generate_url($link_array, array('view' => 'macaccounting', 'subview' => 'top10', 'graph' => $vars['graph'], 'sort' => $vars['sort'], 'period' => '1d'))."'>
|
||||
|
||||
<img style='border: #5e5e5e 2px;' valign=middle src='graph.php?id=".$port['port_id'].'&stat='.$vars['graph'].'&type=port_mac_acc_total&sort='.$vars['sort'].'&from='.$config['time']['day'].'&to='.$config['time']['now']."&width=150&height=50' />
|
||||
</a>
|
||||
</div>
|
||||
<div style='margin: 0px 10px 5px 0px; padding:5px; background: #e5e5e5;'>
|
||||
<span class=device-head>Two Day</span><br />
|
||||
<a href='".generate_url($link_array, array('view' => 'macaccounting', 'subview' => 'top10', 'graph' => $vars['graph'], 'sort' => $vars['sort'], 'period' => 'twoday'))."/'>
|
||||
<a href='".generate_url($link_array, array('view' => 'macaccounting', 'subview' => 'top10', 'graph' => $vars['graph'], 'sort' => $vars['sort'], 'period' => '2d'))."/'>
|
||||
<img style='border: #5e5e5e 2px;' valign=middle src='graph.php?id=".$port['port_id'].'&stat='.$vars['graph'].'&type=port_mac_acc_total&sort='.$vars['sort'].'&from='.$config['time']['twoday'].'&to='.$config['time']['now']."&width=150&height=50' />
|
||||
</a>
|
||||
</div>
|
||||
<div style='margin: 0px 10px 5px 0px; padding:5px; background: #e5e5e5;'>
|
||||
<span class=device-head>Week</span><br />
|
||||
<a href='".generate_url($link_array, array('view' => 'macaccounting', 'subview' => 'top10', 'graph' => $vars['graph'], 'sort' => $vars['sort'], 'period' => 'week'))."/'>
|
||||
<a href='".generate_url($link_array, array('view' => 'macaccounting', 'subview' => 'top10', 'graph' => $vars['graph'], 'sort' => $vars['sort'], 'period' => '1w'))."/'>
|
||||
<img style='border: #5e5e5e 2px;' valign=middle src='graph.php?id=".$port['port_id'].'&type=port_mac_acc_total&sort='.$vars['sort'].'&stat='.$vars['graph'].'&from='.$config['time']['week'].'&to='.$config['time']['now']."&width=150&height=50' />
|
||||
</a>
|
||||
</div>
|
||||
<div style='margin: 0px 10px 5px 0px; padding:5px; background: #e5e5e5;'>
|
||||
<span class=device-head>Month</span><br />
|
||||
<a href='".generate_url($link_array, array('view' => 'macaccounting', 'subview' => 'top10', 'graph' => $vars['graph'], 'sort' => $vars['sort'], 'period' => 'month'))."/'>
|
||||
<a href='".generate_url($link_array, array('view' => 'macaccounting', 'subview' => 'top10', 'graph' => $vars['graph'], 'sort' => $vars['sort'], 'period' => '1m'))."/'>
|
||||
<img style='border: #5e5e5e 2px;' valign=middle src='graph.php?id=".$port['port_id'].'&type=port_mac_acc_total&sort='.$vars['sort'].'&stat='.$vars['graph'].'&from='.$config['time']['month'].'&to='.$config['time']['now']."&width=150&height=50' />
|
||||
</a>
|
||||
</div>
|
||||
<div style='margin: 0px 10px 5px 0px; padding:5px; background: #e5e5e5;'>
|
||||
<span class=device-head>Year</span><br />
|
||||
<a href='".generate_url($link_array, array('view' => 'macaccounting', 'subview' => 'top10', 'graph' => $vars['graph'], 'sort' => $vars['sort'], 'period' => 'year'))."/'>
|
||||
<a href='".generate_url($link_array, array('view' => 'macaccounting', 'subview' => 'top10', 'graph' => $vars['graph'], 'sort' => $vars['sort'], 'period' => '1y'))."/'>
|
||||
<img style='border: #5e5e5e 2px;' valign=middle src='graph.php?id=".$port['port_id'].'&type=port_mac_acc_total&sort='.$vars['sort'].'&stat='.$vars['graph'].'&from='.$config['time']['year'].'&to='.$config['time']['now']."&width=150&height=50' />
|
||||
</a>
|
||||
</div>
|
||||
|
||||
@@ -12,11 +12,31 @@ if ($device['os_group'] == 'cisco') {
|
||||
);
|
||||
$cip_array = array();
|
||||
|
||||
foreach ($cip_oids as $oid) {
|
||||
foreach (array_merge($cip_oids, array('cipMacSwitchedBytes', 'cipMacSwitchedPkts')) as $oid) {
|
||||
echo "$oid ";
|
||||
$cip_array = snmpwalk_cache_cip($device, $oid, $cip_array, 'CISCO-IP-STAT-MIB');
|
||||
}
|
||||
|
||||
// Normalize cip_array
|
||||
$cip_array = array_map(function ($entries) {
|
||||
return array_map(function ($entry) {
|
||||
$new_entry = array();
|
||||
|
||||
foreach (array('Bytes', 'Pkts') as $unit) {
|
||||
$returned_oid = (array_key_exists('cipMacHCSwitched'.$unit, $entry)) ? 'cipMacHCSwitched' : 'cipMacSwitched';
|
||||
$new_value = array();
|
||||
|
||||
foreach ($entry[$returned_oid.$unit] as $key => $value) {
|
||||
$new_value[$key] = intval($value);
|
||||
}
|
||||
|
||||
$new_entry['cipMacHCSwitched'.$unit] = $new_value;
|
||||
}
|
||||
|
||||
return $new_entry;
|
||||
}, $entries);
|
||||
}, $cip_array);
|
||||
|
||||
$polled = time();
|
||||
|
||||
$mac_entries = 0;
|
||||
@@ -62,7 +82,7 @@ if ($device['os_group'] == 'cisco') {
|
||||
d_echo("\n" . $acc['hostname'] . ' ' . $acc['ifDescr'] . " $mac -> $b_in:$b_out:$p_in:$p_out ");
|
||||
|
||||
$rrd_name = array('cip', $ifIndex, $mac);
|
||||
$rrd_dev = RrdDefinition::make()
|
||||
$rrd_def = RrdDefinition::make()
|
||||
->addDataset('IN', 'COUNTER', 0, 12500000000)
|
||||
->addDataset('OUT', 'COUNTER', 0, 12500000000)
|
||||
->addDataset('PIN', 'COUNTER', 0, 12500000000)
|
||||
|
||||
8612
tests/data/ios.json
Normal file
8612
tests/data/ios.json
Normal file
File diff suppressed because it is too large
Load Diff
25370
tests/data/iosxr.json
25370
tests/data/iosxr.json
File diff suppressed because it is too large
Load Diff
@@ -85,3 +85,10 @@ vrf:
|
||||
wireless:
|
||||
wireless_sensors:
|
||||
excluded_fields: [device_id, sensor_id, access_point_id, lastupdate]
|
||||
cisco-mac-accounting:
|
||||
mac_accounting:
|
||||
excluded_fields: [ma_id, port_id, poll_time, poll_prev, poll_period, cipMacHCSwitchedBytes_input_rate, cipMacHCSwitchedBytes_output_rate, cipMacHCSwitchedPkts_input_rate, cipMacHCSwitchedPkts_output_rate]
|
||||
joins:
|
||||
- { left: mac_accounting.port_id, right: ports.port_id, select: [ifIndex] }
|
||||
custom_where: WHERE ports.device_id=?
|
||||
order_by: ports.ifIndex, mac
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user