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


def inventory_casa_power(info):
    yield from ((str(idx), None) for idx in range(len(info)))


def check_casa_power(item, no_params, info):
    unit_nr = int(item)
    if len(info) < unit_nr:
        return (3, "Power Supply %s not found in snmp output" % item)

    return {
        "0": (3, "Power supply - Unknown status (!)"),
        "1": (0, "Power supply OK"),
        "2": (0, "Power supply working under threshold (!)"),  # OK, backup power..
        "3": (1, "Power supply working over threshold (!)"),
        "4": (2, "Power Failure(!!)"),
    }.get(info[unit_nr][0])


check_info["casa_power"] = {
    "check_function": check_casa_power,
    "inventory_function": inventory_casa_power,
    "service_description": "Power %s",
    "snmp_scan_function": lambda oid: oid(".1.3.6.1.2.1.1.2.0").startswith(".1.3.6.1.4.1.20858.2."),
    "snmp_info": (".1.3.6.1.4.1.20858.10.33.1.5.1.4", [""]),  # Power State
}
