#!/usr/bin/env python3
# -*- coding: utf-8; py-indent-offset: 4 -*-
#
# Author:  Linuxfabrik GmbH, Zurich, Switzerland
# Contact: info (at) linuxfabrik (dot) ch
#          https://www.linuxfabrik.ch/
# License: The Unlicense, see LICENSE file.

# https://github.com/Linuxfabrik/monitoring-plugins/blob/main/CONTRIBUTING.md

"""See the check's README for more details."""

import argparse
import sys

import lib.args
import lib.base
from lib.globals import STATE_UNKNOWN

__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
__version__ = '2026040801'

DESCRIPTION = """Returns a freely configurable message, state, and perfdata. Useful for testing
monitoring configurations, simulating alerts, or generating placeholder data."""

DEFAULT_MSG = 'Everything is ok.'
DEFAULT_STATE = 'ok'
DEFAULT_PERFDATA = None


def parse_args():
    """Parse command line arguments using argparse."""
    parser = argparse.ArgumentParser(description=DESCRIPTION)

    parser.add_argument(
        '-V',
        '--version',
        action='version',
        version=f'%(prog)s: v{__version__} by {__author__}',
    )

    parser.add_argument(
        '--always-ok',
        help=lib.args.help('--always-ok'),
        dest='ALWAYS_OK',
        action='store_true',
        default=False,
    )

    parser.add_argument(
        '--message',
        help='Message to return. Default: %(default)s',
        dest='MESSAGE',
        default=DEFAULT_MSG,
    )

    parser.add_argument(
        '--perfdata',
        help='Perfdata to return, formatted according to the Nagios '
        'guidelines. Default: %(default)s',
        dest='PERFDATA',
        default=DEFAULT_PERFDATA,
    )

    parser.add_argument(
        '--state',
        help='State to return (ok, warn, crit, unk). Default: %(default)s',
        choices=['ok', 'warn', 'crit', 'unk'],
        dest='STATE',
        default=DEFAULT_STATE,
    )

    args, _ = parser.parse_known_args()
    return args


def main():
    """The main function. This is where the magic happens."""

    # parse the command line
    try:
        args = parse_args()
    except SystemExit:
        sys.exit(STATE_UNKNOWN)

    # over and out
    lib.base.oao(
        args.MESSAGE,
        lib.base.str2state(args.STATE),
        args.PERFDATA,
        always_ok=args.ALWAYS_OK,
    )


if __name__ == '__main__':
    try:
        main()
    except Exception:
        lib.base.cu()
