127 lines
3.8 KiB
Python
127 lines
3.8 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.
|
|
from dataclasses import dataclass
|
|
from typing import Iterable, Mapping, Tuple, NamedTuple
|
|
from .agent_based_api.v1 import check_levels, equals, register, Service, SNMPTree, all_of, exists
|
|
from .agent_based_api.v1.type_defs import CheckResult, DiscoveryResult, StringTable
|
|
|
|
|
|
def parse_clever_pdu_120(string_table: StringTable):
|
|
data=string_table[0]
|
|
parsed = {}
|
|
parsed = {
|
|
"Line 1" : {
|
|
"voltage": float(data[0]),
|
|
"current": float(data[3])/10,
|
|
"energy": float(data[6]),
|
|
},
|
|
"Line 2" : {
|
|
"voltage": float(data[1]),
|
|
"current": float(data[4])/10,
|
|
"energy": float(data[7]),
|
|
},
|
|
"Line 3" : {
|
|
"voltage": float(data[2]),
|
|
"current": float(data[5])/10,
|
|
"energy": float(data[8]),
|
|
},
|
|
"Total Energy" : {
|
|
"energy" : float((float(data[0])*float(data[3])/10)) + float((float(data[1])*float(data[4])/10)) + float((float(data[2])*float(data[5])/10)),
|
|
},
|
|
}
|
|
return parsed
|
|
|
|
|
|
_UNIT_MAP = {
|
|
"voltage": "V" ,
|
|
"current": "A" ,
|
|
"energy": "W",
|
|
}
|
|
|
|
|
|
register.snmp_section(
|
|
name="clever_pdu_120",
|
|
parsed_section_name="clever_pdu_120",
|
|
parse_function=parse_clever_pdu_120,
|
|
detect = all_of(
|
|
equals(
|
|
".1.3.6.1.2.1.1.2.0",
|
|
".1.3.6.1.4.1.30966",
|
|
),
|
|
exists(".1.3.6.1.4.1.30966.10.3.2.70.0"),
|
|
),
|
|
fetch=SNMPTree(
|
|
".1.3.6.1.4.1.30966.10.3.2",
|
|
[
|
|
"1", # mVoltageA
|
|
"2", # mVoltageB
|
|
"3", # mVoltageC
|
|
"4", # mCurrentA
|
|
"5", # mCurrentB
|
|
"6", # mCurrentC
|
|
"7", # mEnergyA
|
|
"8", # mEnergyB
|
|
"9", # mEnergyC
|
|
],
|
|
),
|
|
)
|
|
|
|
|
|
def discover_clever_pdu_120(section) -> DiscoveryResult:
|
|
yield from (Service(item=line_num) for line_num in section)
|
|
|
|
|
|
def check_clever_pdu_120(item, params, section) -> CheckResult:
|
|
if "Total" not in item:
|
|
for param in params:
|
|
levels_lower = levels_upper = None
|
|
warn, crit = params.get(param)
|
|
if warn > crit:
|
|
levels_lower = warn, crit
|
|
else:
|
|
levels_upper = warn, crit
|
|
|
|
yield from check_levels(
|
|
section.get(item)[param],
|
|
levels_upper = levels_upper,
|
|
levels_lower = levels_lower,
|
|
metric_name = param,
|
|
render_func=lambda v: f"{v:.2f} {_UNIT_MAP[param]}",
|
|
label = param,
|
|
)
|
|
else:
|
|
for param in params:
|
|
if "energy" in param:
|
|
levels_lower = levels_upper = None
|
|
warn, crit = params.get(param)
|
|
if warn > crit:
|
|
levels_lower = warn, crit
|
|
else:
|
|
levels_upper = warn, crit
|
|
yield from check_levels(
|
|
section.get(item)[param],
|
|
levels_upper = levels_upper,
|
|
levels_lower = levels_lower,
|
|
metric_name = param,
|
|
render_func=lambda v: f"{v:.2f} {_UNIT_MAP[param]}",
|
|
label = param,
|
|
)
|
|
|
|
|
|
|
|
register.check_plugin(
|
|
name="clever_pdu_120",
|
|
service_name="%s",
|
|
discovery_function=discover_clever_pdu_120,
|
|
check_function=check_clever_pdu_120,
|
|
check_ruleset_name="clever_pdu",
|
|
check_default_parameters={
|
|
"voltage": (220, 210),
|
|
"current": (32, 33),
|
|
"energy": (35000, 36000),
|
|
},
|
|
)
|