Commit ea4bd684 authored by nimrod's avatar nimrod
Browse files

Better notifications and output.

- Use the parsed plugin output in the notification.
- Log more of the plugin output.
parent 5eb9cfe1
Loading
Loading
Loading
Loading
+17 −5
Original line number Diff line number Diff line
@@ -94,24 +94,36 @@ def main(): # noqa: MC0001

    if check.ExitCode == nagios.NagiosCode.OK:
        logging.info("Check status is OK.")
        logging.info(check.Output)
        logging.info(check.AdditionalOutput)
        logging.info(check.stderr)
    elif check.ExitCode == nagios.NagiosCode.WARNING:
        logging.info("Check status is WARNING.")
        logging.info(check.Output)
        logging.info(check.AdditionalOutput)
        logging.info(check.stderr)
        if args.warn and not args.dry_run:
            notify(f"Check {args.command} on {HOSTNAME} returned a warning.")
            notify(f"{check.Output} on {HOSTNAME}.")
    elif check.ExitCode == nagios.NagiosCode.CRITICAL:
        logging.info("Check status is CRITICAL.")
        logging.info(check.Output)
        logging.info(check.AdditionalOutput)
        logging.info(check.stderr)
        if not args.dry_run:
            notify(f"Check {args.command} on {HOSTNAME} is critical!")
            notify(f"{check.Output} on {HOSTNAME}.")
    elif check.ExitCode == nagios.NagiosCode.UNKNOWN:
        logging.info("Check status is UNKNOWN.")
        logging.info(check.Output)
        logging.info(check.AdditionalOutput)
        logging.info(check.stderr)
        if args.unknown and not args.dry_run:
            notify(
                f"Check {args.command} on {HOSTNAME} is in an unknown state."
            )
            notify(f"{check.Output} on {HOSTNAME}.")
    else:
        logging.info(
            f"Check status is invalid for a Nagios plugin ({check.ExitCode})."
        )
        logging.info(check._stdout)
        logging.info(check.stderr)
        if args.errors:
            notify(f"Check {args.command} on {HOSTNAME} status is invalid.")