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

# .1.3.6.1.4.1.9148.3.3.1.5.1.1.3.1 Power Supply A --> ACMEPACKET-ENVMON-MIB::apEnvMonPowerSupplyStatusDescr.1
# .1.3.6.1.4.1.9148.3.3.1.5.1.1.3.2 Power Supply B --> ACMEPACKET-ENVMON-MIB::apEnvMonPowerSupplyStatusDescr.2
# .1.3.6.1.4.1.9148.3.3.1.5.1.1.4.1 2 --> ACMEPACKET-ENVMON-MIB::apEnvMonPowerSupplyState.1
# .1.3.6.1.4.1.9148.3.3.1.5.1.1.4.2 2 --> ACMEPACKET-ENVMON-MIB::apEnvMonPowerSupplyState.2


def inventory_acme_powersupply(info):
    return [(descr, None) for descr, state in info if state != "7"]


def check_acme_powersupply(item, _no_params, info):
    for descr, state in info:
        if item == descr:
            dev_state, dev_state_readable = acme_environment_states[state]
            return dev_state, "Status: %s" % dev_state_readable


check_info["acme_powersupply"] = {
    "inventory_function": inventory_acme_powersupply,
    "check_function": check_acme_powersupply,
    "service_description": "Power supply %s",
    "snmp_info": (
        ".1.3.6.1.4.1.9148.3.3.1.5.1.1",
        [
            "3",  # ADCMEPACKET-ENVMON-MIB::apEnvMonPowersDescr
            "4",  # ACMEPACKET-ENVMON-MIB::apEnvMonPowerSupplyState
        ],
    ),
    "snmp_scan_function": scan_acme,
}
