#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (C) 2019 tribe29 GmbH - License: GNU General Public License v2
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.


def check_mkevents_arguments(params):
    args = []
    if "remote" in params:
        remote = params["remote"]
        if isinstance(remote, tuple):
            ipaddress, port = remote
            args += ["-H", "%s:%d" % (ipaddress, port)]
        elif remote:
            args += ["-s", remote]

    if params.get("ignore_acknowledged"):
        args.append("-a")

    hostspec = params.get("hostspec", "$HOSTADDRESS$")
    if isinstance(hostspec, list):
        hostspec = "/".join(hostspec)
    args.append(hostspec)

    if "application" in params:
        args.append(params["application"])
    return args


def check_mkevents_description(params):
    item = params.get("item", params.get("application"))
    if item:
        return "Events %s" % item
    return "Events"


active_check_info["mkevents"] = {
    "command_line": "check_mkevents $ARG1$",
    "argument_function": check_mkevents_arguments,
    "service_description": check_mkevents_description,
}
