#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (C) 2019 tribe29 GmbH - License: GNU General Public License v2
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.


def inventory_kentix_humidity(info):
    if info:
        return [(None, None)]


def check_kentix_humidity(_no_item, _no_params, info):
    info[0][0] = info[0][0].split(".", 3)[-1]
    value, lower_warn, upper_warn, _alarm, text = info[0]
    temp = float(value) / 10
    perfdata = [("humidity", temp, lower_warn + ":" + upper_warn)]
    upper_warn = float(upper_warn)
    lower_warn = float(lower_warn)
    infotext = "%.1f%% (min/max at %.1f%%/%.1f%%)" % (temp, lower_warn, upper_warn)
    if temp >= upper_warn or temp <= lower_warn:
        state = 1
        infotext = "%s:  %s" % (text, infotext)
    else:
        state = 0
    return state, infotext, perfdata


check_info["kentix_humidity"] = {
    "check_function": check_kentix_humidity,
    "inventory_function": inventory_kentix_humidity,
    "service_description": "Humidity",
    "has_perfdata": True,
    "snmp_info": (
        ".1.3.6.1.4.1.37954",
        ["2.1.2", "3.1.2"],
        [
            "1",  # humidityValue
            "2",  # humidityMin
            "3",  # humidityMax
            "4",  # humidityAlarm, not used
            "5",  # humidityAlarmtext
        ],
    ),
    "snmp_scan_function": lambda oid: oid(".1.3.6.1.2.1.1.2.0").startswith(".1.3.6.1.4.1.332.11.6"),
}
