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

avaya_chassis_card_operstatus_codes = {
    1: (0, "up"),
    2: (2, "down"),
    3: (0, "testing"),
    4: (3, "unknown"),
    5: (0, "dormant"),
}


def inventory_avaya_chassis_card(info):
    for line in info:
        yield line[0], None


def check_avaya_chassis_card(item, _no_params, info):
    for line in info:
        if line[0] == item:
            status, name = avaya_chassis_card_operstatus_codes[int(line[1])]
            return status, "Operational status: %s" % name


check_info["avaya_chassis_card"] = {
    "check_function": check_avaya_chassis_card,
    "inventory_function": inventory_avaya_chassis_card,
    "service_description": "Card %s",
    "snmp_info": (
        ".1.3.6.1.4.1.2272.1.4.9.1.1",
        [
            1,  # rcCardIndex
            6,  # rcCardOperStatus
        ],
    ),
    "snmp_scan_function": lambda oid: ".1.3.6.1.4.1.2272" in oid(".1.3.6.1.2.1.1.2.0"),
}
