Skip to content

Commit b0cab3c

Browse files
committed
added perf-o-meter / graph
1 parent 8997362 commit b0cab3c

File tree

5 files changed

+127
-3
lines changed

5 files changed

+127
-3
lines changed

entra/agent_based/ms_entra_app_creds.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
CheckPlugin,
8080
CheckResult,
8181
DiscoveryResult,
82+
Metric,
8283
render,
8384
Result,
8485
Service,
@@ -203,14 +204,15 @@ def check_ms_entra_app_creds(item: str, params: Mapping[str, Any], section: Sect
203204
else ""
204205
)
205206

206-
params_cred_expiration_levels = params.get("cred_expiration")
207+
params_cred_expiration_levels = params["cred_expiration"]
207208

208209
# For state calculation, check_levels is used.
209210
# It will take the expiration time of the credential with the earliest expiration time.
210211
if cred_expiration_timespan > 0:
211212
yield from check_levels(
212213
cred_expiration_timespan,
213214
levels_lower=(params_cred_expiration_levels),
215+
metric_name="ms_entra_app_creds_remaining_validity",
214216
label="Remaining",
215217
render_func=render.timespan,
216218
)
@@ -222,6 +224,13 @@ def check_ms_entra_app_creds(item: str, params: Mapping[str, Any], section: Sect
222224
render_func=lambda x: f"{render.timespan(abs(x))} ago",
223225
)
224226

227+
# To prevent a negative value for the metric.
228+
yield Metric(
229+
name="ms_entra_app_creds_remaining_validity",
230+
value=0.0,
231+
levels=params_cred_expiration_levels[1],
232+
)
233+
225234
else:
226235
result_summary = "All application credentials are excluded"
227236

entra/agent_based/ms_entra_ca_vpn_cert.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
CheckPlugin,
5656
CheckResult,
5757
DiscoveryResult,
58+
Metric,
5859
render,
5960
Result,
6061
Service,
@@ -164,14 +165,15 @@ def check_ms_entra_ca_vpn_cert(params: Mapping[str, Any], section: Section) -> C
164165
# Calculate the timespan until the earliest certificate expires or has expired.
165166
cert_expiration_timespan = cert_earliest_expiration_timestamp - datetime.now().timestamp()
166167

167-
params_cert_expiration_levels = params.get("cert_expiration")
168+
params_cert_expiration_levels = params["cert_expiration"]
168169

169170
# For state calculation, check_levels is used.
170171
# It will take the expiration time of the certificate with the earliest expiration time.
171172
if cert_expiration_timespan > 0:
172173
yield from check_levels(
173174
cert_expiration_timespan,
174175
levels_lower=(params_cert_expiration_levels),
176+
metric_name="ms_entra_ca_vpn_cert_remaining_validity",
175177
label="Remaining",
176178
render_func=render.timespan,
177179
)
@@ -183,6 +185,13 @@ def check_ms_entra_ca_vpn_cert(params: Mapping[str, Any], section: Section) -> C
183185
render_func=lambda x: f"{render.timespan(abs(x))} ago",
184186
)
185187

