From ae447ac4a64a95f634795044ae9c4cc5fcb241cc Mon Sep 17 00:00:00 2001 From: Andreas Wrede Date: Tue, 5 May 2026 11:05:45 -0400 Subject: [PATCH] feat: nagios_runner improvements and alerts page fixes - nagios_runner: remove overall_status/overall_status_code/plugin_count fields; each command still reports its own _status and _status_code - threshold: expose {output} and {status} aliases in display templates for nagios_runner generic matches (mapped from _output/status) - alerts.html: fix scrolling by overriding html,body height/overflow (style.css sets both); make hostname a link to /plugins/ Co-Authored-By: Claude Sonnet 4.6 --- README.md | 2 ++ hbd/client/plugins/nagios_runner.py | 40 +++++++++-------------------- hbd/server/templates/alerts.html | 10 +++++--- hbd/server/threshold.py | 13 ++++++++++ 4 files changed, 34 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 66fed85..c42dd67 100644 --- a/README.md +++ b/README.md @@ -299,6 +299,8 @@ Available variables: | `{op_symbol}` | Comparison operator (`>`, `<`, `>=`, …) | | `{check_name}` | Prefix stripped by generic matching (see below) | | `{metric_name}` | Full field name within the plugin data | +| `{output}` | For `nagios_runner` generic matches: the matched check's status text (alias for `{check_name}_output`) | +| `{status}` | For `nagios_runner` generic matches: the matched check's status name — OK/WARNING/CRITICAL/UNKNOWN (alias for `{check_name}_status`) | | any plugin field | Any other field present in the plugin's data | ### Generic Threshold Matching diff --git a/hbd/client/plugins/nagios_runner.py b/hbd/client/plugins/nagios_runner.py index 12fdaf1..d91aecb 100644 --- a/hbd/client/plugins/nagios_runner.py +++ b/hbd/client/plugins/nagios_runner.py @@ -31,16 +31,13 @@ from hbd.client.plugin import MonitorPlugin # Nagios exit codes -NAGIOS_OK = 0 -NAGIOS_WARNING = 1 -NAGIOS_CRITICAL = 2 NAGIOS_UNKNOWN = 3 STATUS_NAMES = { - NAGIOS_OK: "OK", - NAGIOS_WARNING: "WARNING", - NAGIOS_CRITICAL: "CRITICAL", - NAGIOS_UNKNOWN: "UNKNOWN" + 0: "OK", + 1: "WARNING", + 2: "CRITICAL", + 3: "UNKNOWN", } @@ -128,52 +125,39 @@ class NagiosRunnerPlugin(MonitorPlugin): Dictionary with results from all plugins """ results = {} - - # Track overall status (worst status wins) - worst_status = NAGIOS_OK - + for cmd_config in self.commands: name = cmd_config.get("name") command = cmd_config.get("command") - + if not name or not command: self.logger.warning("Skipping command with missing name or command") continue - + # Execute plugin try: status_code, output, perfdata = await self._run_nagios_plugin(command) - + # Store results results[f"{name}_status"] = STATUS_NAMES.get(status_code, "UNKNOWN") results[f"{name}_status_code"] = status_code results[f"{name}_output"] = output - - # Track worst status - if status_code > worst_status: - worst_status = status_code - + # Parse and add performance data if perfdata: for metric_name, metric_value in perfdata.items(): results[f"{name}_{metric_name}"] = metric_value - + self.logger.info( f"Executed {name}: {STATUS_NAMES.get(status_code, 'UNKNOWN')} - {output[:50]}" ) - + except Exception as e: self.logger.error(f"Error running {name}: {e}", exc_info=True) results[f"{name}_status"] = "ERROR" results[f"{name}_status_code"] = NAGIOS_UNKNOWN results[f"{name}_output"] = str(e) - worst_status = NAGIOS_UNKNOWN - - # Add overall status - results["overall_status"] = STATUS_NAMES.get(worst_status, "UNKNOWN") - results["overall_status_code"] = worst_status - results["plugin_count"] = len(self.commands) - + return results async def _run_nagios_plugin( diff --git a/hbd/server/templates/alerts.html b/hbd/server/templates/alerts.html index 493ff1d..9718301 100644 --- a/hbd/server/templates/alerts.html +++ b/hbd/server/templates/alerts.html @@ -4,7 +4,7 @@