#!/usr/bin/python
# -*- coding: utf-8; py-indent-offset: 4 -*-
#  _______ __   _ ____     __
# |       |  \ | |___ \   / /
# |       |   \| | __) | / /-,_
# |       | |\   |/ __/ /__   _|
# |_______|_| \__|_____|   |_|
#
# @author Markus Birth <markus.birth@weltn24.de>
# MIBs: ftp://ftp.snellgroup.com/RollCall/SNMP_MIBs/

factory_settings["snell_iqh_temp_default_levels"] = {
    "levels": (36, 39), # levels for system temperature
}

def inventory_snell_iqh_temp(info):
    inventory = []
    for i in range(0, len(info)):
        for oidend, tname, ttemp, tstate in info[i]:
            if tname != "0":
                inventory.append( (tname, None) )
    return inventory

def check_snell_iqh_temp(item, params, info):
    for i in range(0, len(info)):
        for oidend, tname, ttemp, tstate in info[i]:
            if tname == item:
                message = u"%s - %s℃" % (tstate, ttemp)
                # 36°C = warning / 39°C = critical (should be signaled from the system itself)
                if ( tstate == "OK" or tstate == "" ) and saveint("0"+ttemp)<39:
                    status = 0
                else:
                    status = 2

                perfdata = []
                if ttemp != "":
                    perfdata = [ (tname.replace(" ", "_"), saveint(ttemp), None, None, 0, 50) ]

                return status, message, perfdata
    return 3, "%s not found in SNMP data." % (item)

check_info["snell_iqh_temp"] = {
    "check_function"          : check_snell_iqh_temp,
    "inventory_function"      : inventory_snell_iqh_temp,
    "service_description"     : "%s",
    "group"                   : "temperature",
    "default_levels_variable" : "snell_iqh_temp_default_levels",
    "snmp_info"               : [(".1.3.6.1.4.1.7995.1.3.1", [ "429.1.1", "475.1.1" ], [
                                    OID_END,
                                     2022,    # temp1name
                                     2008,    # temp1Celsius
                                     2003,    # temp1State
                                ]), (".1.3.6.1.4.1.7995.1.3.1", [ "429.1.1", "475.1.1" ], [
                                    OID_END,
                                     2023,    # temp2name
                                     2009,    # temp2Celsius
                                     2004,    # temp2State
                                ])],
    "snmp_scan_function"      : lambda oid: oid(".1.3.6.1.2.1.1.2.0").startswith(".1.3.6.1.4.1.7995.1.3"),
    "has_perfdata"            : True
}
