#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# +------------------------------------------------------------------+
# |             ____ _               _        __  __ _  __           |
# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
# |                                                                  |
# | Copyright Mathias Kettner 2016             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-
# tails. 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.


# .1.3.6.1.4.1.19011.1.3.2.1.3.1.1.1.2.1 "Temperature-R" --> ISPRO-MIB::isDeviceMonitorTemperatureName
# .1.3.6.1.4.1.19011.1.3.2.1.3.1.1.1.3.1 2230 --> ISPRO-MIB::isDeviceMonitorTemperature
# .1.3.6.1.4.1.19011.1.3.2.1.3.1.1.1.4.1 3 --> ISPRO-MIB::isDeviceMonitorTemperatureAlarm
# .1.3.6.1.4.1.19011.1.3.2.1.3.2.2.1.3.1 2300 --> ISPRO-MIB::isDeviceConfigTemperatureLowWarning
# .1.3.6.1.4.1.19011.1.3.2.1.3.2.2.1.4.1 2000 --> ISPRO-MIB::isDeviceConfigTemperatureLowCritical
# .1.3.6.1.4.1.19011.1.3.2.1.3.2.2.1.5.1 3000 --> ISPRO-MIB::isDeviceConfigTemperatureHighWarning
# .1.3.6.1.4.1.19011.1.3.2.1.3.2.2.1.6.1 3800 --> ISPRO-MIB::isDeviceConfigTemperatureHighCritical


def inventory_ispro_sensors_temp(info):
    return [ (line[0], {}) for line in info if line[2] not in [ "1", "2" ] ]


def check_ispro_sensors_temp(item, params, info):
    for name, reading_str, status, warn_low, crit_low, warn, crit in info:
        if item == name:
            devstatus, devstatus_name = ispro_sensors_alarm_states(status)
            return check_temperature(
                        float(reading_str) / 100.0, params,
                        "ispro_sensors_temp_%s" % item,
                        dev_levels =       (float(warn)/100.0,     float(crit)/100.0),
                        dev_levels_lower = (float(warn_low)/100.0, float(crit_low)/100.0),
                        dev_status =       devstatus,
                        dev_status_name =  devstatus_name)


check_info['ispro_sensors_temp'] = {
    'inventory_function'    : inventory_ispro_sensors_temp,
    'check_function'        : check_ispro_sensors_temp,
    'service_description'   : 'Temperature %s',
    'snmp_info'             : ('.1.3.6.1.4.1.19011.1.3.2.1.3', [
                                    "1.1.1.2",    # ISPRO-MIB::isDeviceMonitorTemperatureName
                                    "1.1.1.3",    # ISPRO-MIB::isDeviceMonitorTemperature (unit is 0.01 degree)
                                    "1.1.1.4",    # ISPRO-MIB::isDeviceMonitorTemperatureAlarm
                                    "2.2.1.3",    # ISPRO-MIB::isDeviceConfigTemperatureLowWarning
                                    "2.2.1.4",    # ISPRO-MIB::isDeviceConfigTemperatureLowCritical
                                    "2.2.1.5",    # ISPRO-MIB::isDeviceConfigTemperatureHighWarning
                                    "2.2.1.6",    # ISPRO-MIB::isDeviceConfigTemperatureHighCritical
                              ]),
    'snmp_scan_function'    : ispro_scan_function,
    'has_perfdata'          : True,
    'group'                 : 'temperature',
    'includes'              : [ 'ispro.include', 'temperature.include' ],
}
