Skip to content

Commit 11d8029

Browse files
committed
Fix ups checks with Python ValueError exceptions
Signed-off-by: Sven Rueß <[email protected]>
1 parent 53ef875 commit 11d8029

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

cmk/base/legacy_checks/ups_in_voltage.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313

1414

1515
def discover_ups_in_voltage(info):
16-
yield from ((item, {}) for item, value in info if int(value) > 0)
16+
try:
17+
yield from ((item, {}) for item, value in info if int(value) > 0)
18+
except ValueError:
19+
pass
1720

1821

1922
def parse_ups_in_voltage(string_table: StringTable) -> StringTable:

cmk/base/legacy_checks/ups_out_voltage.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@
1515

1616

1717
def discover_ups_out_voltage(info: list[list[str]]) -> Iterable[tuple[str, dict]]:
18-
yield from ((item, {}) for item, value, *_rest in info if int(value) > 0)
18+
for item, value, in info:
19+
try:
20+
value = int(value)
21+
except ValueError:
22+
value = 0
23+
24+
if value > 0:
25+
yield (item, {})
1926

2027

2128
def parse_ups_out_voltage(string_table: StringTable) -> StringTable:

cmk/plugins/collection/agent_based/ups_out_load.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ class UpsPowerVoltage(NamedTuple):
3434
def int_or_zero(value: str) -> int:
3535
if value == "":
3636
return 0
37-
return int(value)
37+
try:
38+
return int(value)
39+
except ValueError:
40+
return 0
3841

3942

4043
def parse_ups_load(string_table: Sequence[StringTable]) -> Section:

0 commit comments

Comments
 (0)