#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# +------------------------------------------------------------------+
# |             ____ _               _        __  __ _  __           |
# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
# |                                                                  |
# | Copyright Mathias Kettner 2014             mk@mathias-kettner.de |
# +------------------------------------------------------------------+
#
# This file is part of Check_MK.
# The official homepage is at http://mathias-kettner.de/check_mk.
#
# check_mk is free software;  you can redistribute it and/or modify it
# under the  terms of the  GNU General Public License  as published by
# the Free Software Foundation in version 2.  check_mk is  distributed
# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
# ails.  You should have  received  a copy of the  GNU  General Public
# License along with GNU Make; see the file  COPYING.  If  not,  write
# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
# Boston, MA 02110-1301 USA.


def inventory_quantum_libsmall_status(info):
    if info:
        return [ (None, None) ]


def check_quantum_libsmall_status(_no_item, _no_params, info):

    ras_status = {
        1 : (0, "good"),
        2 : (2, "failed"),
        3 : (2, "degraded"),
        4 : (1, "warning"),
        5 : (0, "informational"),
        6 : (3, "unknown"),
        7 : (3, "invalid"),
    }

    opneed_status = {
        0 : (0, "no"),
        1 : (2, "yes"),
    }

    oidtothing = {
        "1" : (ras_status, "Power"),
        "2" : (ras_status, "Cooling"),
        "3" : (ras_status, "Control"),
        "4" : (ras_status, "Connectivity"),
        "5" : (ras_status, "Robotics"),
        "6" : (ras_status, "Media"),
        "7" : (ras_status, "Drive"),
        "8" : (opneed_status, "Operator action request"),
    }

    for oidend, devstate in info:
        stateint = int(devstate)
        interpret, thing = oidtothing[oidend[0]]
        status, statname = interpret[stateint]
        yield status, thing + ": " + statname


check_info['quantum_libsmall_status'] = {
    "check_function"          : check_quantum_libsmall_status,
    "inventory_function"      : inventory_quantum_libsmall_status,
    "service_description"     : "Tape library status",
    "snmp_info"               : (".1.3.6.1.4.1.3697.1.10.10.1.15", [
                                    OID_END,
                                    "10",
                                ]),
    "snmp_scan_function"      : lambda oid: "library" in oid(".1.3.6.1.2.1.1.6.0").lower(),
}

