webui: display sysnames/hostnames instead of ip addresses #4155

When a network is mostly assigned using RFC 1918, DNS resolution is not useful
and devices are displayed by IP address.

When $config['force_ip_to_sysname'] is enabled, use ip_to_sysname() to display
the device hostname or SNMP sysName if present instead of the device IP address.

UI modified by this patch:
- Hover in Dashboard Availability Map (/overview)
- Name in Availability Map (/availability-map/)
- Title of device page (/device/device=...)

* I agree to the conditions of the Contributor Agreement contained in
doc/General/Contributing.md.

GitHub-issue: #4155
Suggested-by: Andres Rahn <andreser@gmail.com>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
This commit is contained in:
philmd
2017-03-03 16:48:53 -03:00
committed by Neil Lathwood
parent 5dc595e260
commit ad6dafd3a5
3 changed files with 12 additions and 9 deletions

View File

@@ -152,6 +152,7 @@ LibreNMS contributors:
- Markus Wigge <markus@cultcom.de> (cultcom) - Markus Wigge <markus@cultcom.de> (cultcom)
- Matthew Wall <llawwehttam@gmail.com> (llawwehttam) - Matthew Wall <llawwehttam@gmail.com> (llawwehttam)
- Andres Rahn <andreser@gmail.com> (Andreser) - Andres Rahn <andreser@gmail.com> (Andreser)
- Philippe Mathieu-Daudé <philmd@users.noreply.github.com> (philmd)
- Christoph Zilian <czilian@hotmail.com> (czilian) - Christoph Zilian <czilian@hotmail.com> (czilian)
- Guillem Mateos <bbguillem@gmail.com> (guillemmateos) - Guillem Mateos <bbguillem@gmail.com> (guillemmateos)
- Joachim Tingvold <joachim@tingvold.com> (jallakim) - Joachim Tingvold <joachim@tingvold.com> (jallakim)

View File

