#!/usr/bin/env python3
# Copyright (C) 2019 Checkmk 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 needed for accessing discovery rulesets.
from cmk.base.check_legacy_includes.cpu_util 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 needed for accessing discovery rulesets.
from cmk.base.check_legacy_includes.datapower_scan import *  # pylint: disable=wildcard-import,unused-wildcard-import

factory_settings["datapower_cpu_default_levels"] = {"util": (80.0, 90.0)}


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


def check_datapower_cpu(_no_item, params, info):
    util = int(info[0][0])
    return check_cpu_util(util, params)


check_info["datapower_cpu"] = {
    "inventory_function": inventory_datapower_cpu,
    "check_function": check_datapower_cpu,
    "service_description": "CPU Utilization",
    "snmp_info": (
        ".1.3.6.1.4.1.14685.3.1.14",
        [
            "2",  # dpStatusCPUUsageoneMinute
        ],
    ),
    "snmp_scan_function": scan_datapower,
    "group": "cpu_utilization",
    "default_levels_variable": "datapower_cpu_default_levels",
    "has_perfdata": True,
}
