mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
feature: Support fdb table on generic devices (#6902)
* feature: support fdb table on generic devices refactored code to use snmpwalk_group refactored ajax table code to use joins and reduce extra queries add indexes for device_id and port_id, drop primary index Make all columns sortable Fix a few other small issues * Add index for vlan_id since that field can be searched by the user * fix whitespace * Rename 197.sql to 198.sql * set row count for table
This commit is contained in:
committed by
Neil Lathwood
parent
bda5a4343e
commit
e8dd72e8db
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
$param = array();
|
||||
|
||||
$sql .= ' FROM `ports_fdb` AS F, `ports` AS P, `devices` AS D, `vlans` as V ';
|
||||
$sql = ' FROM `ports_fdb` AS `F`';
|
||||
|
||||
if (is_admin() === false && is_read() === false) {
|
||||
$sql .= ' LEFT JOIN `devices_perms` AS `DP` ON `D`.`device_id` = `DP`.`device_id`';
|
||||
@@ -9,15 +9,19 @@ if (is_admin() === false && is_read() === false) {
|
||||
$param[] = $_SESSION['user_id'];
|
||||
}
|
||||
|
||||
$sql .= " WHERE F.port_id = P.port_id AND P.device_id = D.device_id AND F.vlan_id = V.vlan_id $where ";
|
||||
$sql .= " LEFT JOIN `ports` AS `P` ON `F`.`port_id`=`P`.`port_id`";
|
||||
$sql .= " LEFT JOIN `devices` AS `D` ON `F`.`device_id`=`D`.`device_id`";
|
||||
$sql .= " LEFT JOIN `vlans` AS `V` ON `F`.`vlan_id`=`V`.`vlan_id`";
|
||||
$sql .= " LEFT JOIN `ipv4_mac` ON `F`.`mac_address`=`ipv4_mac`.`mac_address`";
|
||||
|
||||
$sql .= " WHERE 1";
|
||||
if (is_numeric($_POST['device_id'])) {
|
||||
$sql .= ' AND P.device_id = ?';
|
||||
$sql .= ' AND `F`.`device_id`=?';
|
||||
$param[] = $_POST['device_id'];
|
||||
}
|
||||
|
||||
if (is_numeric($_POST['port_id'])) {
|
||||
$sql .= ' AND P.port_id = ?';
|
||||
$sql .= ' AND `F`.`port_id`=?';
|
||||
$param[] = $_POST['port_id'];
|
||||
}
|
||||
|
||||
@@ -26,13 +30,13 @@ if (isset($_POST['searchPhrase']) && !empty($_POST['searchPhrase'])) {
|
||||
$mac_search = '%'.str_replace(array(':', ' ', '-', '.', '0x'), '', mres($_POST['searchPhrase'])).'%';
|
||||
|
||||
if (isset($_POST['searchby']) && $_POST['searchby'] == 'vlan') {
|
||||
$sql .= ' AND `vlan_vlan` LIKE ?';
|
||||
$sql .= ' AND `V`.`vlan_vlan` = ?';
|
||||
$param[] = $vlan_search;
|
||||
} elseif (isset($_POST['searchby']) && $_POST['searchby'] == 'mac') {
|
||||
$sql .= ' AND `mac_address` LIKE ?';
|
||||
$sql .= ' AND `F`.`mac_address` LIKE ?';
|
||||
$param[] = $mac_search;
|
||||
} else {
|
||||
$sql .= ' AND (`vlan_vlan` LIKE ? OR `mac_address` LIKE ?)';
|
||||
$sql .= ' AND (`V`.`vlan_vlan` = ? OR `F`.`mac_address` LIKE ?)';
|
||||
$param[] = $vlan_search;
|
||||
$param[] = $mac_search;
|
||||
}
|
||||
@@ -46,7 +50,7 @@ if (empty($total)) {
|
||||
}
|
||||
|
||||
if (!isset($sort) || empty($sort)) {
|
||||
$sort = '`hostname` ASC';
|
||||
$sort = '`F`.`port_id` ASC';
|
||||
}
|
||||
|
||||
$sql .= " ORDER BY $sort";
|
||||
@@ -60,25 +64,23 @@ if ($rowCount != -1) {
|
||||
$sql .= " LIMIT $limit_low,$limit_high";
|
||||
}
|
||||
|
||||
$sql = "SELECT *,`P`.`ifDescr` AS `interface`,`V`.`vlan_vlan` $sql";
|
||||
$sql = "SELECT `P`.*, `ifDescr` AS `interface`, `F`.`mac_address`, `ipv4_mac`.`ipv4_address`, `V`.`vlan_vlan` as `vlan`, `D`.`hostname` AS `device` $sql";
|
||||
|
||||
foreach (dbFetchRows($sql, $param) as $entry) {
|
||||
$entry = cleanPort($entry);
|
||||
if (!$ignore) {
|
||||
if ($entry['ifInErrors'] > 0 || $entry['ifOutErrors'] > 0) {
|
||||
$error_img = generate_port_link($entry, "<i class='fa fa-flag fa-lg' style='color:red' aria-hidden='true'></i>", port_errors);
|
||||
$error_img = generate_port_link($entry, "<i class='fa fa-flag fa-lg' style='color:red' aria-hidden='true'></i>", 'port_errors');
|
||||
} else {
|
||||
$error_img = '';
|
||||
}
|
||||
|
||||
$fdb_host = dbFetchRow('SELECT * FROM ports_fdb AS F, ipv4_mac AS M WHERE F.mac_address = ? AND M.mac_address = F.mac_address', array($entry['mac_address']));
|
||||
$response[] = array(
|
||||
'os' => $entry['os'],
|
||||
'device' => generate_device_link(device_by_id_cache($entry['device_id'])),
|
||||
'mac_address' => formatMac($entry['mac_address']),
|
||||
'ipv4_address' => $fdb_host['ipv4_address'],
|
||||
'hostname' => generate_device_link($entry),
|
||||
'ipv4_address' => $entry['ipv4_address'],
|
||||
'interface' => generate_port_link($entry, makeshortif(fixifname(cleanPort($entry['label'])))).' '.$error_img,
|
||||
'vlan' => $entry['vlan_vlan'],
|
||||
'vlan' => $entry['vlan'],
|
||||
);
|
||||
}//end if
|
||||
|
||||
|
||||
Reference in New Issue
Block a user