@@ -226,16 +226,17 @@ if (defined('SHOW_SETTINGS')) {
$deviceLabelOld = 'availability-map-oldview-box-down'; $deviceLabelOld = 'availability-map-oldview-box-down';
$host_down_count++; $host_down_count++;
} }
$device_system_name = ip_to_sysname($device, $device['hostname']);
if ($config['webui']['availability_map_compact'] == 0) { if ($config['webui']['availability_map_compact'] == 0) {
if ($directpage == "yes") { if ($directpage == "yes") {
$deviceIcon = getIconTag($device); $deviceIcon = getIconTag($device);
$temp_output[] = ' $temp_output[] = '
<a href="' .generate_device_url($device). '" title="' . $device['hostname'] . " - " . formatUptime($device['uptime']) . '"> <a href="' .generate_device_url($device). '" title="' . $device_system_name . " - " . formatUptime($device['uptime']) . '">
<div class="device-availability ' . $deviceState . '" style="width:' . $config['webui']['availability_map_box_size'] . 'px;"> <div class="device-availability ' . $deviceState . '" style="width:' . $config['webui']['availability_map_box_size'] . 'px;">
<span class="availability-label label ' . $deviceLabel . ' label-font-border">' . $deviceState . '</span> <span class="availability-label label ' . $deviceLabel . ' label-font-border">' . $deviceState . '</span>
<span class="device-icon">' . $deviceIcon . '</span><br> <span class="device-icon">' . $deviceIcon . '</span><br>
<span class="small">' . shorthost(ip_to_sysname($device, $device['hostname'])) . '</span> <span class="small">' . shorthost($device_system_name) . '</span>
</div> </div>
</a>'; </a>';
} else { } else {
@@ -244,12 +245,12 @@ if (defined('SHOW_SETTINGS')) {
$deviceLabel .= ' widget-availability-fixed'; $deviceLabel .= ' widget-availability-fixed';
} }
$temp_output[] = ' $temp_output[] = '
<a href="' .generate_device_url($device). '" title="' . $device['hostname'] . " - " . formatUptime($device['uptime']) . '"> <a href="' .generate_device_url($device). '" title="' . $device_system_name . " - " . formatUptime($device['uptime']) . '">
<span class="label ' . $deviceLabel . ' widget-availability label-font-border">' . $deviceState . '</span> <span class="label ' . $deviceLabel . ' widget-availability label-font-border">' . $deviceState . '</span>
</a>'; </a>';
} }
} else { } else {
$temp_output[] = "<a href='" . generate_device_url($device) . "' title='" . $device['hostname'] . ' - ' . formatUptime($device['uptime']) . "'><div class='" . $deviceLabelOld . "' style='width:${compact_tile}px;height:${compact_tile}px;'></div></a>"; $temp_output[] = "<a href='" . generate_device_url($device) . "' title='" . $device_system_name . ' - ' . formatUptime($device['uptime']) . "'><div class='" . $deviceLabelOld . "' style='width:${compact_tile}px;height:${compact_tile}px;'></div></a>";
} }
} }
} }
@@ -275,17 +276,18 @@ if (defined('SHOW_SETTINGS')) {
$serviceState = "down"; $serviceState = "down";
$service_down_count++; $service_down_count++;
} }
$service_system_name = ip_to_sysname($service, $service['hostname']);
if ($config['webui']['availability_map_compact'] == 0) { if ($config['webui']['availability_map_compact'] == 0) {
if ($directpage == "yes") { if ($directpage == "yes") {
$deviceIcon = getIconTag($service); $deviceIcon = getIconTag($service);
$temp_output[] = ' $temp_output[] = '
<a href="' . generate_url(array('page' => 'device', 'tab' => 'services', 'device' => $service['device_id'])) . '" title="' . $service['hostname'] . " - " . $service['service_type'] . " - " . $service['service_desc'] . '"> <a href="' . generate_url(array('page' => 'device', 'tab' => 'services', 'device' => $service['device_id'])) . '" title="' . $service_system_name . " - " . $service['service_type'] . " - " . $service['service_desc'] . '">
<div class="service-availability ' . $serviceState . '" style="width:' . $config['webui']['availability_map_box_size'] . 'px;"> <div class="service-availability ' . $serviceState . '" style="width:' . $config['webui']['availability_map_box_size'] . 'px;">
<span class="service-name-label label ' . $serviceLabel . ' label-font-border">' . $service["service_type"] . '</span> <span class="service-name-label label ' . $serviceLabel . ' label-font-border">' . $service["service_type"] . '</span>
<span class="availability-label label ' . $serviceLabel . ' label-font-border">' . $serviceState . '</span> <span class="availability-label label ' . $serviceLabel . ' label-font-border">' . $serviceState . '</span>
<span class="device-icon">' . $deviceIcon . '</span><br> <span class="device-icon">' . $deviceIcon . '</span><br>
<span class="small">' . shorthost(ip_to_sysname($service, $service['hostname'])) . '</span> <span class="small">' . shorthost($service_system_name) . '</span>
</div> </div>
</a>'; </a>';
} else { } else {
@@ -295,12 +297,12 @@ if (defined('SHOW_SETTINGS')) {
$serviceLabel .= ' widget-availability-fixed'; $serviceLabel .= ' widget-availability-fixed';
} }
$temp_output[] = ' $temp_output[] = '
<a href="' . generate_url(array('page' => 'device', 'tab' => 'services', 'device' => $service['device_id'])) . '" title="' . shorthost(ip_to_sysname($service, $service['hostname'])) . " - " . $service['service_type'] . " - " . $service['service_desc'] . '"> <a href="' . generate_url(array('page' => 'device', 'tab' => 'services', 'device' => $service['device_id'])) . '" title="' . shorthost($service_system_name) . " - " . $service['service_type'] . " - " . $service['service_desc'] . '">
<span class="label ' . $serviceLabel . ' widget-availability label-font-border">' . $serviceText . '</span> <span class="label ' . $serviceLabel . ' widget-availability label-font-border">' . $serviceText . '</span>
</a>'; </a>';
} }
} else { } else {
$temp_output[] = "<a href='" . generate_url(array('page' => 'device', 'tab' => 'services', 'device' => $service['device_id'])) . "' title='${service['hostname']} - ${service['service_type']} - ${service['service_desc']}'><div class='" . $serviceLabelOld . "' style='width:${compact_tile}px;height:${compact_tile}px;'></div></a>"; $temp_output[] = "<a href='" . generate_url(array('page' => 'device', 'tab' => 'services', 'device' => $service['device_id'])) . "' title='${service_system_name} - ${service['service_type']} - ${service['service_desc']}'><div class='" . $serviceLabelOld . "' style='width:${compact_tile}px;height:${compact_tile}px;'></div></a>";
} }
} }
} else { } else {

View File

@@ -28,7 +28,7 @@ if (device_permitted($vars['device']) || $check_device == $vars['device']) {
$entity_state = get_dev_entity_state($device['device_id']); $entity_state = get_dev_entity_state($device['device_id']);
// print_r($entity_state); // print_r($entity_state);
$pagetitle[] = $device['hostname']; $pagetitle[] = ip_to_sysname($device, $device['hostname']);
$component = new LibreNMS\Component(); $component = new LibreNMS\Component();
$component_count = $component->getComponentCount($device['device_id']); $component_count = $component->getComponentCount($device['device_id']);