-
Notifications
You must be signed in to change notification settings - Fork 475
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
17045 FIX gude_relayport: Fix section parsing
Parsing of the section for the 'gude_relayport' used to crash, because of wrong OIDs. This has now been fixed. SUP-22135 Change-Id: I6b35122ec3061e1b8fce0ea0d51d396139efa317 (cherry picked from commit 022643a882c36b5afb82ead0e7f95936965392a1)
- Loading branch information
Showing
6 changed files
with
406 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[//]: # (werk v2) | ||
# gude_relayport: Fix section parsing | ||
|
||
key | value | ||
---------- | --- | ||
date | 2025-02-06T23:28:25+00:00 | ||
version | 2.3.0p27 | ||
class | fix | ||
edition | cre | ||
component | checks | ||
level | 1 | ||
compatible | yes | ||
|
||
Parsing of the section for the 'gude_relayport' used to crash when the device was off or did not deliver values. | ||
This has now been fixed. | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (C) 2025 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 collections.abc import Mapping | ||
from dataclasses import asdict, dataclass | ||
|
||
from cmk.agent_based.v2 import ( | ||
CheckPlugin, | ||
CheckResult, | ||
DiscoveryResult, | ||
Service, | ||
SimpleSNMPSection, | ||
SNMPTree, | ||
startswith, | ||
StringTable, | ||
) | ||
from cmk.plugins.lib.elphase import check_elphase, CheckParams | ||
|
||
# .1.3.6.1.4.1.28507.38.1.3.1.2.1.2.1 TWTA 2 --> GUDEADS-EPC822X-MIB::epc822XPortName.1 | ||
# .1.3.6.1.4.1.28507.38.1.3.1.2.1.3.1 0 --> GUDEADS-EPC822X-MIB::epc822XPortState.1 | ||
# .1.3.6.1.4.1.28507.38.1.5.1.2.1.4.1 0 --> GUDEADS-EPC822X-MIB::epc822XspPowerActive.1 | ||
# .1.3.6.1.4.1.28507.38.1.5.1.2.1.5.1 0 --> GUDEADS-EPC822X-MIB::epc822XspCurrent.1 | ||
# .1.3.6.1.4.1.28507.38.1.5.1.2.1.6.1 228 --> GUDEADS-EPC822X-MIB::epc822XspVoltage.1 | ||
# .1.3.6.1.4.1.28507.38.1.5.1.2.1.7.1 4995 --> GUDEADS-EPC822X-MIB::epc822XspFrequency.1 | ||
# .1.3.6.1.4.1.28507.38.1.5.1.2.1.10.1 0 --> GUDEADS-EPC822X-MIB::epc822XspPowerApparent.1 | ||
|
||
_STATE_MAP = { | ||
"0": (2, "off"), | ||
"1": (0, "on"), | ||
} | ||
|
||
|
||
@dataclass(frozen=True, kw_only=True) | ||
class RelayPort: | ||
device_state: tuple[int, str] | ||
power: float | None | ||
current: float | None | ||
voltage: float | None | ||
frequency: float | None | ||
appower: float | None | ||
|
||
|
||
Section = Mapping[str, RelayPort] | ||
|
||
|
||
def parse_gude_relayport(string_table: StringTable) -> Section: | ||
return { | ||
portname: RelayPort( | ||
device_state=_STATE_MAP[state], | ||
power=float(power) if power else None, | ||
current=float(current) * 0.001 if current else None, | ||
voltage=float(voltage) if voltage else None, | ||
frequency=float(freq) * 0.01 if freq else None, | ||
appower=float(appower) if appower else None, | ||
) | ||
for portname, state, power, current, voltage, freq, appower in string_table | ||
} | ||
|
||
|
||
snmp_section_gude_relayport = SimpleSNMPSection( | ||
name="gude_relayport", | ||
detect=startswith(".1.3.6.1.2.1.1.2.0", ".1.3.6.1.4.1.28507.38"), | ||
fetch=SNMPTree( | ||
base=".1.3.6.1.4.1.28507.38.1", | ||
oids=[ | ||
"3.1.2.1.2", # GUDEADS-EPC822X-MIB::epc822XPortName.1 | ||
"3.1.2.1.3", # GUDEADS-EPC822X-MIB::epc822XPortState.1 | ||
"5.5.2.1.4", # GUDEADS-EPC822X-MIB::epc822XspPowerActive.1 | ||
"5.5.2.1.5", # GUDEADS-EPC822X-MIB::epc822XspCurrent.1 | ||
"5.5.2.1.6", # GUDEADS-EPC822X-MIB::epc822XspVoltage.1 | ||
"5.5.2.1.7", # GUDEADS-EPC822X-MIB::epc822XspFrequency.1 | ||
"5.5.2.1.10", # GUDEADS-EPC822X-MIB::epc822XspPowerApparent.1 | ||
], | ||
), | ||
parse_function=parse_gude_relayport, | ||
) | ||
|
||
|
||
def discover_gude_relayport( | ||
section: Section, | ||
) -> DiscoveryResult: | ||
yield from (Service(item=relayport) for relayport in section) | ||
|
||
|
||
def check_gude_relayport(item: str, params: CheckParams, section: Section) -> CheckResult: | ||
if (relayport := section.get(item)) is None: | ||
return | ||
|
||
yield from check_elphase( | ||
item, params, {item: {k: v for k, v in asdict(relayport).items() if v is not None}} | ||
) | ||
|
||
|
||
check_plugin_gude_relayport = CheckPlugin( | ||
name="gude_relayport", | ||
service_name="Relay port %s", | ||
discovery_function=discover_gude_relayport, | ||
check_function=check_gude_relayport, | ||
check_ruleset_name="el_inphase", | ||
check_default_parameters={ | ||
"voltage": (220, 210), | ||
"current": (15, 16), | ||
}, | ||
) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.