#!/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_raritan_pdu_outletcount(info):
    if info and info[0]:
        yield None, None


def check_raritan_pdu_outletcount(item, params, info):
    try:
        yield check_levels(
            int(info[0][0]), "outletcount", params, human_readable_func=lambda f: "%.f" % f
        )
    except IndexError:
        pass


check_info["raritan_pdu_outletcount"] = {
    "inventory_function": inventory_raritan_pdu_outletcount,
    "check_function": check_raritan_pdu_outletcount,
    "service_description": "Outlet Count",
    "group": "plug_count",
    "has_perfdata": True,
    "snmp_info": (".1.3.6.1.4.1.13742.6.3.2.2.1.4", ["1"]),  # outletCount
    "snmp_scan_function": lambda oid: oid(".1.3.6.1.2.1.1.2.0").startswith(".1.3.6.1.4.1.13742.6")
    and (
        oid(".1.3.6.1.4.1.13742.6.3.2.1.1.3.1").startswith("PX2-2")
        or oid(".1.3.6.1.4.1.13742.6.3.2.1.1.3.1").startswith("PX3")
    ),
}
