From 6c5566537d0136a37a6e190bf6af403f39c4a6a7 Mon Sep 17 00:00:00 2001 From: Diego Canton de Brito Date: Mon, 5 Oct 2020 10:18:32 -0300 Subject: [PATCH 1/2] Improvements in the display and search of data. 1) Displays "sysname"; 2) Make port names and devices capitalized, making the search easier; --- data-pick.php | 700 +++++++++++++++++++++++++------------------------- 1 file changed, 351 insertions(+), 349 deletions(-) diff --git a/data-pick.php b/data-pick.php index b995691d..4419b089 100755 --- a/data-pick.php +++ b/data-pick.php @@ -7,105 +7,105 @@ $weathermap_config = array ( - 'show_interfaces' => 'all', - 'sort_if_by' => 'ifAlias', + 'show_interfaces' => 'all', + 'sort_if_by' => 'ifAlias', ); $valid_sort_if_by = array ( - 'ifAlias', - 'ifDescr', - 'ifIndex', - 'ifName', + 'ifAlias', + 'ifDescr', + 'ifIndex', + 'ifName', ); $valid_show_interfaces = array ( - 'all' => -1, - 'any' => -1, - '-1' => -1, - # - 'none' => 0, - '0' => 0, + 'all' => -1, + 'any' => -1, + '-1' => -1, + # + 'none' => 0, + '0' => 0, ); - /* - * Include the LibreNMS config, so we know about the database. - * - * Include config first to get install dir, then load defaults and config - * again to get full set of config values. - */ - /* Load Weathermap config defaults, see file for description. */ + /* + * Include the LibreNMS config, so we know about the database. + * + * Include config first to get install dir, then load defaults and config + * again to get full set of config values. + */ + /* Load Weathermap config defaults, see file for description. */ $init_modules = ['web', 'auth']; require $librenms_base . '/includes/init.php'; - if (!Auth::check()) { - header('Location: /'); - exit; - } + if (!Auth::check()) { + header('Location: /'); + exit; + } - chdir($librenms_base . '/plugins/Weathermap'); - $librenms_found = true; + chdir($librenms_base . '/plugins/Weathermap'); + $librenms_found = true; - /* Validate configuration, see defaults.inc.php for explaination */ - if (in_array ($config['plugins']['Weathermap']['sort_if_by'], $valid_sort_if_by)) - $weathermap_config['sort_if_by'] = $config['plugins']['Weathermap']['sort_if_by']; + /* Validate configuration, see defaults.inc.php for explaination */ + if (in_array ($config['plugins']['Weathermap']['sort_if_by'], $valid_sort_if_by)) + $weathermap_config['sort_if_by'] = $config['plugins']['Weathermap']['sort_if_by']; - if (in_array ($config['plugins']['Weathermap']['show_interfaces'], $valid_show_interfaces)) - $weathermap_config['show_interfaces'] = $valid_show_interfaces[$config['plugins']['Weathermap']['show_interfaces']]; - elseif (validate_device_id ($config['plugins']['Weathermap']['show_interfaces'])) - $weathermap_config['show_interfaces'] = $config['plugins']['Weathermap']['show_interfaces']; + if (in_array ($config['plugins']['Weathermap']['show_interfaces'], $valid_show_interfaces)) + $weathermap_config['show_interfaces'] = $valid_show_interfaces[$config['plugins']['Weathermap']['show_interfaces']]; + elseif (validate_device_id ($config['plugins']['Weathermap']['show_interfaces'])) + $weathermap_config['show_interfaces'] = $config['plugins']['Weathermap']['show_interfaces']; // ****************************************** function js_escape($str) { - $str = str_replace('\\', '\\\\', $str); - $str = str_replace("'", "\\\'", $str); + $str = str_replace('\\', '\\\\', $str); + $str = str_replace("'", "\\\'", $str); - $str = "'".$str."'"; + $str = "'".$str."'"; - return($str); + return($str); } if(isset($_REQUEST['command']) && $_REQUEST["command"]=='link_step2') { - $dataid = intval($_REQUEST['dataid']); + $dataid = intval($_REQUEST['dataid']); ?> - + This window should disappear in a moment. - - + + + Pick a data source value('device_id'); - if ($node1_id) - $host_id = $node1_id; - } - - // Link query - $hosts = \App\Models\Device::orderBy('hostname')->get(['device_id', 'hostname']); + $host_id = $weathermap_config['show_interfaces']; + + $overlib = true; + $aggregate = false; + + if(isset($_REQUEST['aggregate'])) $aggregate = ( $_REQUEST['aggregate']==0 ? false : true); + if(isset($_REQUEST['overlib'])) $overlib= ( $_REQUEST['overlib']==0 ? false : true); + + /* Explicit device_id given? */ + if (isset ($_REQUEST['host_id']) and !empty ($_REQUEST['host_id'])) + { + $host_id = intval ($_REQUEST['host_id']); + } + + /* If the editor gave us the links source node name, try to find the device_id + * so we can present the user with the interfaces of this particular device. */ + if (isset ($_REQUEST['node1']) and !empty ($_REQUEST['node1'])) + { + $node1 = strtolower ($_REQUEST['node1']); + $node1_id = \App\Models\Device::where('hostname', 'like', "%$node1%")->value('device_id'); + if ($node1_id) + $host_id = $node1_id; + } + + // Link query + $hosts = \App\Models\Device::orderBy('hostname')->get(['device_id', 'hostname', 'sysname']); ?>

Pick a data source:

-isNotEmpty()) { - print 'Host:
'; + print 'Host:
'; } - print ''; - print '
'; - print '
'; - print ' '; + print ''; + print '
'; + print '
'; + print ' '; - print '