Skip to content

Commit 439bda7

Browse files
logan-connollyJenkins
authored andcommitted
20254 innovaphone(licenses): fix division by zero
Instead of crashing at runtime, the check should return an unknown result when the total (denominator) is zero and still show the used/total values in the result summary. CMK-37821 Change-Id: Idcddd57aeb0477f7a9b3f88bf5a9d4ee8caf7ed3
1 parent 8987d5c commit 439bda7

3 files changed

Lines changed: 26 additions & 5 deletions

File tree

.werks/20254.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[//]: # (werk v3)
2+
# innovaphone_licenses: fix division by zero error
3+
4+
key | value
5+
---------- | ---
6+
date | 2026-08-07T04:53:19.239404+00:00
7+
version | 3.0.0b1
8+
class | fix
9+
edition | community
10+
component | checks
11+
level | 1
12+
compatible | yes
13+
14+
The _Licenses_ service on Innovaphone devices went UNKNOWN with a crash report
15+
when a device reported a total of 0 licenses (for example a misconfigured or
16+
not-yet-licensed system), since the utilization percentage was computed as a
17+
division by zero.
18+
19+
A total of 0 no longer crashes the check; the service instead reports state
20+
UNKNOWN with "Utilization: n/a", while still showing the used and total
21+
counts.

cmk/legacy_checks/innovaphone_licenses.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,14 @@ def check_innovaphone_licenses(_no_item, params, info):
3333
if not info:
3434
return None
3535
total, used = map(savefloat, info[0])
36-
perc_used = (100.0 * used) / total
36+
perc_used = (100.0 * used) / total if total else None
3737
warn, crit = params["levels"]
38-
message = f"Used {used:.0f}/{total:.0f} Licences ({perc_used:.0f}%)"
38+
utilization_message = f" ({perc_used:.0f}%)" if perc_used is not None else ""
39+
message = f"Used {used:.0f}/{total:.0f} Licences{utilization_message}"
3940
levels = f"Warning/ Critical at ({warn}/{crit})"
4041
perf = [("licenses", used, None, None, 0, total)]
42+
if perc_used is None:
43+
return 3, message, perf
4144
if perc_used > crit:
4245
return 2, message + levels, perf
4346
if perc_used > warn:

tests/unit/cmk/legacy_checks/test_innovaphone_licenses.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
# mypy: disable-error-code="misc"
77
# mypy: disable-error-code="no-untyped-call"
88

9-
import pytest
10-
119
from cmk.legacy_checks.innovaphone_licenses import check_innovaphone_licenses
1210

1311

@@ -18,7 +16,6 @@ def test_check_innovaphone_licenses_metric_boundaries() -> None:
1816
assert perf == [("licenses", 50.0, None, None, 0, 100.0)]
1917

2018

21-
@pytest.mark.xfail(strict=True, raises=ZeroDivisionError, reason="a total of 0 crashes the check")
2219
def test_check_innovaphone_licenses_zero_total() -> None:
2320
assert check_innovaphone_licenses(None, {"levels": (90.0, 95.0)}, [["0", "0"]]) == (
2421
3,

0 commit comments

Comments
 (0)