Fix missing-host highlight flagging regexes after a comma or 'or' separator

This commit is contained in:
Luigi D'Acunto 2026-09-30 15:12:09 +02:00
parent 63177a9573
commit 7c385bef64
2 changed files with 12 additions and 3 deletions

View file

@ -5,6 +5,11 @@ All notable changes to **Checkmk SwissKnife** are documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [2.24.1] - 2026-09-30
### Fixed
- Missing-host highlighting no longer flags regexes that follow a comma or an "or" in a "Host name matches one of regex A, B or C" condition as host names.
## [2.24.0] - 2026-09-28
### Added

View file

@ -1,7 +1,7 @@
// ==UserScript==
// @name Checkmk SwissKnife
// @namespace https://luigidacunto.com/
// @version 2.24.0
// @version 2.24.1
// @checkmk 2.3.x - 2.4.x
// @description Collection of UI improvements for Checkmk WATO. Each fix or enhancement is added here as an independent feature.
// @author Luigi D'Acunto
@ -913,10 +913,14 @@
items.forEach(li => {
if (!li.textContent.trim().startsWith('Host name')) return;
let isRegex = false;
li.querySelectorAll('b').forEach(b => {
// Text right before each <b> tells regex ("matches regex", "one of regex") from exact name ("is", "is not")
// Text right before each <b> tells regex ("matches regex", "one of regex") from exact name ("is", "is not").
// A bare "," / " or " separator continues the previous mode: "matches regex A or B" → B is a regex too.
const before = b.previousSibling ? b.previousSibling.textContent : '';
if (/regex/.test(before) || b.querySelector('a')) return;
if (/regex/.test(before)) isRegex = true;
else if (!/^[\s,]*(or)?[\s,]*$/.test(before)) isRegex = false;
if (isRegex || b.querySelector('a')) return;
b.classList.add('cmk-sk-missing-host');
b.title = 'Host not found in Checkmk (deleted?)';
});