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

#
# 2017 comNET GmbH, Bjoern Mueller

# Default levels from http://www.detectcarbonmonoxide.com/co-health-risks/

factory_settings["kentix_co"] = {
    "levels_ppm": (10, 25),
}


def inventory_kentix_co(info):
    if info:
        yield None, {}


def check_kentix_co(item, params, info):
    warn, crit = params["levels_ppm"]
    value = info[0][0].split(".", 3)[-1]
    infotext = "CO value at %s ppm (parts per million)" % value
    value = int(value)
    perfdata = [("parts_per_million", value, warn, crit)]
    if value >= crit:
        yield 2, infotext, perfdata
    elif value >= warn:
        yield 1, infotext, perfdata
    else:
        yield 0, infotext, perfdata


check_info["kentix_co"] = {
    "inventory_function": inventory_kentix_co,
    "check_function": check_kentix_co,
    "default_levels_variable": "kentix_co",
    "service_description": "Carbon Monoxide",
    "has_perfdata": True,
    "snmp_info": (
        ".1.3.6.1.4.1.37954",
        ["2.1.4", "3.1.3"],
        [
            "1",  # coValue
        ],
    ),
    "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"),
    "group": "carbon_monoxide",
}
