Show port description and dns name in FDB table (#9370)

- Added Port Description field to FDB Table
- Added DNS Name field to FDB Table
- Fixed sorting by port in FDB Table

DO NOT DELETE THIS TEXT

#### Please note

> Please read this information carefully. You can run `./scripts/pre-commit.php` to check your code before submitting.

- [x] Have you followed our [code guidelines?](http://docs.librenms.org/Developing/Code-Guidelines/)

#### Testers

If you would like to test this pull request then please run: `./scripts/github-apply <pr_id>`, i.e `./scripts/github-apply 5926`
After you are done testing, you can remove the changes with `./scripts/github-remove`.  If there are schema changes, you can ask on discord how to revert.
This commit is contained in:
Jellyfrog
2018-11-08 23:08:39 +01:00
committed by Neil Lathwood
parent d736adc289
commit 40a84b5131
2 changed files with 10 additions and 6 deletions

View File

@@ -6,7 +6,8 @@ $param = array();
$select = "SELECT `F`.`port_id` AS `port_id`, `F`.`device_id`, `ifInErrors`, `ifOutErrors`, `ifOperStatus`,";
$select .= " `ifAdminStatus`, `ifAlias`, `ifDescr`, `mac_address`, `V`.`vlan_vlan` AS `vlan`,";
$select .= " `hostname`, `hostname` AS `device` , group_concat(`M`.`ipv4_address` SEPARATOR ', ') AS `ipv4_address`";
$select .= " `hostname`, `hostname` AS `device` , group_concat(`M`.`ipv4_address` SEPARATOR ', ') AS `ipv4_address`,";
$select .= " `P`.`ifDescr` AS `interface`";
$sql = " FROM `ports_fdb` AS `F`";
$sql .= " LEFT JOIN `devices` AS `D` USING(`device_id`)";
@@ -56,15 +57,16 @@ if (isset($vars['searchPhrase']) && !empty($vars['searchPhrase'])) {
$desc_search = '%' . $search . '%';
$where .= ' AND `P`.`ifAlias` LIKE ?';
$param[] = $desc_search;
} elseif ((isset($vars['searchby']) && $vars['searchby'] == 'mac') ||
(!is_numeric($search) || $search > 4096)
) {
} elseif (isset($vars['searchby']) && $vars['searchby'] == 'mac') {
$where .= ' AND `F`.`mac_address` LIKE ?';
$param[] = $mac_search;
} else {
$where .= ' AND (`V`.`vlan_vlan` = ? OR `F`.`mac_address` LIKE ?)';
$sql .= " LEFT JOIN `ipv4_mac` AS `M` USING (`mac_address`)";
$where .= ' AND (`V`.`vlan_vlan` = ? OR `F`.`mac_address` LIKE ? OR `P`.`ifAlias` LIKE ? OR `M`.`ipv4_address` LIKE ?)';
$param[] = (int)$search;
$param[] = $mac_search;
$param[] = '%' . $search . '%';
$param[] = '%' . gethostbyname(trim($vars['searchPhrase'])) . '%';
}
}
@@ -72,7 +74,7 @@ $total = (int)dbFetchCell("SELECT COUNT(*) $sql $where", $param);
// Don't use ipv4_mac in count it will inflate the rows unless we aggregate it
// Except for ip search.
if ($vars['searchby'] != 'ip' && $vars['searchby'] != 'dnsname') {
if (empty($vars['searchPhrase']) || isset($vars['searchby']) && $vars['searchby'] != 'ip' && $vars['searchby'] != 'dnsname') {
$sql .= " LEFT JOIN `ipv4_mac` AS `M` USING (`mac_address`)";
}
$sql .= $where;

View File

@@ -7,7 +7,9 @@ $no_refresh = true;
<th data-column-id="mac_address">MAC address</th>
<th data-column-id="ipv4_address">IPv4 Address</th>
<th data-column-id="interface">Port</th>
<th data-column-id="description">Description</th>
<th data-column-id="vlan">Vlan</th>
<th data-column-id="dnsname" data-visible="false">DNS Name</th>
</tr>
</thead>
</table>