#!/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.wlc_clients import *  # pylint: disable=wildcard-import,unused-wildcard-import
# .1.3.6.1.4.1.14179.2.1.1.1.2.1 FOO
# .1.3.6.1.4.1.14179.2.1.1.1.2.2 BAR
# .1.3.6.1.4.1.14179.2.1.1.1.2.3 Hans
# .1.3.6.1.4.1.14179.2.1.1.1.2.4 PETER
# .1.3.6.1.4.1.14179.2.1.1.1.2.16 Huhu
# .1.3.6.1.4.1.14179.2.1.1.1.42.1 foo
# .1.3.6.1.4.1.14179.2.1.1.1.42.2 bar
# .1.3.6.1.4.1.14179.2.1.1.1.42.3 hans
# .1.3.6.1.4.1.14179.2.1.1.1.42.4 gastzugang
# .1.3.6.1.4.1.14179.2.1.1.1.42.16 gastzugang
# .1.3.6.1.4.1.14179.2.1.1.1.38.1 6
# .1.3.6.1.4.1.14179.2.1.1.1.38.2 12
# .1.3.6.1.4.1.14179.2.1.1.1.38.3 0
# .1.3.6.1.4.1.14179.2.1.1.1.38.4 6
# .1.3.6.1.4.1.14179.2.1.1.1.38.16 6


def parse_cisco_wlc_clients(info):
    parsed = {}
    sum_clients = 0
    for name, interface, num_clients in info:
        sum_clients_name = int(num_clients)
        sum_clients += sum_clients_name

        if name in parsed:
            sum_clients_name += parsed[name][0]
            interface = parsed[name][1] + ", " + interface

        parsed[name] = (sum_clients_name, "%s: %s" % (interface, num_clients))

    parsed["Summary"] = (sum_clients, "")
    return parsed


check_info["cisco_wlc_clients"] = {
    "parse_function": parse_cisco_wlc_clients,
    "inventory_function": inventory_wlc_clients,
    "check_function": check_wlc_clients,
    "service_description": "Clients %s",
    "group": "wlc_clients",
    "has_perfdata": True,
    "snmp_scan_function": lambda oid: oid('.1.3.6.1.2.1.1.2.0') in [
        ".1.3.6.1.4.1.14179.1.1.4.3",
        ".1.3.6.1.4.1.9.1.1069",
        ".1.3.6.1.4.1.9.1.1279",
        ".1.3.6.1.4.1.9.1.1293",
        ".1.3.6.1.4.1.9.1.1615",
        ".1.3.6.1.4.1.9.1.1631",
        ".1.3.6.1.4.1.9.1.1645",
        ".1.3.6.1.4.1.9.1.2170",
        ".1.3.6.1.4.1.9.1.2250",
        ".1.3.6.1.4.1.9.1.2370",  # Cisco Aironet 2800
        ".1.3.6.1.4.1.9.1.2371",
        ".1.3.6.1.4.1.9.1.2427",
        ".1.3.6.1.4.1.9.1.2489",
    ],
    "snmp_info": (".1.3.6.1.4.1.14179.2.1.1.1", [
        "2",
        "42",
        "38",
    ]),
}
