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

# NOTE: Careful when replacing the *-import below with a more specific import. This can cause
# problems because it might remove variables from the check-context which are necessary for
# resolving legacy discovery results such as [("SUMMARY", "diskstat_default_levels")]. Furthermore,
# it might also remove variables needed for accessing discovery rulesets.
from cmk.base.check_legacy_includes.enviromux import *  # pylint: disable=wildcard-import,unused-wildcard-import

# NOTE: Careful when replacing the *-import below with a more specific import. This can cause
# problems because it might remove variables from the check-context which are necessary for
# resolving legacy discovery results such as [("SUMMARY", "diskstat_default_levels")]. Furthermore,
# it might also remove variables needed for accessing discovery rulesets.
from cmk.base.check_legacy_includes.humidity import *  # pylint: disable=wildcard-import,unused-wildcard-import

# NOTE: Careful when replacing the *-import below with a more specific import. This can cause
# problems because it might remove variables from the check-context which are necessary for
# resolving legacy discovery results such as [("SUMMARY", "diskstat_default_levels")]. Furthermore,
# it might also remove variables needed for accessing discovery rulesets.
from cmk.base.check_legacy_includes.temperature import *  # pylint: disable=wildcard-import,unused-wildcard-import

# .
#   .--temperature---------------------------------------------------------.
#   |      _                                      _                        |
#   |     | |_ ___ _ __ ___  _ __   ___ _ __ __ _| |_ _   _ _ __ ___       |
#   |     | __/ _ \ '_ ` _ \| '_ \ / _ \ '__/ _` | __| | | | '__/ _ \      |
#   |     | ||  __/ | | | | | |_) |  __/ | | (_| | |_| |_| | | |  __/      |
#   |      \__\___|_| |_| |_| .__/ \___|_|  \__,_|\__|\__,_|_|  \___|      |
#   |                       |_|                                            |
#   +----------------------------------------------------------------------+
#   |                                                                      |
#   '----------------------------------------------------------------------'

factory_settings["enviromux_default_levels"] = ENVIROMUX_CHECK_DEFAULT_PARAMETERS

check_info["enviromux"] = {
    "parse_function": parse_enviromux,
    "inventory_function": inventory_enviromux_temperature,
    "check_function": check_enviromux_temperature,
    "service_description": "Sensor %s",
    "snmp_info": (
        ".1.3.6.1.4.1.3699.1.1.11.1.3.1.1",
        [
            "1",  # intSensorIndex
            "2",  # intSensorType
            "3",  # intSensorDescription
            "4",  # intSensorGroupNb
            "5",  # intSensorGroup
            "6",  # intSensorValue
            "7",  # intSensorUnit
            "8",  # intSensorUnitName
            "9",  # intSensorStatus
            "10",  # intSensorMinThreshold
            "11",  # intSensorMaxThreshold
            # These appear to only return bogus values
            # "12", # intSensorMinWarnThreshold
            # "13", # intSensorMaxWarnThreshold
        ],
    ),
    "has_perfdata": True,
    "snmp_scan_function": enviromux_scan_function,
    "group": "temperature",
}

# .
#   .--Voltage-------------------------------------------------------------.
#   |                 __     __    _ _                                     |
#   |                 \ \   / /__ | | |_ __ _  __ _  ___                   |
#   |                  \ \ / / _ \| | __/ _` |/ _` |/ _ \                  |
#   |                   \ V / (_) | | || (_| | (_| |  __/                  |
#   |                    \_/ \___/|_|\__\__,_|\__, |\___|                  |
#   |                                         |___/                        |
#   +----------------------------------------------------------------------+
#   |                                                                      |
#   '----------------------------------------------------------------------'

check_info["enviromux.voltage"] = {
    "inventory_function": inventory_enviromux_voltage,
    "check_function": check_enviromux_voltage,
    "service_description": "Sensor %s",
    "has_perfdata": True,
    "group": "voltage",
    "default_levels_variable": "enviromux_default_levels",
}

# .
#   .--Humidity------------------------------------------------------------.
#   |              _   _                 _     _ _ _                       |
#   |             | | | |_   _ _ __ ___ (_) __| (_) |_ _   _               |
#   |             | |_| | | | | '_ ` _ \| |/ _` | | __| | | |              |
#   |             |  _  | |_| | | | | | | | (_| | | |_| |_| |              |
#   |             |_| |_|\__,_|_| |_| |_|_|\__,_|_|\__|\__, |              |
#   |                                                  |___/               |
#   +----------------------------------------------------------------------+
#   |                                                                      |
#   '----------------------------------------------------------------------'

check_info["enviromux.humidity"] = {
    "inventory_function": inventory_enviromux_humidity,
    "check_function": check_enviromux_humidity,
    "service_description": "Sensor %s",
    "has_perfdata": True,
    "group": "humidity",
}