188+
# To prevent a negative value for the metric.
189+
yield Metric(
190+
name="ms_entra_ca_vpn_cert_remaining_validity",
191+
value=0.0,
192+
levels=params_cert_expiration_levels[1],
193+
)
194+
186195
# To display custom summary and details we need to yield Result.
187196
# The real state is calculated using the worst state of Result and check_levels.
188197
yield Result(

entra/agent_based/ms_entra_saml_certs.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
CheckPlugin,
5959
CheckResult,
6060
DiscoveryResult,
61+
Metric,
6162
render,
6263
Result,
6364
Service,
@@ -125,7 +126,7 @@ def check_ms_entra_saml_certs(
125126
if not app:
126127
return
127128

128-
params_levels_cert_expiration = params.get("cert_expiration")
129+
params_levels_cert_expiration = params["cert_expiration"]
129130

130131
if app.cert_expiration:
131132
# Cert expiration time and timespan calculation
@@ -152,6 +153,7 @@ def check_ms_entra_saml_certs(
152153
yield from check_levels(
153154
cert_expiration_timespan,
154155
levels_lower=(params_levels_cert_expiration),
156+
metric_name="ms_entra_saml_certs_remaining_validity",
155157
label="Remaining",
156158
render_func=render.timespan,
157159
)
@@ -163,6 +165,13 @@ def check_ms_entra_saml_certs(
163165
render_func=lambda x: "%s ago" % render.timespan(abs(x)),
164166
)
165167

168+
# To prevent a negative value for the metric.
169+
yield Metric(
170+
name="ms_entra_saml_certs_remaining_validity",
171+
value=0.0,
172+
levels=params_levels_cert_expiration[1],
173+
)
174+
166175
# To display custom summary and details we need to yield Result.
167176
# The real state is calculated using the worst state of Result and check_levels.
168177
yield Result(

entra/agent_based/ms_entra_sync.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def check_ms_entra_sync(params: Mapping[str, Any], section: Section) -> CheckRes
8686
yield from check_levels(
8787
sync_last_timespan,
8888
levels_upper=(params["sync_period"]),
89+
metric_name="ms_entra_sync_elapsed_time",
8990
label="Last sync",
9091
render_func=lambda x: f"{render.timespan(abs(x))} ago",
9192
)

entra/graphing/ms_entra.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8; py-indent-offset: 4; max-line-length: 100 -*-
3+
4+
# Copyright (C) 2025 Christopher Pommer <cp.software@outlook.de>
5+
6+
# This program is free software; you can redistribute it and/or
7+
# modify it under the terms of the GNU General Public License
8+
# as published by the Free Software Foundation; either version 2
9+
# of the License, or (at your option) any later version.
10+
11+
# This program is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
16+
# You should have received a copy of the GNU General Public License
17+
# along with this program; if not, write to the Free Software
18+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19+
20+
21+
####################################################################################################
22+
# The graph parameters are part of the Microsoft Entra special agent (ms_entra)
23+
24+
from cmk.graphing.v1 import Title
25+
from cmk.graphing.v1.metrics import (
26+
Color,
27+
Unit,
28+
Metric,
29+
TimeNotation,
30+
)
31+
from cmk.graphing.v1.perfometers import Closed, FocusRange, Open, Perfometer
32+
33+
UNIT_TIME = Unit(TimeNotation())
34+
35+
# Microsoft Entra App Credentials
36+
37+
metric_ms_entra_app_creds_remaining_validity = Metric(
38+
name="ms_entra_app_creds_remaining_validity",
39+
title=Title("Remaining credential validity time"),
40+
unit=UNIT_TIME,
41+
color=Color.YELLOW,
42+
)
43+
44+
perfometer_ms_entra_app_creds_remaining_validity = Perfometer(
45+
name="ms_entra_app_creds_remaining_validity",
46+
focus_range=FocusRange(Closed(0), Open(15552000)),
47+
segments=["ms_entra_app_creds_remaining_validity"],
48+
)
49+
50+
51+
# Microsoft Entra CA VPN Certificate
52+
53+
metric_ms_entra_ca_vpn_cert_remaining_validity = Metric(
54+
name="ms_entra_ca_vpn_cert_remaining_validity",
55+
title=Title("Remaining certificate validity time"),
56+
unit=UNIT_TIME,
57+
color=Color.YELLOW,
58+
)
59+
60+
perfometer_ms_entra_ca_vpn_cert_remaining_validity = Perfometer(
61+
name="ms_entra_ca_vpn_cert_remaining_validity",
62+
focus_range=FocusRange(Closed(0), Open(15552000)),
63+
segments=["ms_entra_ca_vpn_cert_remaining_validity"],
64+
)
65+
66+
67+
# Microsoft Entra SAML Certificate
68+
69+
metric_ms_entra_saml_certs_remaining_validity = Metric(
70+
name="ms_entra_saml_certs_remaining_validity",
71+
title=Title("Remaining certificate validity time"),
72+
unit=UNIT_TIME,
73+
color=Color.YELLOW,
74+
)
75+
76+
perfometer_ms_entra_saml_certs_remaining_validity = Perfometer(
77+
name="ms_entra_saml_certs_remaining_validity",
78+
focus_range=FocusRange(Closed(0), Open(15552000)),
79+
segments=["ms_entra_saml_certs_remaining_validity"],
80+
)
81+
82+
83+
# Microsoft Entra Sync
84+
85+
metric_ms_entra_sync_elapsed_time = Metric(
86+
name="ms_entra_sync_elapsed_time",
87+
title=Title("Elapsed time since last sync"),
88+
unit=UNIT_TIME,
89+
color=Color.DARK_YELLOW,
90+
)
91+
92+
perfometer_ms_entra_sync_elapsed_time = Perfometer(
93+
name="ms_entra_sync_elapsed_time",
94+
focus_range=FocusRange(Closed(0), Open(3600)),
95+
segments=["ms_entra_sync_elapsed_time"],
96+
)

0 commit comments

Comments
 (0)