Skip to content
Snippets Groups Projects
Commit 4c067d4c authored by nimrod's avatar nimrod
Browse files

Handle notifications without command output.

parent a70e63a4
Branches
Tags
No related merge requests found
Pipeline #2660 passed
......@@ -4,6 +4,7 @@ __version__ = "0.1.5"
import argparse
import logging
import os.path
import socket
import sys
......@@ -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__)
......@@ -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})."
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment