Loading .gitlab-ci.yml +11 −0 Original line number Diff line number Diff line Loading @@ -45,3 +45,14 @@ run-executable: needs: - job: build-executable artifacts: true pytest: extends: .python3 stage: test before_script: - poetry install script: - poetry run pytest --junit-xml test.xml artifacts: reports: junit: test.xml mnpw/__init__.py +1 −1 Original line number Diff line number Diff line Loading @@ -52,7 +52,7 @@ def main(): check = nagios.Check(args.command, args.arguments) try: check.run(args.timeout, args.dry_run) except Exception as ex: except Exception as ex: # pylint: disable=broad-except parser.error(str(ex)) Loading mnpw/nagios.py +18 −6 Original line number Diff line number Diff line """Nagios check implementation.""" """Nagios check implementation. Based on the specification from https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/3/en/pluginapi.html""" import enum import subprocess import subprocess # nosemgrep: rules.bandit.B404 DEFAULT_TIMEOUT = 10 # In seconds. Loading @@ -21,11 +24,11 @@ class Check: Command = None Arguments = [] ExitCode = None Result = None Output = None PerfData = None LongOutput = None AdditionalOutput = None StandardError = None stderr = None def __init__(self, command, args): if not command: Loading @@ -34,9 +37,16 @@ class Check: if args: self.Arguments = args def run(self, timeout=DEFAULT_TIMEOUT, dryrun=False): def _parse_output(self): """Parses the plugin output to get the output, perf data and long output. Can be run after the plugin has run and finished successfully.""" if self.ExitCode is None: raise RuntimeError("Check hasn't run yet.") def run(self, timeout=DEFAULT_TIMEOUT): """Run the check (if it's hasn't run yet).""" if self.Result is not None: if self.ExitCode is not None: raise Exception("Check has already run.") try: proc = subprocess.run( Loading @@ -53,3 +63,5 @@ class Check: raise RuntimeError(f"Command {self.Command} not found.") except subprocess.TimeoutExpired: raise RuntimeError("Timeout exceeded.") self.ExitCode = proc.returncode self.stderr = proc.stderr pyproject.toml +1 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ requests = "^2.25.1" [tool.poetry.dev-dependencies] pre-commit = "^2.13.0" pyinstaller = "^4.3" pytest = "^6.2.4" [tool.poetry.scripts] mnpw = "mnpw:main" Loading tests/__init__.py 0 → 100644 +0 −0 Empty file added. Loading
.gitlab-ci.yml +11 −0 Original line number Diff line number Diff line Loading @@ -45,3 +45,14 @@ run-executable: needs: - job: build-executable artifacts: true pytest: extends: .python3 stage: test before_script: - poetry install script: - poetry run pytest --junit-xml test.xml artifacts: reports: junit: test.xml
mnpw/__init__.py +1 −1 Original line number Diff line number Diff line Loading @@ -52,7 +52,7 @@ def main(): check = nagios.Check(args.command, args.arguments) try: check.run(args.timeout, args.dry_run) except Exception as ex: except Exception as ex: # pylint: disable=broad-except parser.error(str(ex)) Loading
mnpw/nagios.py +18 −6 Original line number Diff line number Diff line """Nagios check implementation.""" """Nagios check implementation. Based on the specification from https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/3/en/pluginapi.html""" import enum import subprocess import subprocess # nosemgrep: rules.bandit.B404 DEFAULT_TIMEOUT = 10 # In seconds. Loading @@ -21,11 +24,11 @@ class Check: Command = None Arguments = [] ExitCode = None Result = None Output = None PerfData = None LongOutput = None AdditionalOutput = None StandardError = None stderr = None def __init__(self, command, args): if not command: Loading @@ -34,9 +37,16 @@ class Check: if args: self.Arguments = args def run(self, timeout=DEFAULT_TIMEOUT, dryrun=False): def _parse_output(self): """Parses the plugin output to get the output, perf data and long output. Can be run after the plugin has run and finished successfully.""" if self.ExitCode is None: raise RuntimeError("Check hasn't run yet.") def run(self, timeout=DEFAULT_TIMEOUT): """Run the check (if it's hasn't run yet).""" if self.Result is not None: if self.ExitCode is not None: raise Exception("Check has already run.") try: proc = subprocess.run( Loading @@ -53,3 +63,5 @@ class Check: raise RuntimeError(f"Command {self.Command} not found.") except subprocess.TimeoutExpired: raise RuntimeError("Timeout exceeded.") self.ExitCode = proc.returncode self.stderr = proc.stderr
pyproject.toml +1 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ requests = "^2.25.1" [tool.poetry.dev-dependencies] pre-commit = "^2.13.0" pyinstaller = "^4.3" pytest = "^6.2.4" [tool.poetry.scripts] mnpw = "mnpw:main" Loading