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


hwg_humidity_defaultlevels = (0, 0, 60, 70)

def inventory_hwg_humidity(info):
    return [ (line[0], "hwg_humidity_defaultlevels")
              for line in info
              if int(line[2]) != 0 and line[4] in ["4"] ]


def check_hwg_humidity(item, params, info):
#    status_text = {
#        "0" : "Invalid",
#        "1" : "Normal",
#        "2" : "Out Of Range Low",
#        "3" : "Out Of Range High",
#        "4" : "Alarm Low",
#        "5" : "Alarm High",
#    }

    # Nomenclature in this check: sensorstatus is what the device sends, status is what the check returns.
    for index, descr, sensorstatus, current, unit in info:
        if index == item:
            if unit != "4":
                return

            humidity = float(current)
            status, infotext, perfdata = check_humidity(humidity, params)
            if descr:
                infotext += " (%s)" % descr
            return status, infotext, perfdata



check_info['hwg_humidity'] = {
    "check_function"          : check_hwg_humidity,
    "inventory_function"      : inventory_hwg_humidity,
    "service_description"     : "Humidity %s",
    "has_perfdata"            : True,
    "snmp_info" : (".1.3.6.1.4.1.21796.4.1.3", [# sensors index (1-2)
            "1.1",
            # sensor name string
            "1.2",
            # unit state: 0=Invalid, 1=Normal, 2=OutOfRangeLo, 3=OutOfRangeHi, 4=AlarmLo, 5=AlarmHi
            "1.3",
            # current value string
            "1.4",
            # sensor unit integer 0=unknown, 1=°C, 2=°F, 3=°K, 4=%
            "1.7",
   ]),
   "snmp_scan_function"       : lambda oid: "hwg" in oid(".1.3.6.1.2.1.1.1.0").lower(),
   "group"                    : "humidity",
   "includes"                 : [ "humidity.include" ],
}

