|
18 | 18 | );
|
19 | 19 |
|
20 | 20 | $weathermap_config = array (
|
| 21 | + 'show_interfaces' => 'all', |
21 | 22 | 'sort_if_by' => 'ifAlias',
|
22 | 23 | );
|
23 | 24 |
|
|
28 | 29 | 'ifName',
|
29 | 30 | );
|
30 | 31 |
|
| 32 | +$valid_show_interfaces = array ( |
| 33 | + 'all' => -1, |
| 34 | + 'any' => -1, |
| 35 | + '-1' => -1, |
| 36 | + # |
| 37 | + 'none' => 0, |
| 38 | + '0' => 0, |
| 39 | +); |
| 40 | + |
31 | 41 | // Try to find most appropriate librenms config file
|
32 | 42 | foreach ($config_file_paths as $path) {
|
33 | 43 | if (file_exists ($path)) {
|
|
65 | 75 | chdir('plugins/Weathermap');
|
66 | 76 | $librenms_found = TRUE;
|
67 | 77 |
|
68 |
| - /* Validate configuration */ |
| 78 | + /* Validate configuration, see defaults.inc.php for explaination */ |
69 | 79 | if (in_array ($config['plugins']['Weathermap']['sort_if_by'], $valid_sort_if_by))
|
70 | 80 | $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']; |
71 | 86 | }
|
72 | 87 | else {
|
73 | 88 | $librenms_found = FALSE;
|
@@ -286,7 +301,7 @@ function applyDSFilterChange(objForm) {
|
286 | 301 |
|
287 | 302 | //$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 ";
|
288 | 303 |
|
289 |
| - $host_id = -1; |
| 304 | + $host_id = $weathermap_config['show_interfaces']; |
290 | 305 |
|
291 | 306 | $overlib = true;
|
292 | 307 | $aggregate = false;
|
@@ -336,27 +351,21 @@ function applyDSFilterChange(objForm) {
|
336 | 351 | print '</form><div class="listcontainer"><ul id="dslist">';
|
337 | 352 |
|
338 | 353 | /*
|
339 |
| - * Query interfaces... |
| 354 | + * Query interfaces (if we should)... |
340 | 355 | */
|
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"; |
354 | 359 |
|
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 | + } |
358 | 364 |
|
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 | + } |
360 | 369 |
|
361 | 370 | $i=0;
|
362 | 371 | if( mysqli_num_rows($result) > 0 )
|
|
0 commit comments