Loading mnpw/__init__.py +18 −3 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ __version__ = "0.1.5" import argparse import logging import os.path import socket import sys Loading @@ -28,6 +29,20 @@ def notify(message): logging.error("Failed to send notification.") def notify_wrapper(check): """mnpw specific notifications. The above notify function is generic, this function is more specific to the notifications mnpw sends. """ if check.Output is None or check.Output.strip() == "": notify( f"[{HOSTNAME}] {os.path.basename(check.Command)} returned {check.ExitCode}." # noqa: E501 ) else: notify(f"[{HOSTNAME}] {check.Output}") def main(): # noqa: MC0001 """Main entrypoint.""" parser = argparse.ArgumentParser(description=__doc__) Loading Loading @@ -112,15 +127,15 @@ def main(): # noqa: MC0001 elif check.ExitCode == nagios.NagiosCode.WARNING: logging.info("Check status is WARNING.") if args.warn and not args.dry_run: notify(f"[{HOSTNAME}] {check.Output}") notify_wrapper(check) elif check.ExitCode == nagios.NagiosCode.CRITICAL: logging.info("Check status is CRITICAL.") if not args.dry_run: notify(f"[{HOSTNAME}] {check.Output}") notify_wrapper(check) elif check.ExitCode == nagios.NagiosCode.UNKNOWN: logging.info("Check status is UNKNOWN.") if args.unknown and not args.dry_run: notify(f"[{HOSTNAME}] {check.Output}") notify_wrapper(check) else: logging.info( f"Check status is invalid for a Nagios plugin ({check.ExitCode})." Loading Loading
mnpw/__init__.py +18 −3 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ __version__ = "0.1.5" import argparse import logging import os.path import socket import sys Loading @@ -28,6 +29,20 @@ def notify(message): logging.error("Failed to send notification.") def notify_wrapper(check): """mnpw specific notifications. The above notify function is generic, this function is more specific to the notifications mnpw sends. """ if check.Output is None or check.Output.strip() == "": notify( f"[{HOSTNAME}] {os.path.basename(check.Command)} returned {check.ExitCode}." # noqa: E501 ) else: notify(f"[{HOSTNAME}] {check.Output}") def main(): # noqa: MC0001 """Main entrypoint.""" parser = argparse.ArgumentParser(description=__doc__) Loading Loading @@ -112,15 +127,15 @@ def main(): # noqa: MC0001 elif check.ExitCode == nagios.NagiosCode.WARNING: logging.info("Check status is WARNING.") if args.warn and not args.dry_run: notify(f"[{HOSTNAME}] {check.Output}") notify_wrapper(check) elif check.ExitCode == nagios.NagiosCode.CRITICAL: logging.info("Check status is CRITICAL.") if not args.dry_run: notify(f"[{HOSTNAME}] {check.Output}") notify_wrapper(check) elif check.ExitCode == nagios.NagiosCode.UNKNOWN: logging.info("Check status is UNKNOWN.") if args.unknown and not args.dry_run: notify(f"[{HOSTNAME}] {check.Output}") notify_wrapper(check) else: logging.info( f"Check status is invalid for a Nagios plugin ({check.ExitCode})." Loading