Fixes to Export CSV (#12830)

* fixes to port CSV Export

Signed-off-by: Patrik Forsberg <git@paddyonline.net>

* fix code-style issues

Signed-off-by: Patrik Forsberg <git@paddyonline.net>

Co-authored-by: Tony Murray <murraytony@gmail.com>
This commit is contained in:
Patrik Forsberg
2021-05-05 04:51:19 +02:00
committed by GitHub
parent 8135bd70d0
commit e40e1069d5
2 changed files with 23 additions and 10 deletions

View File

@@ -62,7 +62,7 @@ foreach ($menu_options as $option => $text) {
}
$displayLists .= '<div style="float: right;">';
$displayLists .= '<a href="csv.php/report=' . \LibreNMS\Util\Url::generate($vars, ['format' => '']) . '" title="Export as CSV" target="_blank" rel="noopener">Export CSV</a> | <a href="' . \LibreNMS\Util\Url::generate($vars) . '" title="Update the browser URL to reflect the search criteria.">Update URL</a> | ';
$displayLists .= '<a href="' . \LibreNMS\Util\Url::generate($vars, ['format' => '', 'page' => 'csv.php', 'report' => 'ports']) . '" title="Export as CSV" target="_blank" rel="noopener">Export CSV</a> | <a href="' . \LibreNMS\Util\Url::generate($vars) . '" title="Update the browser URL to reflect the search criteria.">Update URL</a> | ';
if (isset($vars['searchbar']) && $vars['searchbar'] == 'hide') {
$displayLists .= '<a href="' . \LibreNMS\Util\Url::generate($vars, ['searchbar' => '']) . '">Search</a>';

View File

@@ -3,20 +3,21 @@
$param = [];
if (! isset($vars['ignore'])) {
$vars['ignore'] = '0';
$vars['ignore'] = 0;
}
if (! isset($vars['disabled'])) {
$vars['disabled'] = '0';
$vars['disabled'] = 0;
}
if (! isset($vars['deleted'])) {
$vars['deleted'] = '0';
$vars['deleted'] = 0;
}
$where = '';
foreach ($vars as $var => $value) {
$value = trim($value);
if ($value != '') {
switch ($var) {
case 'hostname':
@@ -35,9 +36,20 @@ foreach ($vars as $var => $value) {
break;
case 'deleted':
if ($value == 1 || $value == 'yes') {
$where .= ' AND I.deleted = 1';
}
break;
case 'disabled':
if ($value == 1 || $value == 'yes') {
$where .= ' AND I.disabled = 1';
}
break;
case 'ignore':
if ($value == 1) {
$where .= ' AND (I.ignore = 1 OR D.ignore = 1) AND I.deleted = 0';
if ($value == 1 || $value == 'yes') {
$where .= ' AND (I.ignore = 1 OR D.ignore = 1)';
}
break;
@@ -61,22 +73,22 @@ foreach ($vars as $var => $value) {
break;
case 'errors':
if ($value == 1) {
if ($value == 1 || $value = 'yes') {
$where .= " AND (I.`ifInErrors_delta` > '0' OR I.`ifOutErrors_delta` > '0')";
}
break;
case 'state':
if ($value == 'down') {
$where .= 'AND I.ifAdminStatus = ? AND I.ifOperStatus = ?';
$where .= ' AND I.ifAdminStatus = ? AND I.ifOperStatus = ?';
$param[] = 'up';
$param[] = 'down';
} elseif ($value == 'up') {
$where .= "AND I.ifAdminStatus = ? AND I.ifOperStatus = ? AND I.ignore = '0' AND D.ignore='0' AND I.deleted='0'";
$where .= ' AND I.ifAdminStatus = ? AND I.ifOperStatus = ? AND I.ignore = 0 AND D.ignore = 0 AND I.deleted = 0';
$param[] = 'up';
$param[] = 'up';
} elseif ($value == 'admindown') {
$where .= 'AND I.ifAdminStatus = ? AND D.ignore = 0';
$where .= ' AND I.ifAdminStatus = ? AND D.ignore = 0';
$param[] = 'down';
}
break;
@@ -151,6 +163,7 @@ $csv[] = [
'Media',
'Description',
];
foreach ($ports as $port) {
if (port_permitted($port['port_id'], $port['device_id'])) {
$speed = \LibreNMS\Util\Number::formatSi($port['ifSpeed'], 2, 3, 'bps');