#!/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 typing import List from cmk.base.plugins.agent_based.agent_based_api.v1 import ( register, Result, Service, SNMPTree, startswith, State, ) from cmk.base.plugins.agent_based.agent_based_api.v1.type_defs import ( CheckResult, DiscoveryResult, StringTable, ) Section = [] def parse_avocent_psu(string_table: List[StringTable]) -> Section: return string_table[0][0] register.snmp_section( name="avocent_psu", detect=startswith(".1.3.6.1.2.1.1.1.0", "Avocent"), parse_function=parse_avocent_psu, fetch=[ SNMPTree( base=".1.3.6.1.4.1.10418.26.2.1.8", oids=[ "1", #Number of PSU installed "2", #PowerSupply1 state "3", #PowerSupply2 state ], ), ], ) def discovery_avocent_psu(section: Section) -> DiscoveryResult: yield Service() def _power_supply_status_descr(status_nr: str) -> str: return { "1": "Powered On", "2": "Powered Off", "9999": "Power Supply is not installed", }.get(status_nr, status_nr) def _power_supply_state(status_nr: str) -> State: return { "1": State.OK, "2": State.CRIT, "9999": State.OK }.get(status_nr, State.UNKNOWN) def check_avocent_psu( section: Section, ) -> CheckResult: number_of_psu=section[0] state_psu_1=section[1] state_psu_2=section[2] yield Result( state=State.OK, summary="Number of PSU installed: %s" % number_of_psu, ) yield Result( state=_power_supply_state(state_psu_1), summary="Power Supply 1 is %s" % _power_supply_status_descr(state_psu_1), ) yield Result( state=_power_supply_state(state_psu_2), summary="Power Supply 2 is %s" % _power_supply_status_descr(state_psu_2), ) register.check_plugin( name="avocent_psu", sections=["avocent_psu"], service_name="Power Supplies", discovery_function=discovery_avocent_psu, check_function=check_avocent_psu )