135 lines
3.6 KiB
Python
135 lines
3.6 KiB
Python
#!/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 dataclasses
|
|
from typing import Mapping
|
|
|
|
from .agent_based_api.v1 import (
|
|
contains,
|
|
get_value_store,
|
|
Metric,
|
|
register,
|
|
Result,
|
|
Service,
|
|
SNMPTree,
|
|
State,
|
|
startswith
|
|
)
|
|
from .agent_based_api.v1.type_defs import CheckResult, DiscoveryResult, StringTable
|
|
from .utils.temperature import check_temperature, TempParamType
|
|
|
|
@dataclasses.dataclass(frozen=True)
|
|
class Sensor:
|
|
value: float
|
|
|
|
|
|
@dataclasses.dataclass(frozen=True)
|
|
class VoltageSensor(Sensor):
|
|
...
|
|
|
|
|
|
@dataclasses.dataclass(frozen=True)
|
|
class Section:
|
|
temperature_sensors: Mapping[str, Sensor]
|
|
voltage_sensors: Mapping[str, Sensor]
|
|
|
|
temperature_sensors_name = ['CPU','Board']
|
|
voltage_sensors_name = ['PSU 1','PSU 2']
|
|
|
|
def parse_avocent_sensors(string_table: StringTable) -> Section:
|
|
temperature_sensors = {}
|
|
voltage_sensors = {}
|
|
position = 0
|
|
for temp_sens_name in temperature_sensors_name:
|
|
temperature_sensors[temp_sens_name] = Sensor(value=int(string_table[0][position]))
|
|
position +=1
|
|
|
|
pos = 2
|
|
for volt_sens_name in voltage_sensors_name:
|
|
voltage_sensors[volt_sens_name] = Sensor(value=float(string_table[0][pos])/100)
|
|
pos += 1
|
|
|
|
return Section(
|
|
temperature_sensors=temperature_sensors,
|
|
voltage_sensors=voltage_sensors,
|
|
)
|
|
|
|
register.snmp_section(
|
|
name="avocent_sensors",
|
|
detect=startswith(".1.3.6.1.2.1.1.1.0", "Avocent"),
|
|
parse_function=parse_avocent_sensors,
|
|
fetch=SNMPTree(
|
|
base=".1.3.6.1.4.1.10418.26.2.7",
|
|
oids=[
|
|
"1", #acsSensorsInternalCurrentCPUTemperature
|
|
"6", #acsSensorsInternalCurrentBoardTemperature
|
|
"17", #acsSensorsVoltagePowerSupply1
|
|
"18", #acsSensorsVoltagePowerSupply2
|
|
],
|
|
),
|
|
)
|
|
|
|
|
|
|
|
def discover_avocent_voltage_sensors(section: Section) -> DiscoveryResult:
|
|
yield from (Service(item=sensor_name) for sensor_name in section.voltage_sensors)
|
|
|
|
|
|
def check_avocent_voltage_sensors(
|
|
item: str,
|
|
section: Section,
|
|
) -> CheckResult:
|
|
if not (sensor := section.voltage_sensors.get(item)):
|
|
return
|
|
|
|
yield Result(
|
|
state=State.OK,
|
|
summary=f"{sensor.value:.1f} V",
|
|
)
|
|
|
|
yield Metric(
|
|
name="voltage",
|
|
value=sensor.value,
|
|
)
|
|
|
|
|
|
register.check_plugin(
|
|
name="avocent_voltage_sensors",
|
|
sections=["avocent_sensors"],
|
|
service_name="Voltage %s",
|
|
discovery_function=discover_avocent_voltage_sensors,
|
|
check_function=check_avocent_voltage_sensors,
|
|
)
|
|
|
|
|
|
def discover_avocent_sensors_temp(section: Section) -> DiscoveryResult:
|
|
yield from (Service(item=sensor_name) for sensor_name in section.temperature_sensors)
|
|
|
|
|
|
def check_avocent_sensors_temp(
|
|
item: str,
|
|
params: TempParamType,
|
|
section: Section,
|
|
) -> CheckResult:
|
|
if not (sensor := section.temperature_sensors.get(item)):
|
|
return
|
|
yield from check_temperature(
|
|
reading=sensor.value,
|
|
params=params,
|
|
unique_name=item,
|
|
value_store=get_value_store(),
|
|
)
|
|
|
|
register.check_plugin(
|
|
name="avocent_sensors_temp",
|
|
sections=["avocent_sensors"],
|
|
service_name="Temperature %s",
|
|
discovery_function=discover_avocent_sensors_temp,
|
|
check_function=check_avocent_sensors_temp,
|
|
check_ruleset_name="temperature",
|
|
check_default_parameters={"device_levels_handling": "devdefault"},
|
|
)
|