Index: includes/entities/probe.inc.php =================================================================== --- includes/entities/probe.inc.php (revision 15424) +++ includes/entities/probe.inc.php (working copy) @@ -18,31 +18,44 @@ } // Helper function to parse Nagios performance data string function parse_nagios_perfdata(string $perfdata_string): array { $metrics = []; - $pattern = "/'?(.+?)'?=([0-9\.\-]+)([a-zA-Z%]*c?);?([^;]*);?([^;]*);?([^;]*);?([^;]*)/"; + $pattern = "/(?:^|\s)(?:'([^']+)'|([^\s=]+))=" . + "([-+]?(?:\d+(?:\.\d*)?|\.\d+))" . + "([a-zA-Z%]*)" . + "(?:;([^;\s]*))?" . + "(?:;([^;\s]*))?" . + "(?:;([^;\s]*))?" . + "(?:;([^;\s]*))?/"; + if (preg_match_all($pattern, $perfdata_string, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) { - $uom = trim($match[3]) ?? ''; + $label = $match[1] !== '' ? $match[1] : $match[2]; + $uom = $match[4] ?? ''; + $type = str_ends_with($uom, 'c') ? 'COUNTER' : 'GAUGE'; + if ($type === 'COUNTER') { - $uom = rtrim($uom, 'c'); + $uom = substr($uom, 0, -1); } $metrics[] = [ - 'label' => trim($match[1]), - 'value' => (float) $match[2], + 'label' => $label, + 'value' => (float) $match[3], 'uom' => $uom, 'type' => $type, - 'warn' => trim($match[4]) ?? '', - 'crit' => trim($match[5]) ?? '', - 'min' => trim($match[6]) ?? '', - 'max' => trim($match[7]) ?? '', + 'warn' => $match[5] ?? '', + 'crit' => $match[6] ?? '', + 'min' => $match[7] ?? '', + 'max' => $match[8] ?? '', ]; } } + return $metrics; }