Skip to content

Commit a0f7c75

Browse files
logan-connollyJenkins
authored andcommitted
innovaphone(licenses): improve check results
We first want the check summary to match our v2 standards which is yielding individual results with `<label>: <value>` summaries. This made it so that only the utilization result needed the calculated state and levels message. As noted in the comment in this commit, we are not using the check levels helper here because the legacy plugin was using an exclusive check for the level boundaries. So as to not break behavior with existing commits, we are continue to roll our own check levels implementation in this check. Change-Id: Ifd1aa8fa0b81472fbccb38256d932506fe2227cf
1 parent d95c0ce commit a0f7c75

2 files changed

Lines changed: 42 additions & 32 deletions

File tree

cmk/plugins/innovaphone/agent_based/innovaphone_licenses.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,25 @@ def discover_innovaphone_licenses(section: LicenseUsage) -> DiscoveryResult:
5252

5353

5454
def check_innovaphone_licenses(params: Mapping[str, Any], section: LicenseUsage) -> CheckResult:
55-
perc_used = section.utilization
55+
yield Result(state=State.OK, summary=f"Used: {section.used}")
56+
yield Result(state=State.OK, summary=f"Total: {section.total}")
57+
5658
warn, crit = params["levels"]
57-
utilization_message = f" ({perc_used:.0f}%)" if perc_used is not None else ""
58-
message = f"Used {section.used}/{section.total} Licences{utilization_message}"
59-
levels = f"Warning/ Critical at ({warn}/{crit})"
60-
if perc_used is None:
61-
yield Result(state=State.UNKNOWN, summary=message)
62-
elif perc_used > crit:
63-
yield Result(state=State.CRIT, summary=message + levels)
64-
elif perc_used > warn:
65-
yield Result(state=State.WARN, summary=message + levels)
66-
else:
67-
yield Result(state=State.OK, summary=message)
59+
levels_info = f"(warn/crit at {warn:.0f}%/{crit:.0f}%)"
60+
61+
# NOTE: not using check levels here because the legacy plugin used a exclusive relationship for
62+
# both the warn and critical thresholds. So, we are essentially rolling our own here. That may
63+
# change in the future, but requires a deeper look into what that means for deployed envs.
64+
match section.utilization:
65+
case None:
66+
yield Result(state=State.UNKNOWN, summary="Utilization: n/a")
67+
case float(value) if value > crit:
68+
yield Result(state=State.CRIT, summary=f"Utilization: {value:.0f}% {levels_info}")
69+
case float(value) if value > warn:
70+
yield Result(state=State.WARN, summary=f"Utilization: {value:.0f}% {levels_info}")
71+
case _:
72+
yield Result(state=State.OK, summary=f"Utilization: {section.utilization:.0f}%")
73+
6874
yield Metric("licenses", section.used, boundaries=(0, section.total))
6975

7076

