/
ups_power.py
57 lines (45 loc) · 1.53 KB
/
ups_power.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python3
# Copyright (C) 2022 Checkmk 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.utils.ups import DETECT_UPS_GENERIC
from .agent_based_api.v1 import OIDEnd, register, SNMPTree
from .agent_based_api.v1.type_defs import StringTable
def _parse_value(value: str) -> int | None:
try:
return int(value)
except ValueError:
return None
def parse_ups_power(
string_table: List[StringTable],
) -> dict[str, int]:
section: dict[str, int] = {}
for idx, voltage_str, power_str in string_table[0]:
if (voltage := _parse_value(voltage_str)) is None or not voltage:
# TODO Fix unused voltage
continue
if (power := _parse_value(power_str)) is None:
continue
# Some "RPS SpA" systems are not RFC conform in this value.
# The values can get negative but should never be.
if power < 0:
power *= -1
section[idx] = power
return section
register.snmp_section(
name="ups_power",
parsed_section_name="epower",
detect=DETECT_UPS_GENERIC,
parse_function=parse_ups_power,
fetch=[
SNMPTree(
base=".1.3.6.1.2.1.33.1.4.4.1",
oids=[
OIDEnd(),
"2", # voltage
"4", # power
],
)
],
)