#!/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.hp_mcs import *  # pylint: disable=wildcard-import,unused-wildcard-import

# example output


def inventory_hp_mcs_system(info):
    return [(info[0][0], None)]


def check_hp_mcs_system(item, _no_params, info):
    translate_status = {
        0: (2, "Not available"),
        1: (3, "Other"),
        2: (0, "OK"),
        3: (1, "Degraded"),
        4: (2, "Failed"),
    }
    serial = info[0][2]
    _idx1, status, _idx2, _dev_type = info[0][1]
    state, state_readable = translate_status[status]
    if state:
        yield state, "Status: %s" % state_readable
    yield 0, "Serial: %s" % serial


check_info["hp_mcs_system"] = {
    "inventory_function": inventory_hp_mcs_system,
    "check_function": check_hp_mcs_system,
    "service_description": "%s",
    "snmp_info": (
        ".1.3.6.1.4.1.232",
        [
            "2.2.4.2",  # CPQSINFO-MIB::cpqSiProductName
            BINARY("11.2.10.1"),  # CPQHOST-MIB::cpqHoMibStatusArray
            "11.2.10.3",  # CPQHOST-MIB::cpqHoGUID
        ],
    ),
    "snmp_scan_function": hp_mcs_scan_function,
}
