Loading .gitlab-ci.yml +4 −2 Original line number Diff line number Diff line --- include: # - project: shore/ci-templates # file: templates/pre-commit.yml - project: shore/ci-templates file: templates/pre-commit.yml - project: shore/ci-templates file: templates/python.yml - project: shore/ci-templates Loading Loading @@ -31,6 +31,7 @@ install-wheel: script: - mnpw --help - mnpw --version - python3 -c 'import mnpw.nagios' pytest: extends: .python3 Loading @@ -55,6 +56,7 @@ bats: - >- curl --location --silent https://github.com/cloudbees-oss/juxr/releases/download/0.1.22/juxr-x86_64-unknown-linux-gnu.tar.gz | tar -zxC /usr/local/bin/ Loading mnpw/__init__.py +15 −9 Original line number Diff line number Diff line Loading @@ -4,11 +4,14 @@ __version__ = "0.1.0" import argparse import logging import socket import requests from mnpw import nagios HOSTNAME = socket.gethostname() def notify(message): """Send a notification.""" Loading @@ -17,7 +20,7 @@ def notify(message): ) def main(): def main(): # noqa: MC0001 """Main entrypoint.""" parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("command", type=str, help="Plugin command") Loading Loading @@ -85,29 +88,32 @@ def main(): try: check.run(args.timeout) except Exception as ex: # pylint: disable=broad-except if args.errors: notify(f"") if args.errors and not args.dry_run: notify(f"Check {args.command} on {HOSTNAME} failed: {ex}.") parser.error(str(ex)) if check.ExitCode == nagios.NagiosCode.OK: logging.info("Check status is OK.") elif check.ExitCode == nagios.NagiosCode.WARNING: logging.info("Check status is WARNING.") if args.warn: notify(f"") if args.warn and not args.dry_run: notify(f"Check {args.command} on {HOSTNAME} returned a warning.") elif check.ExitCode == nagios.NagiosCode.CRITICAL: logging.info("Check status is CRITICAL.") notify(f"") if not args.dry_run: notify(f"Check {args.command} on {HOSTNAME} is critical!") elif check.ExitCode == nagios.NagiosCode.UNKNOWN: logging.info("Check status is UNKNOWN.") if args.unknown: notify(f"") if args.unknown and not args.dry_run: notify( f"Check {args.command} on {HOSTNAME} is in an unknown state." ) else: logging.info( f"Check status is invalid for a Nagios plugin ({check.ExitCode})." ) if args.errors: notify(f"") notify(f"Check {args.command} on {HOSTNAME} status is invalid.") if __name__ == "__main__": Loading Loading
.gitlab-ci.yml +4 −2 Original line number Diff line number Diff line --- include: # - project: shore/ci-templates # file: templates/pre-commit.yml - project: shore/ci-templates file: templates/pre-commit.yml - project: shore/ci-templates file: templates/python.yml - project: shore/ci-templates Loading Loading @@ -31,6 +31,7 @@ install-wheel: script: - mnpw --help - mnpw --version - python3 -c 'import mnpw.nagios' pytest: extends: .python3 Loading @@ -55,6 +56,7 @@ bats: - >- curl --location --silent https://github.com/cloudbees-oss/juxr/releases/download/0.1.22/juxr-x86_64-unknown-linux-gnu.tar.gz | tar -zxC /usr/local/bin/ Loading
mnpw/__init__.py +15 −9 Original line number Diff line number Diff line Loading @@ -4,11 +4,14 @@ __version__ = "0.1.0" import argparse import logging import socket import requests from mnpw import nagios HOSTNAME = socket.gethostname() def notify(message): """Send a notification.""" Loading @@ -17,7 +20,7 @@ def notify(message): ) def main(): def main(): # noqa: MC0001 """Main entrypoint.""" parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("command", type=str, help="Plugin command") Loading Loading @@ -85,29 +88,32 @@ def main(): try: check.run(args.timeout) except Exception as ex: # pylint: disable=broad-except if args.errors: notify(f"") if args.errors and not args.dry_run: notify(f"Check {args.command} on {HOSTNAME} failed: {ex}.") parser.error(str(ex)) if check.ExitCode == nagios.NagiosCode.OK: logging.info("Check status is OK.") elif check.ExitCode == nagios.NagiosCode.WARNING: logging.info("Check status is WARNING.") if args.warn: notify(f"") if args.warn and not args.dry_run: notify(f"Check {args.command} on {HOSTNAME} returned a warning.") elif check.ExitCode == nagios.NagiosCode.CRITICAL: logging.info("Check status is CRITICAL.") notify(f"") if not args.dry_run: notify(f"Check {args.command} on {HOSTNAME} is critical!") elif check.ExitCode == nagios.NagiosCode.UNKNOWN: logging.info("Check status is UNKNOWN.") if args.unknown: notify(f"") if args.unknown and not args.dry_run: notify( f"Check {args.command} on {HOSTNAME} is in an unknown state." ) else: logging.info( f"Check status is invalid for a Nagios plugin ({check.ExitCode})." ) if args.errors: notify(f"") notify(f"Check {args.command} on {HOSTNAME} status is invalid.") if __name__ == "__main__": Loading