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


# this is currently here only to prevent error messages when upgrading
factory_settings["adva_fsp_temp_default_levels"] = {}


def inventory_adva_fsp_temp(info):
    for line in info:
        # Ignore unconnected sensors
        if len(line) == 5 and line[0] != "" and line[4] != "" and int(line[0]) >= -2730:
            yield line[4], {}

def check_adva_fsp_temp(item, params, info):
    for line in info:
        if len(line) == 5 and line[4] == item:
            temp, high, low, descr = line[0:4]
            temp = float(temp) / 10
            high = float(high) / 10
            low = float(low) / 10

            if temp <= -2730:
                return 3, "Invalid sensor data"

            if low > -273:
                return check_temperature(
                    temp, params, "adva_fsp_temp_%s" % item,
                    dev_levels=(high, high), dev_levels_lower=(low, low))
            else:
                return check_temperature(
                    temp, params, "adva_fsp_temp_%s" % item,
                    dev_levels=(high, high))

check_info['adva_fsp_temp'] = {
    "inventory_function"      : inventory_adva_fsp_temp,
    "check_function"          : check_adva_fsp_temp,
    "service_description"     : "Temperature %s",
    "has_perfdata"            : True,
    "snmp_info"               : ( ".1.3.6.1.4.1.2544", [
                                    "1.11.2.4.2.1.1.1", # moduleDiagnosticsTemp
                                    "1.11.2.4.2.1.1.2", # moduleDiagnosticsUpperTempThres
                                    "1.11.2.4.2.1.1.3", # moduleDiagnosticsLowerTempThres
                                    "2.5.5.1.1.1",
                                    "2.5.5.2.1.5",
                                    #"2.5.5.1.1.10",
                              ]),
    "snmp_scan_function"      : lambda oid:
                                oid(".1.3.6.1.2.1.1.1.0") == "Fiber Service Platform F7",
    "group"                   : "temperature",
    "includes"                : [ "temperature.include" ],
    "default_levels_variable" : "adva_fsp_temp_default_levels"
}
