#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2019 Checkmk 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.

# This is the Checkmk check to configure active checks of check_flapping
# via WATO. It must be placed into share/check_mk/checks directory.


def check_flapping_arguments(params):
    description, svc_patterns, settings = params

    args = ''

    if "timerange" in settings:
        args += ' -r %d' % int(settings["timerange"])

    if "num_state_changes" in settings:
        args += ' -w %d' % int(settings["num_state_changes"][0])
        args += ' -c %d' % int(settings["num_state_changes"][1])

    args += ' %s %s' % (host_name(), ' '.join([quote_shell_string(s) for s in svc_patterns]))

    return args


active_check_info['flapping'] = {
    "command_line": '$USER2$/check_flapping $ARG1$',
    "argument_function": check_flapping_arguments,
    "service_description": lambda params: "flapping %s" % params[0],
    "has_perfdata": True,
}
