Skip to content

Commit 95b6f92

Browse files
committed
Fix ups checks with Python ValueError exceptions
Signed-off-by: Sven Rueß <[email protected]>
1 parent 3b13d29 commit 95b6f92

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-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: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,17 @@
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 (
19+
item,
20+
value,
21+
) in info:
22+
try:
23+
value_int = int(value)
24+
except ValueError:
25+
value_int = 0
26+
27+
if value_int > 0:
28+
yield (item, {})
1929

2030

2131
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)