Skip to content

Commit 7cbc709

Browse files
committed
Allow user to configure which ports are shown in data-picker on load.
By default all interfaces of all devices are loaded and listed when opening the data-picker. In large setups this will cause high loading times every time the data-picker is loaded. With the following option this behvaiour can be changed, valid values are: 'all', 'any', '-1' Show all ports (default) 'none', '0' Don't load any ports. <integer> >= 0 Show port of libreNMS $device_id $config['plugins']['Weathermap']['show_interfaces'] = 'all'; Signed-off-by: Maximilian Wilhelm <[email protected]>
1 parent d406fae commit 7cbc709

File tree

2 files changed

+41
-20
lines changed

2 files changed

+41
-20
lines changed

data-pick.php

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
);
1919

2020
$weathermap_config = array (
21+
'show_interfaces' => 'all',
2122
'sort_if_by' => 'ifAlias',
2223
);
2324

@@ -28,6 +29,15 @@
2829
'ifName',
2930
);
3031

32+
$valid_show_interfaces = array (
33+
'all' => -1,
34+
'any' => -1,
35+
'-1' => -1,
36+
#
37+
'none' => 0,
38+
'0' => 0,
39+
);
40+
3141
// Try to find most appropriate librenms config file
3242
foreach ($config_file_paths as $path) {
3343
if (file_exists ($path)) {
@@ -65,9 +75,14 @@
6575
chdir('plugins/Weathermap');
6676
$librenms_found = TRUE;
6777

68-
/* Validate configuration */
78+
/* Validate configuration, see defaults.inc.php for explaination */
6979
if (in_array ($config['plugins']['Weathermap']['sort_if_by'], $valid_sort_if_by))
7080
$weathermap_config['sort_if_by'] = $config['plugins']['Weathermap']['sort_if_by'];
81+
82+
if (in_array ($config['plugins']['Weathermap']['show_interfaces'], $valid_show_interfaces))
83+
$weathermap_config['show_interfaces'] = $valid_show_interfaces[$config['plugins']['Weathermap']['show_interfaces']];
84+
elseif (validate_device_id ($config['plugins']['Weathermap']['show_interfaces']))
85+
$weathermap_config['show_interfaces'] = $config['plugins']['Weathermap']['show_interfaces'];
7186
}
7287
else {
7388
$librenms_found = FALSE;
@@ -286,7 +301,7 @@ function applyDSFilterChange(objForm) {
286301

287302
//$SQL_picklist = "select data_local.host_id, data_template_data.local_data_id, data_template_data.name_cache, data_template_data.active, data_template_data.data_source_path from data_local,data_template_data,data_input,data_template where data_local.id=data_template_data.local_data_id and data_input.id=data_template_data.data_input_id and data_local.data_template_id=data_template.id ";
288303

289-
$host_id = -1;
304+
$host_id = $weathermap_config['show_interfaces'];
290305

291306
$overlib = true;
292307
$aggregate = false;
@@ -336,27 +351,21 @@ function applyDSFilterChange(objForm) {
336351
print '</form><div class="listcontainer"><ul id="dslist">';
337352

338353
/*
339-
* Query interfaces...
354+
* Query interfaces (if we should)...
340355
*/
341-
$query = "SELECT devices.device_id,hostname,ports.port_id,ports.ifAlias,ports.ifIndex,ports.ifDescr,ports.deleted FROM devices LEFT JOIN ports ON devices.device_id=ports.device_id WHERE ports.disabled=0";
342-
343-
/* ...of specific host/device? */
344-
if($host_id > 0) {
345-
$query .= " AND devices.device_id='$host_id'";
346-
}
347-
348-
$sort_if_by = $config['plugins']['Weathermap']['sort_if_by'];
349-
if (in_array ($sort_if_by, $valid_sort_if_by)) {
350-
$query .= " ORDER BY hostname,ports.$sort_if_by";
351-
} else {
352-
$query .= " ORDER BY hostname,ports.ifAlias";
353-
}
356+
$result = Null;
357+
if ($host_id != 0) {
358+
$query = "SELECT devices.device_id,hostname,ports.port_id,ports.ifAlias,ports.ifIndex,ports.ifDescr,ports.deleted FROM devices LEFT JOIN ports ON devices.device_id=ports.device_id WHERE ports.disabled=0";
354359

355-
/* ...in specific order? */
356-
$query .= " ORDER BY hostname,ports." . $weathermap_config['sort_if_by'];
357-
$result = mysqli_query($link,$query);
360+
/* ...of specific host/device? */
361+
if($host_id > 0) {
362+
$query .= " AND devices.device_id='$host_id'";
363+
}
358364

359-
// print $SQL_picklist;
365+
/* ...in specific order? */
366+
$query .= " ORDER BY hostname,ports." . $weathermap_config['sort_if_by'];
367+
$result = mysqli_query($link,$query);
368+
}
360369

361370
$i=0;
362371
if( mysqli_num_rows($result) > 0 )

defaults.inc.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,16 @@
1515
*/
1616
$config['plugins']['Weathermap']['sort_if_by'] = 'ifAlias';
1717

18+
19+
/* By default all interfaces of all devices are loaded and listed when
20+
* opening the data-picker. In large setups this will cause high loading
21+
* times every time the data-picker is loaded. With the following option
22+
* this behvaiour can be changed, valid values are:
23+
*
24+
* 'all', 'any', '-1' Show all ports (default)
25+
* 'none', '0' Don't load any ports.
26+
* <integer> >= 0 Show port of libreNMS $device_id
27+
*
28+
*/
29+
$config['plugins']['Weathermap']['show_interfaces'] = 'all';
1830
?>

0 commit comments

Comments
 (0)