diff --git a/hbd/client/plugins/nagios_runner.py b/hbd/client/plugins/nagios_runner.py index 566522f..64301f6 100644 --- a/hbd/client/plugins/nagios_runner.py +++ b/hbd/client/plugins/nagios_runner.py @@ -87,13 +87,14 @@ class NagiosRunnerPlugin(MonitorPlugin): async def initialize(self) -> bool: """Initialize the Nagios runner plugin. - + Returns: True if at least one command is configured, False otherwise """ self.logger.info(f"Initializing {self.name} plugin") - + if not self.commands: + self.skip_reason = "no commands configured (add nagios_runner.commands to config)" self.logger.info("No Nagios commands configured") return False diff --git a/tests/test_nagios_runner.py b/tests/test_nagios_runner.py new file mode 100644 index 0000000..4656a5e --- /dev/null +++ b/tests/test_nagios_runner.py @@ -0,0 +1,22 @@ +import asyncio +import logging +import os +import stat + +import pytest + +from hbd.client.plugins.nagios_runner import ( + NagiosRunnerPlugin, + NAGIOS_OK, + NAGIOS_WARNING, + NAGIOS_CRITICAL, + NAGIOS_UNKNOWN, +) + + +def test_no_commands_sets_skip_reason(): + plugin = NagiosRunnerPlugin(config={"commands": []}) + result = asyncio.run(plugin.initialize()) + assert result is False + assert plugin.skip_reason is not None + assert "nagios_runner.commands" in plugin.skip_reason