From d4479e12dd88ce753c0a7d15669a85876c812d72 Mon Sep 17 00:00:00 2001 From: Sander Steffann Date: Fri, 22 Apr 2022 17:05:55 +0200 Subject: [PATCH] Fix IPv6 in service check host (#13939) * Add hostName cleaning to Clean * Apply RFC 5952 formatting to Clean::hostName output * Use more liberal cleaning for hostnames * Remove unwanted whitespace * Apply Clean::hostName() to all relevant fields * Fix docstring * Use IP::isValid inline * Update Clean.php * Update services.inc.php Co-authored-by: Tony Murray --- includes/services.inc.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/includes/services.inc.php b/includes/services.inc.php index ddfaf638382b..d6a019cb4ae5 100644 --- a/includes/services.inc.php +++ b/includes/services.inc.php @@ -5,6 +5,7 @@ use LibreNMS\Config; use LibreNMS\RRD\RrdDefinition; use LibreNMS\Util\Clean; +use LibreNMS\Util\IP; function get_service_status($device = null) { @@ -122,9 +123,9 @@ function poll_service($service) $update = []; $old_status = $service['service_status']; $service['service_type'] = Clean::fileName($service['service_type']); - $service['service_ip'] = Clean::fileName($service['service_ip']); - $service['hostname'] = Clean::fileName($service['hostname']); - $service['overwrite_ip'] = Clean::fileName($service['overwrite_ip']); + $service['service_ip'] = IP::isValid($service['service_ip']) ? $service['service_ip'] : Clean::fileName($service['service_ip']); + $service['hostname'] = IP::isValid($service['hostname']) ? $service['hostname'] : Clean::fileName($service['hostname']); + $service['overwrite_ip'] = IP::isValid($service['overwrite_ip']) ? $service['overwrite_ip'] : Clean::fileName($service['overwrite_ip']); $check_cmd = ''; // if we have a script for this check, use it.