#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# +------------------------------------------------------------------+
# |             ____ _               _        __  __ _  __           |
# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
# |                                                                  |
# | Copyright Mathias Kettner 2013             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.
"""
        airIRRCUnitStatusOperateMode                    SCALAR  read-only       INTEGER 1.3.6.1.4.1.318.1.1.13.3.2.2.2.1.0
        airIRRCUnitStatusCoolOutput                     SCALAR  read-only       INTEGER 1.3.6.1.4.1.318.1.1.13.3.2.2.2.2.0
        airIRRCUnitStatusCoolDemand                     SCALAR  read-only       INTEGER 1.3.6.1.4.1.318.1.1.13.3.2.2.2.3.0
        airIRRCUnitStatusAirFlowUS                      SCALAR  read-only       INTEGER 1.3.6.1.4.1.318.1.1.13.3.2.2.2.4.0
        airIRRCUnitStatusAirFlowMetric                  SCALAR  read-only       INTEGER 1.3.6.1.4.1.318.1.1.13.3.2.2.2.5.0
        airIRRCUnitStatusRackInletTempUS                SCALAR  read-only       INTEGER 1.3.6.1.4.1.318.1.1.13.3.2.2.2.6.0
        airIRRCUnitStatusRackInletTempMetric            SCALAR  read-only       INTEGER 1.3.6.1.4.1.318.1.1.13.3.2.2.2.7.0
        airIRRCUnitStatusSupplyAirTempUS                SCALAR  read-only       INTEGER 1.3.6.1.4.1.318.1.1.13.3.2.2.2.8.0
        airIRRCUnitStatusSupplyAirTempMetric            SCALAR  read-only       INTEGER 1.3.6.1.4.1.318.1.1.13.3.2.2.2.9.0
        airIRRCUnitStatusReturnAirTempUS                SCALAR  read-only       INTEGER 1.3.6.1.4.1.318.1.1.13.3.2.2.2.10.0
        airIRRCUnitStatusReturnAirTempMetric            SCALAR  read-only       INTEGER 1.3.6.1.4.1.318.1.1.13.3.2.2.2.11.0
        airIRRCUnitStatusContainmtDPUS                  SCALAR  read-only       INTEGER 1.3.6.1.4.1.318.1.1.13.3.2.2.2.12.0
        airIRRCUnitStatusContainmtDPMetric              SCALAR  read-only       INTEGER 1.3.6.1.4.1.318.1.1.13.3.2.2.2.13.0
        airIRRCUnitStatusFilterDPUS                     SCALAR  read-only       INTEGER 1.3.6.1.4.1.318.1.1.13.3.2.2.2.14.0
        airIRRCUnitStatusFilterDPMetric                 SCALAR  read-only       INTEGER 1.3.6.1.4.1.318.1.1.13.3.2.2.2.15.0
        airIRRCUnitStatusFanSpeed                       SCALAR  read-only       INTEGER 1.3.6.1.4.1.318.1.1.13.3.2.2.2.16.0
        airIRRCUnitStatusInputState                     SCALAR  read-only       INTEGER 1.3.6.1.4.1.318.1.1.13.3.2.2.2.17.0
        airIRRCUnitStatusOutputState                    SCALAR  read-only       INTEGER 1.3.6.1.4.1.318.1.1.13.3.2.2.2.18.0
        airIRRCUnitStatusActivePowerSource              SCALAR  read-only       INTEGER 1.3.6.1.4.1.318.1.1.13.3.2.2.2.19.0
        airIRRCUnitStatusFluidValvePosition             SCALAR  read-only       INTEGER 1.3.6.1.4.1.318.1.1.13.3.2.2.2.20.0
        airIRRCUnitStatusFluidFlowUS                    SCALAR  read-only       INTEGER 1.3.6.1.4.1.318.1.1.13.3.2.2.2.21.0
        airIRRCUnitStatusFluidFlowMetric                SCALAR  read-only       INTEGER 1.3.6.1.4.1.318.1.1.13.3.2.2.2.22.0
        airIRRCUnitStatusEnteringFluidTemperatureUS     SCALAR  read-only       INTEGER 1.3.6.1.4.1.318.1.1.13.3.2.2.2.23.0
        airIRRCUnitStatusEnteringFluidTemperatureMetric SCALAR  read-only       INTEGER 1.3.6.1.4.1.318.1.1.13.3.2.2.2.24.0
        airIRRCUnitStatusLeavingFluidTemperatureUS      SCALAR  read-only       INTEGER 1.3.6.1.4.1.318.1.1.13.3.2.2.2.25.0
        airIRRCUnitStatusLeavingFluidTemperatureMetric  SCALAR  read-only       INTEGER 1.3.6.1.4.1.318.1.1.13.3.2.2.2.26.0
"""

def apc_inrow_temp_convert(info):
    vars = [
            "Rack Inlet",
            "Supply Air",
            "Return Air",
            "Entering Fluid",
            "Leaving Fluid",
            ]
    count = 0
    data = {}
    for name in vars:
        if info[count] != "-1":
            value = saveint(info[count])
            data[name] = value / 10.0
        count += 1
    return data

apc_inrow_temp_default_levels = ( 30, 35 )
def inventory_apc_inrow_temp(info):
    info = apc_inrow_temp_convert(info)
    return [ (x, "apc_inrow_temp_default_levels") for x in info.keys() ]

def check_apc_inrow_temp(item, params, info):
    info = apc_inrow_temp_convert(info)
    for sensor, value in info.items():
        if sensor == item:
            warn, crit = params
            levels = " (Warning/Critical at %.2f/%2f°C)" % ( warn, crit)
            message = "Current: %.2f°C" % value
            perf = [ ('temp', value, warn, crit ) ]
            if value > crit:
                return 2, message + levels, perf
            if value > warn:
                return 1, message + levels, perf
            return 0, message, perf

    return 3, "Sensor not found"

check_info["apc_inrow_temp"] = {
    "check_function"        : check_apc_inrow_temp,
    "inventory_function"    : inventory_apc_inrow_temp,
    "service_description"   : "Temperature %s",
    "group"                 : "hw_temperature",
    "snmp_info"             : (".1.3.6.1.4.1.318.1.1.13.3.2.2.2", [ 7, 9, 11, 24, 26  ]),
    "snmp_scan_function"    : lambda oid: oid(".1.3.6.1.2.1.1.2.0") == ".1.3.6.1.4.1.318.1.3.14.5",
    "has_perfdata"          : True,
}

