#!/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.

# NOTE: Careful when replacing the *-import below with a more specific import. This can cause
# problems because it might remove variables from the check-context which are necessary for
# resolving legacy discovery results such as [("SUMMARY", "diskstat_default_levels")]. Furthermore,
# it might also remove variables needed for accessing discovery rulesets.
from cmk.base.check_legacy_includes.azure import *  # pylint: disable=wildcard-import,unused-wildcard-import


@get_data_or_go_stale
def check_azure_virtualnetworkgateways(_item, params, resource):
    for metric_key, cmk_key, displ in (
        ("maximum_P2SConnectionCount", "connections", "Point-to-site connections"),
        ("average_P2SBandwidth", "p2s_bandwidth", "Point-to-site bandwidth"),
        ("average_AverageBandwidth", "s2s_bandwidth", "Site-to-site bandwidth"),
    ):
        levels_l = params.get("%s_levels_lower" % cmk_key, (None, None))
        levels_u = params.get("%s_levels_upper" % cmk_key, (None, None))
        mcheck = check_azure_metric(
            resource, metric_key, cmk_key, displ, levels=levels_u, levels_lower=levels_l
        )
        if mcheck:
            yield mcheck

    for kv_pair in azure_iter_informative_attrs(resource):
        yield 0, "%s: %s" % kv_pair


check_info["azure_virtualnetworkgateways"] = {
    "parse_function": parse_azure,
    "inventory_function": discover(),
    "check_function": check_azure_virtualnetworkgateways,
    "service_description": "VNet Gateway %s",
    "has_perfdata": True,
    "group": "azure_virtualnetworkgateways",
}
