From b1dabef96c51bdafa20de0a1a4d4a1eaa7015e8b Mon Sep 17 00:00:00 2001 From: fsalomon Date: Tue, 28 Apr 2026 14:18:37 +0200 Subject: [PATCH] Preserve state labels in plugin output (#1366) - Keep bracketed state labels as text inside plugin output (state-ball replacements) - Hide the text visually while preserving the existing state-ball styling Nice when copy&pasting plugin output to a code agent. --------- Co-authored-by: Fabian Salomon <4098510+fsalomon@users.noreply.github.com> --- library/Icingadb/Util/PluginOutput.php | 14 ++++----- .../Icingadb/Util/PluginOutputTest.php | 29 ++++++++++++------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/library/Icingadb/Util/PluginOutput.php b/library/Icingadb/Util/PluginOutput.php index 916cea2e..d66e35f5 100644 --- a/library/Icingadb/Util/PluginOutput.php +++ b/library/Icingadb/Util/PluginOutput.php @@ -34,13 +34,13 @@ class PluginOutput extends HtmlString protected const TEXT_REPLACEMENTS = [ "\t", "\n", - '', - '', - '', - '', - '', - '', - '', + '[OK]', + '[WARNING]', + '[CRITICAL]', + '[UNKNOWN]', + '[UP]', + '[DOWN]', + '[INFO]', '@@@@@@' ]; diff --git a/test/php/library/Icingadb/Util/PluginOutputTest.php b/test/php/library/Icingadb/Util/PluginOutputTest.php index e9159636..f8eac877 100644 --- a/test/php/library/Icingadb/Util/PluginOutputTest.php +++ b/test/php/library/Icingadb/Util/PluginOutputTest.php @@ -38,9 +38,9 @@ class PluginOutputTest extends TestCase INPUT; $expectedOutput = <<<'EXPECTED_OUTPUT' - Dummy state - \_ Fake "state" - \_ Fake state again +[OK] Dummy state + \_ [OK] Fake "state" + \_ [WARNING] Fake state again EXPECTED_OUTPUT; $this->checkOutput($expectedOutput, $input); @@ -55,7 +55,7 @@ EXPECTED_OUTPUT; INPUT; $expectedOutput = <<<'EXPECTED_OUTPUT' - Dummy +[OK] Dummy EXPECTED_OUTPUT; $this->checkOutput($expectedOutput, $input, 10); @@ -86,9 +86,9 @@ INPUT; $expectedOutput = <<<'EXPECTED_OUTPUT' Hello

World

, this "is" a test. - Dummy state - \_ Fake "state" - \_ Fake state again +[OK] Dummy state + \_ [OK] Fake "state" + \_ [WARNING] Fake state again text ends here EXPECTED_OUTPUT; @@ -106,7 +106,7 @@ INPUT; $expectedOutput = <<<'EXPECTED_OUTPUT' Hello

World

, this "is" a test. - Dummy state +[OK] Dummy state special chars: !@#$%^&*()_+{}|:"<>?`-=[]\;',​./ text ends here EXPECTED_OUTPUT; @@ -149,7 +149,11 @@ EXPECTED_OUTPUT; $l = strtolower($s); $input = sprintf('[%s] Test', $s); - $expectedOutput = sprintf(' Test', $l); + $expectedOutput = sprintf( + '[%s] Test', + $l, + $s + ); $this->checkOutput($expectedOutput, $input); @@ -167,7 +171,12 @@ EXPECTED_OUTPUT; $l = strtolower($s); $input = sprintf('%s [%s] Test', $dummyHtml, $s); - $expectedOutput = sprintf('%s Test', $dummyHtml, $l); + $expectedOutput = sprintf( + '%s [%s] Test', + $dummyHtml, + $l, + $s + ); $this->checkOutput($expectedOutput, $input);