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

# Author: Lars Michelsen <lm@mathias-kettner.de>

# General Status:
# '.1.3.6.1.4.1.232.22.2.3.1.1.1.5'  => 'cpqRackCommonEnclosurePartNumber',
# '.1.3.6.1.4.1.232.22.2.3.1.1.1.6'  => 'cpqRackCommonEnclosureSparePartNumber',
# '.1.3.6.1.4.1.232.22.2.3.1.1.1.7'  => 'cpqRackCommonEnclosureSerialNum',
# '.1.3.6.1.4.1.232.22.2.3.1.1.1.8'  => 'cpqRackCommonEnclosureFWRev',
# '.1.3.6.1.4.1.232.22.2.3.1.1.1.16' => 'cpqRackCommonEnclosureCondition',

# GENERAL MAPS:

hp_blade_status_map = {1: 'Other', 2: 'Ok', 3: 'Degraded', 4: 'Failed'}
hp_blade_status2nagios_map = {
    'Other': 2,
    'Ok': 0,
    'Degraded': 1,
    'Failed': 2,
}


def inventory_hp_blade_general(info):
    if len(info) > 0 and len(info[0]) > 1:
        return [(None, None)]


def check_hp_blade_general(item, params, info):
    snmp_state = hp_blade_status_map[int(info[0][1])]
    status = hp_blade_status2nagios_map[snmp_state]
    return (status,
            "General Status is %s (Firmware: %s, S/N: %s)" % (snmp_state, info[0][0], info[0][2]))


check_info["hp_blade"] = {
    'check_function': check_hp_blade_general,
    'inventory_function': inventory_hp_blade_general,
    'service_description': 'General Status',
    'snmp_info': ('.1.3.6.1.4.1.232.22.2.3.1.1.1', ['8', '16', '7']),
    'snmp_scan_function': lambda oid: ".11.5.7.1.2" in oid(".1.3.6.1.2.1.1.2.0"),
}