tests/unit/cmk/plugins/innovaphone/agent_based/test_innovaphone_licenses.py

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ def test_discover_innovaphone_licenses() -> None:
5959
{"levels": (90.0, 95.0)},
6060
LicenseUsage(used=0, total=0),
6161
[
62-
Result(state=State.UNKNOWN, summary="Used 0/0 Licences"),
62+
Result(state=State.OK, summary="Used: 0"),
63+
Result(state=State.OK, summary="Total: 0"),
64+
Result(state=State.UNKNOWN, summary="Utilization: n/a"),
6365
Metric("licenses", 0.0, boundaries=(0.0, 0.0)),
6466
],
6567
id="zero values",
@@ -68,7 +70,9 @@ def test_discover_innovaphone_licenses() -> None:
6870
{"levels": (90.0, 95.0)},
6971
LicenseUsage(used=0, total=100),
7072
[
71-
Result(state=State.OK, summary="Used 0/100 Licences (0%)"),
73+
Result(state=State.OK, summary="Used: 0"),
74+
Result(state=State.OK, summary="Total: 100"),
75+
Result(state=State.OK, summary="Utilization: 0%"),
7276
Metric("licenses", 0.0, boundaries=(0.0, 100.0)),
7377
],
7478
id="zero utilization with nonzero total",
@@ -77,7 +81,9 @@ def test_discover_innovaphone_licenses() -> None:
7781
{"levels": (90.0, 95.0)},
7882
LicenseUsage(used=50, total=100),
7983
[
80-
Result(state=State.OK, summary="Used 50/100 Licences (50%)"),
84+
Result(state=State.OK, summary="Used: 50"),
85+
Result(state=State.OK, summary="Total: 100"),
86+
Result(state=State.OK, summary="Utilization: 50%"),
8187
Metric("licenses", 50.0, boundaries=(0.0, 100.0)),
8288
],
8389
id="ok state",
@@ -86,7 +92,9 @@ def test_discover_innovaphone_licenses() -> None:
8692
{"levels": (90.0, 95.0)},
8793
LicenseUsage(used=90, total=100),
8894
[
89-
Result(state=State.OK, summary="Used 90/100 Licences (90%)"),
95+
Result(state=State.OK, summary="Used: 90"),
96+
Result(state=State.OK, summary="Total: 100"),
97+
Result(state=State.OK, summary="Utilization: 90%"),
9098
Metric("licenses", 90.0, boundaries=(0.0, 100.0)),
9199
],
92100
id="ok state at warn boundary",
@@ -95,10 +103,9 @@ def test_discover_innovaphone_licenses() -> None:
95103
{"levels": (90.0, 95.0)},
96104
LicenseUsage(used=92, total=100),
97105
[
98-
Result(
99-
state=State.WARN,
100-
summary="Used 92/100 Licences (92%)Warning/ Critical at (90.0/95.0)",
101-
),
106+
Result(state=State.OK, summary="Used: 92"),
107+
Result(state=State.OK, summary="Total: 100"),
108+
Result(state=State.WARN, summary="Utilization: 92% (warn/crit at 90%/95%)"),
102109
Metric("licenses", 92.0, boundaries=(0.0, 100.0)),
103110
],
104111
id="warn state",
@@ -107,10 +114,9 @@ def test_discover_innovaphone_licenses() -> None:
107114
{"levels": (90.0, 95.0)},
108115
LicenseUsage(used=95, total=100),
109116
[
110-
Result(
111-
state=State.WARN,
112-
summary="Used 95/100 Licences (95%)Warning/ Critical at (90.0/95.0)",
113-
),
117+
Result(state=State.OK, summary="Used: 95"),
118+
Result(state=State.OK, summary="Total: 100"),
119+
Result(state=State.WARN, summary="Utilization: 95% (warn/crit at 90%/95%)"),
114120
Metric("licenses", 95.0, boundaries=(0.0, 100.0)),
115121
],
116122
id="warn state at crit boundary",
@@ -119,10 +125,9 @@ def test_discover_innovaphone_licenses() -> None:
119125
{"levels": (90.0, 95.0)},
120126
LicenseUsage(used=96, total=100),
121127
[
122-
Result(
123-
state=State.CRIT,
124-
summary="Used 96/100 Licences (96%)Warning/ Critical at (90.0/95.0)",
125-
),
128+
Result(state=State.OK, summary="Used: 96"),
129+
Result(state=State.OK, summary="Total: 100"),
130+
Result(state=State.CRIT, summary="Utilization: 96% (warn/crit at 90%/95%)"),
126131
Metric("licenses", 96.0, boundaries=(0.0, 100.0)),
127132
],
128133
id="crit state",
@@ -131,10 +136,9 @@ def test_discover_innovaphone_licenses() -> None:
131136
{"levels": (90.0, 95.0)},
132137
LicenseUsage(used=110, total=100),
133138
[
134-
Result(
135-
state=State.CRIT,
136-
summary="Used 110/100 Licences (110%)Warning/ Critical at (90.0/95.0)",
137-
),
139+
Result(state=State.OK, summary="Used: 110"),
140+
Result(state=State.OK, summary="Total: 100"),
141+
Result(state=State.CRIT, summary="Utilization: 110% (warn/crit at 90%/95%)"),
138142
Metric("licenses", 110.0, boundaries=(0.0, 100.0)),
139143
],
140144
id="used > total",

0 commit comments

Comments
 (0)