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

from typing import NamedTuple

from cmk.base.check_legacy_includes.cisco_ucs import map_operability, scan_cisco_ucs

# comNET GmbH, Fabian Binder - 2018-05-07


class Section(NamedTuple):
    model: str
    state: int
    operability: str
    serial: str
    vendor: str


def parse_cisco_ucs_raid(string_table) -> Section:
    return Section(
        string_table[0][0],
        *map_operability[string_table[0][1]],
        string_table[0][2],
        string_table[0][3],
    )


def discover_cisco_ucs_raid(section):
    yield None, {}


def check_cisco_ucs_raid(_no_item, _no_params, section):
    yield section.state, f"Status: {section.operability}"
    yield 0, f"Model: {section.model}"
    yield 0, f"Vendor: {section.vendor}"
    yield 0, f"Serial number: {section.serial}"


check_info["cisco_ucs_raid"] = {
    "parse_function": parse_cisco_ucs_raid,
    "check_function": check_cisco_ucs_raid,
    "inventory_function": discover_cisco_ucs_raid,
    "service_description": "RAID Controller",
    "snmp_scan_function": scan_cisco_ucs,
    "snmp_info": (
        ".1.3.6.1.4.1.9.9.719.1.45.1.1",
        [
            "5",  # cucsStorageControllerModel
            "7",  # cucsStorageControllerOperability
            "14",  # cucsStorageControllerSerial
            "17",  # cucsStorageControllerVendor
        ],
    ),
}
