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

dell_om_sensors_default_levels = (50, 60)


def dell_om_sensors_item(name):
    return name.replace("Temp", "").strip()


def inventory_dell_om_sensors(info):
    return [ (dell_om_sensors_item(line[4]), "dell_om_sensors_default_levels") for line in info ]


def check_dell_om_sensors(item, params, info):
    #Probetypes found in check_openmanage3.pl
    probe_types = {
         1  : 'Other',      # type is other than following values
         2  : 'Unknown',    # type is unknown
         3  : 'AmbientESM', # type is Ambient Embedded Systems Management temperature probe
         16 : 'Discrete',   # type is temperature probe with discrete reading
    }
    for idx, sensor_state, reading, sensor_type, location_name in info:
        if item == idx or dell_om_sensors_item(location_name) == item:
            if params == None:
                params = dell_om_sensors_default_levels # compatibility with old autochecks
            temp = int(reading) / 10.0

            yield check_temperature(temp, params)

            if item == idx: # old style item: output location name
                yield 0, "%s, Type: %s" % (location_name, probe_types[int(sensor_type)])

            if int(sensor_state) != 3:
                yield 2, "in critical state"


check_info["dell_om_sensors"] = {
    "check_function"        : check_dell_om_sensors,
    "inventory_function"    : inventory_dell_om_sensors,
    "service_description"   : "Temperature %s",
    "has_perfdata"          : True,
    "group"                 : "room_temperature",
    # There is no other way to find out that openmanage is present.
    "snmp_scan_function"    : scan_dell_om,
    "snmp_info"             : ( ".1.3.6.1.4.1.674.10892.1.700.20.1", [
                                        '2', # ProbeIndex
                                        '5', # ProbeStatus
                                        '6', # ProbeReading
                                        '7', # ProbeType
                                        '8', # ProbeLocationName
                                        #'10.1', # ProbeUpperCriticalThreshold',
                                        #'11.1', # ProbeUpperNonCriticalThreshold',
                                        #'12.1', # ProbeLowerNonCriticalThreshold',
                                        #'13.1', # ProbeLowerCriticalThreshold',
                                        #'16.1', # ProbeDiscreteReading',
                              ]),
    "includes"              : [ "dell_om.include", "temperature.include" ],
}

