#!/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_cmciii_lcp_airin(info):
    if info:
        return [( None, None )]

def check_cmciii_lcp_airin(item, params, info):
    unit_desc, unit_status, desc, status = info[0][0:4]
    temps = cmciii_extract_temps(info[0][4:])

    state = 0
    sym = ""
    if status.lower() != "ok" or unit_status.lower() != "ok":
        if status.lower() in ( "ok", "warning" ) and \
                unit_status.lower() in  ( "ok", "warning" ):
            state = 1
        else:
            state = 2
    if temps[4] < temps[0] or temps[4] > temps[3] :
        state = 2
        sym = "(!!)"
    elif temps[4] < temps[1] or temps[4] > temps[2]:
        state = max(state, 1)
        sym = "(!)"
    else:
        state = max(state, 0)

    info_text = "%s %s %s %s, Temp.Average: %.1f°C%s, Top/Mid/Bottom: %.1f/%.1f/%.1f" % \
                    (unit_desc, unit_status, desc, status, temps[4], sym, temps[5], temps[6], temps[7])

    levels_text = ", lowcrit/lowwarn/highwarn/highcrit: %.1f/%.1f/%.1f/%.1f" % ( temps[0], temps[1], temps[2], temps[3] )

    perfdata = [ ("temp", temps[4], str(temps[1])+":"+str(temps[2]), str(temps[0])+":"+str(temps[3]), 0 ) ]

    return (state, info_text + levels_text, perfdata)

check_info['cmciii_lcp_airin'] = {
    "check_function"      : check_cmciii_lcp_airin,
    "inventory_function"  : inventory_cmciii_lcp_airin,
    "has_perfdata"        : True,
    "service_description" : "LCP Fanunit Air IN",
    "snmp_scan_function"  : lambda oid: oid(".1.3.6.1.2.1.1.1.0").startswith("Rittal LCP") and \
                                oid(".1.3.6.1.4.1.2606.7.4.2.2.1.3.2.6").startswith("Air.Temperature.DescName"),
    "snmp_info"           : ( '.1.3.6.1.4.1.2606.7.4.2.2.1.10',
       [ '2.6', '2.13', '2.15', '2.23', '2.21', '2.20', '2.19', '2.18', '2.17', '2.7', '2.8', '2.9' ]
    ),
    "includes"            : [ 'cmciii.include' ],
}
#
# .1.3.6.1.4.1.2606.7.4.2.2.1.3.2.6 Air.Temperature.DescName
# .1.3.6.1.4.1.2606.7.4.2.2.1.3.2.7 Air.Temperature.In-Top
# .1.3.6.1.4.1.2606.7.4.2.2.1.3.2.8 Air.Temperature.In-Mid
# .1.3.6.1.4.1.2606.7.4.2.2.1.3.2.9 Air.Temperature.In-Bot
# .1.3.6.1.4.1.2606.7.4.2.2.1.3.2.10 Air.Temperature.Out-Top
# .1.3.6.1.4.1.2606.7.4.2.2.1.3.2.11 Air.Temperature.Out-Mid
# .1.3.6.1.4.1.2606.7.4.2.2.1.3.2.12 Air.Temperature.Out-Bot
# .1.3.6.1.4.1.2606.7.4.2.2.1.3.2.13 Air.Temperature.Status
# .1.3.6.1.4.1.2606.7.4.2.2.1.3.2.14 Air.Temperature.Category
# .1.3.6.1.4.1.2606.7.4.2.2.1.3.2.15 Air.Server-In.DescName
# .1.3.6.1.4.1.2606.7.4.2.2.1.3.2.16 Air.Server-In.Setpoint
# .1.3.6.1.4.1.2606.7.4.2.2.1.3.2.17 Air.Server-In.Average
# .1.3.6.1.4.1.2606.7.4.2.2.1.3.2.18 Air.Server-In.SetPtHighAlarm
# .1.3.6.1.4.1.2606.7.4.2.2.1.3.2.19 Air.Server-In.SetPtHighWarning
# .1.3.6.1.4.1.2606.7.4.2.2.1.3.2.20 Air.Server-In.SetPtLowWarning
# .1.3.6.1.4.1.2606.7.4.2.2.1.3.2.21 Air.Server-In.SetPtLowAlarm
# .1.3.6.1.4.1.2606.7.4.2.2.1.3.2.22 Air.Server-In.Hysteresis
# .1.3.6.1.4.1.2606.7.4.2.2.1.3.2.23 Air.Server-In.Status
# .1.3.6.1.4.1.2606.7.4.2.2.1.3.2.24 Air.Server-In.Category
# .1.3.6.1.4.1.2606.7.4.2.2.1.3.2.25 Air.Server-Out.DescName
# .1.3.6.1.4.1.2606.7.4.2.2.1.3.2.26 Air.Server-Out.Average
# .1.3.6.1.4.1.2606.7.4.2.2.1.3.2.27 Air.Server-Out.SetPtHighAlarm
# .1.3.6.1.4.1.2606.7.4.2.2.1.3.2.28 Air.Server-Out.SetPtHighWarning
# .1.3.6.1.4.1.2606.7.4.2.2.1.3.2.29 Air.Server-Out.SetPtLowWarning
# .1.3.6.1.4.1.2606.7.4.2.2.1.3.2.30 Air.Server-Out.SetPtLowAlarm
# .1.3.6.1.4.1.2606.7.4.2.2.1.3.2.31 Air.Server-Out.Hysteresis
# .1.3.6.1.4.1.2606.7.4.2.2.1.3.2.32 Air.Server-Out.Status
# .1.3.6.1.4.1.2606.7.4.2.2.1.3.2.33 Air.Server-Out.Category
#
