#!/usr/bin/env python3
# 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.

import time

from cmk.base.check_api import check_levels

aironet_default_error_levels = (1.0, 10.0)  # per second


def inventory_aironet_errors(info):
    yield from ((line[0], "aironet_default_error_levels") for line in info)


def check_aironet_errors(item, params, info):
    for line in info:
        if line[0] == item:
            value = int(line[1])
            this_time = time.time()
            yield check_levels(
                get_rate("aironet_errors.%s" % item, this_time, value),
                "errors",
                params,
                infoname="Errors/s",
            )
            return


check_info["aironet_errors"] = {
    "check_function": check_aironet_errors,
    "inventory_function": inventory_aironet_errors,
    "service_description": "MAC CRC errors radio %s",
    "has_perfdata": True,
    # CISCO-DOT11-IF-MIB::cd11IfRecFrameMacCrcErrors
    "snmp_info": (".1.3.6.1.4.1.9.9.272.1.2.1.1.1", [0, 2]),
    "snmp_scan_function": lambda oid: oid(".1.3.6.1.2.1.1.2.0")
    in [
        ".1.3.6.1.4.1.9.1.525",
        ".1.3.6.1.4.1.9.1.618",
        ".1.3.6.1.4.1.9.1.685",
        ".1.3.6.1.4.1.9.1.758",
        ".1.3.6.1.4.1.9.1.1034",
        ".1.3.6.1.4.1.9.1.1247",
    ],
}
