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

# Check has been developed using a Emerson Network Power Rack PDU Card
# Agent App Firmware Version  4.840.0
# Agent Boot Firmware Version 4.540.3
# FDM Version 1209
# GDD Version 45585

# Example info:
# [['1', 'TEST-123-HOST', '1', '535055G103T2010JUN240295', '1']]


def inventory_lgp_pdu_info(info):
    if info:
        inv = []
        for pdu in info:
            # Use the SysAssignLabel as item
            inv.append((pdu[2], None))
        return inv


def check_lgp_pdu_info(item, params, info):
    for pdu in info:
        if pdu[2] == item:
            return (0, "Entry-ID: %s, Label: %s (%s), S/N: %s, Num. RCs: %s" % tuple(pdu))

    return (3, "Device can not be found in SNMP output.")


check_info["lgp_pdu_info"] = {
    "check_function": check_lgp_pdu_info,
    "inventory_function": inventory_lgp_pdu_info,
    "service_description": "Liebert PDU Info %s",
    "snmp_info": (
        ".1.3.6.1.4.1.476.1.42.3.8.20.1",
        [
            5,  # LIEBERT-GP-PDU-MIB::lgpPduEntryId
            10,  # LIEBERT-GP-PDU-MIB::lgpPduEntryUsrLabel
            15,  # LIEBERT-GP-PDU-MIB::lgpPduEntrySysAssignLabel
            45,  # LIEBERT-GP-PDU-MIB::lgpPduEntrySerialNumber
            50,  # LIEBERT-GP-PDU-MIB::lgpPduEntryRbCount
        ],
    ),
    "snmp_scan_function": lambda oid: oid(".1.3.6.1.2.1.1.2.0") == ".1.3.6.1.4.1.476.1.42",
}
