Commit dc2eeb15 authored by nimrod's avatar nimrod
Browse files

Yet more testing.

- Fill in the notification messages, addressed last linting issues.
- Enabled pre-commit in CI.
- Add importing of the nagios submodule in the wheel test.
parent d3ab0120
Loading
Loading
Loading
Loading
Loading
+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
@@ -31,6 +31,7 @@ install-wheel:
  script:
    - mnpw --help
    - mnpw --version
    - python3 -c 'import mnpw.nagios'

pytest:
  extends: .python3
@@ -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/
+15 −9
Original line number Diff line number Diff line
@@ -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."""
@@ -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")
@@ -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__":