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

import cmk.base.plugins.agent_based.utils.pulse_secure as pulse_secure

# 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.cpu_util import *  # pylint: disable=wildcard-import,unused-wildcard-import

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

KEY_PULSE_SECURE_CPU = "cpu_util"


def check_pulse_secure_cpu(item, params, parsed):

    if not parsed:
        return None

    return check_cpu_util(parsed[KEY_PULSE_SECURE_CPU], params, this_time=time.time())


check_info["pulse_secure_cpu_util"] = {
    "parse_function": lambda info: pulse_secure.parse_pulse_secure(info, KEY_PULSE_SECURE_CPU),
    "inventory_function": discover_single,
    "check_function": check_pulse_secure_cpu,
    "service_description": "Pulse Secure IVE CPU utilization",
    "has_perfdata": True,
    "snmp_info": (
        ".1.3.6.1.4.1.12532",
        [
            "10",  # iveCpuUtil
        ],
    ),
    "snmp_scan_function": pulse_secure.scan_pulse_secure,
    "group": "cpu_utilization",
    "default_levels_variable": "pulse_secure_cpu_util_def_levels",
}
