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:
Jozef Pivarník
2019-05-21 03:56:19 +02:00
committed by Tony Murray
parent 4387ab052e
commit 2dc05ee501
10 changed files with 39031 additions and 30 deletions

View File

@@ -57,6 +57,7 @@ class ModuleTestHelper
'vlans' => ['ports', 'vlans'],
'vrf' => ['ports', 'vrf'],
'nac' => ['ports', 'nac'],
'cisco-mac-accounting' => ['ports', 'cisco-mac-accounting'],
];

View File

@@ -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

View File

@@ -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";

View File

@@ -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'].'&amp;stat='.$vars['graph'].'&amp;type=port_mac_acc_total&amp;sort='.$vars['sort'].'&amp;from='.$config['time']['day'].'&amp;to='.$config['time']['now']."&amp;width=150&amp;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'].'&amp;stat='.$vars['graph'].'&amp;type=port_mac_acc_total&amp;sort='.$vars['sort'].'&amp;from='.$config['time']['twoday'].'&amp;to='.$config['time']['now']."&amp;width=150&amp;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'].'&amp;type=port_mac_acc_total&amp;sort='.$vars['sort'].'&amp;stat='.$vars['graph'].'&amp;from='.$config['time']['week'].'&amp;to='.$config['time']['now']."&amp;width=150&amp;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'].'&amp;type=port_mac_acc_total&amp;sort='.$vars['sort'].'&amp;stat='.$vars['graph'].'&amp;from='.$config['time']['month'].'&amp;to='.$config['time']['now']."&amp;width=150&amp;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'].'&amp;type=port_mac_acc_total&amp;sort='.$vars['sort'].'&amp;stat='.$vars['graph'].'&amp;from='.$config['time']['year'].'&amp;to='.$config['time']['now']."&amp;width=150&amp;height=50' />
</a>
</div>

View File

@@ -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
View File

File diff suppressed because it is too large Load Diff

View File

File diff suppressed because it is too large Load Diff

View File

@@ -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

View File

File diff suppressed because it is too large Load Diff

View File

File diff suppressed because it is too large Load Diff