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

# cseSysMemoryUtilization   .1.3.6.1.4.1.9.9.305.1.1.2.0
#

cisco_sys_mem_default_levels = (80.0, 90.0)


def inventory_cisco_sys_mem(info):
    if info:
        return [(None, "cisco_sys_mem_default_levels")]
    return []


def check_cisco_sys_mem(_no_item, params, info):
    if info[0][0]:
        mem_used_percent = float(info[0][0])
        return check_levels(
            mem_used_percent,
            "mem_used_percent",
            params,
            human_readable_func=get_percent_human_readable,
            infoname="Supervisor Memory used",
            boundaries=(0, 100),
        )


check_info["cisco_sys_mem"] = {
    "check_function": check_cisco_sys_mem,
    "inventory_function": inventory_cisco_sys_mem,
    "service_description": "Supervisor Mem Used",
    "has_perfdata": True,
    "group": "cisco_supervisor_mem",  # seperate group since only percentage
    "snmp_scan_function": lambda oid: oid(".1.3.6.1.2.1.1.1.0").startswith("Cisco NX-OS"),
    "snmp_info": (".1.3.6.1.4.1.9.9.305.1.1.2", "0"),
}
