#!/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_traceroute_arguments(params):
    args = []

    if not params["dns"]:
        args.append("-n")
    method = params["method"]
    if method == "icmp":
        args.append("-I")
    elif method == "tcp":
        args.append("-T")
    # else: None -> default method

    for router, state in params["routers"]:
        args += ["-%s" % state, router]

    family = params.get("address_family")
    if family is None:
        family = "ipv6" if is_ipv6_primary(host_name()) else "ipv4"

    if family == "ipv6":
        args.append("-6")
    else:
        args.append("-4")
    args.append("$HOSTADDRESS$")

    return args


active_check_info["traceroute"] = {
    "command_line": "check_traceroute $ARG1$",
    "argument_function": check_traceroute_arguments,
    "service_description": lambda params: "Routing",
    "has_perfdata": True,
}
