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

juniper_cpu_default_levels = (80.0, 90.0)


def inventory_juniper_cpu(info):
    return []


def check_juniper_cpu(item, params, info):
    for line in info:
        if line[0] == item:
            # this check was using cpu load readings falsely reporting them
            # as utilization. Since the device doesn't seem to report the number
            # of available cpu cores, load monitoring isn't properly doable
            return 3, "This check is obsolete and has been replaced, " \
                "please re-discover service on this host"


check_info["juniper_cpu"] = {
    "check_function": check_juniper_cpu,
    "inventory_function": inventory_juniper_cpu,
    "service_description": "CPU utilization %s",
    "has_perfdata": True,
    # Use utils.juniper.DETECT when migrating
    "snmp_scan_function": lambda oid: oid(".1.3.6.1.2.1.1.2.0").startswith(".1.3.6.1.4.1.2636.1.1.1"
                                                                          ),
    "snmp_info": (
        ".1.3.6.1.4.1.2636.3.1.13.1",
        [
            5,  #jnxOperatingDescr
            20,  #jnxOperating1MinLoadAvg
            21,  #jnxOperating5MinLoadAvg
            22,  #jnxOperating15MinLoadAvg
        ])
}
