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

from cmk.base.check_legacy_includes import qnap
from cmk.base.check_legacy_includes.temperature import check_temperature

factory_settings["qnap_hdd_temp_default_levels"] = {
    "levels": (40, 45),
}


def parse_qnap_hdd_temp(info):
    parsed = {}
    for hdd, temp in info:
        try:
            temp = float(temp.split()[0])
            parsed[hdd] = temp
        except ValueError:
            pass
    return parsed


@get_parsed_item_data
def check_qqnap_hdd_temp(item, params, data):
    yield check_temperature(reading=data, unique_name=item, params=params)


check_info["qnap_hdd_temp"] = {
    "inventory_function": discover(),
    "parse_function": parse_qnap_hdd_temp,
    "check_function": check_qqnap_hdd_temp,
    "service_description": "QNAP %s Temperature",
    "snmp_info": (".1.3.6.1.4.1.24681.1.2.11.1", ["2", "3"]),
    "snmp_scan_function": qnap.scan,
    "has_perfdata": True,
    "default_levels_variable": "qnap_hdd_temp_default_levels",
    "group": "temperature",
}
