Skip to content

Commit 0f3d088

Browse files
authored
Upload initial release
1 parent d0c4dfb commit 0f3d088

11 files changed

+988
-0
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#!/usr/bin/env python3
2+
# -*- encoding: utf-8; py-indent-offset: 4 -*-
3+
4+
# Copyright (C) 2024 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+
import json
22+
from collections.abc import Mapping, Sequence
23+
from dataclasses import dataclass
24+
from datetime import datetime
25+
from typing import Any
26+
27+
from cmk.agent_based.v2 import (
28+
AgentSection,
29+
check_levels,
30+
CheckPlugin,
31+
CheckResult,
32+
DiscoveryResult,
33+
render,
34+
Result,
35+
Service,
36+
State,
37+
StringTable,
38+
)
39+
40+
41+
@dataclass(frozen=True)
42+
class CertInfo:
43+
cert_appleid: str
44+
cert_expiration: str
45+
46+
47+
Section = Sequence[CertInfo]
48+
49+
# Example data from special agent:
50+
# <<<ms_intune_apple_mdm_push_cert:sep(0)>>>
51+
# {
52+
# "cert_appleid": "mail@domain.de",
53+
# "cert_expiration": "2000-01-01T00:00:00Z"
54+
# }
55+
56+
57+
def parse_ms_intune_apple_mdm_push_cert(string_table: StringTable) -> Section:
58+
parsed = json.loads(string_table[0][0])
59+
return parsed
60+
61+
62+
def discover_ms_intune_apple_mdm_push_cert(section: Section) -> DiscoveryResult:
63+
yield Service()
64+
65+
66+
def check_ms_intune_apple_mdm_push_cert(params: Mapping[str, Any], section: Section) -> CheckResult:
67+
cert_appleid = section["cert_appleid"]
68+
cert_expiration = section["cert_expiration"]
69+
70+
params_levels_cert_expiration = params.get("cert_expiration")
71+
72+
cert_expiration_datetime = datetime.strptime(cert_expiration, "%Y-%m-%dT%H:%M:%SZ")
73+
cert_expiration_timestamp = cert_expiration_datetime.timestamp()
74+
cert_expiration_timestamp_render = render.datetime(int(cert_expiration_timestamp))
75+
76+
cert_expiration_timespan = cert_expiration_timestamp - datetime.now().timestamp()
77+
78+
if cert_expiration_timespan > 0:
79+
yield from check_levels(
80+
cert_expiration_timespan,
81+
levels_lower=(params_levels_cert_expiration),
82+
label="Remaining",
83+
render_func=render.timespan,
84+
)
85+
else:
86+
yield from check_levels(
87+
cert_expiration_timespan,
88+
levels_lower=(params_levels_cert_expiration),
89+
label="Expired",
90+
render_func=lambda x: "%s ago" % render.timespan(abs(x)),
91+
)
92+
93+
yield Result(
94+
state=State.OK,
95+
summary=f"Expiration time: {cert_expiration_timestamp_render} (UTC)",
96+
details=f"Expiration time: {cert_expiration_timestamp_render} (UTC)\\n Apple ID: {cert_appleid}",
97+
)
98+
99+
100+
agent_section_ms_intune_apple_push_cert = AgentSection(
101+
name="ms_intune_apple_mdm_push_cert",
102+
parse_function=parse_ms_intune_apple_mdm_push_cert,
103+
)
104+
105+
106+
check_plugin_ms_intune_apple_mdm_push_cert = CheckPlugin(
107+
name="ms_intune_apple_mdm_push_cert",
108+
service_name="Intune Apple MDM push certificate",
109+
discovery_function=discover_ms_intune_apple_mdm_push_cert,
110+
check_function=check_ms_intune_apple_mdm_push_cert,
111+
check_ruleset_name="ms_intune_apple_mdm_push_cert",
112+
check_default_parameters={"cert_expiration": ("fixed", (1209600.0, 432000.0))},
113+
)
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
#!/usr/bin/env python3
2+
# -*- encoding: utf-8; py-indent-offset: 4 -*-
3+
4+
# Copyright (C) 2024 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+
import json
22+
from collections.abc import Mapping, Sequence
23+
from dataclasses import dataclass
24+
from datetime import datetime
25+
from typing import Any
26+
27+
from cmk.agent_based.v2 import (
28+
AgentSection,
29+
check_levels,
30+
CheckPlugin,
31+
CheckResult,
32+
DiscoveryResult,
33+
render,
34+
Result,
35+
Service,
36+
State,
37+
StringTable,
38+
)
39+
40+
41+
@dataclass(frozen=True)
42+
class TokenInfo:
43+
token_id: str
44+
token_appleid: str
45+
token_state: str
46+
token_expiration: str
47+
48+
49+
# Example data from special agent:
50+
# <<<ms_intune_apple_vpp_tokens:sep(0)>>>
51+
# [
52+
# {
53+
# "token_id": "00000000-0000-0000-0000-000000000000",
54+
# "token_appleid": "vpp@domain.td",
55+
# "token_state": "valid",
56+
# "token_expiration": "2025-03-02T06:54:05Z"
57+
# },
58+
# {
59+
# "token_id": "00000000-0000-0000-0000-000000000001",
60+
# "token_appleid": "vpp@domain.td",
61+
# "token_state": "valid",
62+
# "token_expiration": "2025-03-02T06:54:05Z"
63+
# },
64+
# ...
65+
# ]
66+
67+
Section = Mapping[str, Sequence[TokenInfo]]
68+
69+
70+
def parse_ms_intune_apple_vpp_tokens(string_table: StringTable) -> Section:
71+
parsed = {}
72+
for item in json.loads("".join(string_table[0])):
73+
parsed[item["token_id"]] = item
74+
return parsed
75+
76+
77+
def discover_ms_intune_apple_vpp_tokens(section: Section) -> DiscoveryResult:
78+
for group in section:
79+
yield Service(item=group)
80+
81+
82+
def check_ms_intune_apple_vpp_tokens(item: str, params: Mapping[str, Any], section: Section) -> CheckResult:
83+
token = section.get(item)
84+
if not token:
85+
return
86+
87+
params_levels_token_expiration = params.get("token_expiration")
88+
89+
token_appleid = token["token_appleid"]
90+
token_state = token["token_state"]
91+
token_expiration = token["token_expiration"]
92+
93+
token_expiration_datetime = datetime.strptime(token_expiration, "%Y-%m-%dT%H:%M:%SZ")
94+
token_expiration_timestamp = token_expiration_datetime.timestamp()
95+
token_expiration_timestamp_render = render.datetime(int(token_expiration_timestamp))
96+
97+
token_expiration_timespan = token_expiration_timestamp - datetime.now().timestamp()
98+
99+
result_details = (
100+
f"Expiration time: {token_expiration_timestamp_render} (UTC)"
101+
f"\\nState: {token_state}"
102+
f"\\nApple ID: {token_appleid}"
103+
)
104+
result_summary = f"Expiration time: {token_expiration_timestamp_render} (UTC), State: {token_state}"
105+
106+
if token_expiration_timespan > 0:
107+
yield from check_levels(
108+
token_expiration_timespan,
109+
levels_lower=(params_levels_token_expiration),
110+
label="Remaining",
111+
render_func=render.timespan,
112+
)
113+
else:
114+
yield from check_levels(
115+
token_expiration_timespan,
116+
levels_lower=(params_levels_token_expiration),
117+
label="Expired",
118+
render_func=lambda x: "%s ago" % render.timespan(abs(x)),
119+
)
120+
121+
if token_state != "valid":
122+
yield Result(
123+
state=State.CRIT,
124+
summary=result_summary,
125+
details=result_details,
126+
)
127+
else:
128+
yield Result(
129+
state=State.OK,
130+
summary=result_summary,
131+
details=result_details,
132+
)
133+
134+
135+
agent_section_ms_intune_apple_vpp_tokens = AgentSection(
136+
name="ms_intune_apple_vpp_tokens",
137+
parse_function=parse_ms_intune_apple_vpp_tokens,
138+
)
139+
140+
141+
check_plugin_ms_intune_apple_vpp_tokens = CheckPlugin(
142+
name="ms_intune_apple_vpp_tokens",
143+
service_name="Intune VPP token %s",
144+
discovery_function=discover_ms_intune_apple_vpp_tokens,
145+
check_function=check_ms_intune_apple_vpp_tokens,
146+
check_ruleset_name="ms_intune_apple_vpp_tokens",
147+
check_default_parameters={"token_expiration": ("fixed", (1209600.0, 432000.0))},
148+
)
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#!/usr/bin/env python3
2+
# -*- encoding: utf-8; py-indent-offset: 4 -*-
3+
4+
# Copyright (C) 2024 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 result_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+
import json
22+
from collections.abc import Mapping, Sequence
23+
from dataclasses import dataclass
24+
from datetime import datetime
25+
26+
from cmk.agent_based.v2 import (
27+
AgentSection,
28+
CheckPlugin,
29+
CheckResult,
30+
DiscoveryResult,
31+
render,
32+
Result,
33+
Service,
34+
State,
35+
StringTable,
36+
)
37+
38+
39+
@dataclass(frozen=True)
40+
class ConnectorInfo:
41+
connector_connection_last: str
42+
connector_state: str
43+
connector_name: str
44+
connector_version: str
45+
46+
47+
Section = Mapping[str, Sequence[ConnectorInfo]]
48+
49+
# Example data from special agent:
50+
# <<<ms_intune_cert_connectors:sep(0)>>>
51+
# [
52+
# {
53+
# "connector_connection_last": "2024-05-18T21:33:26.1092739Z",
54+
# "connector_state": "active",
55+
# "connector_name": "Connector1",
56+
# "connector_version": "6.2301.1.0"
57+
# },
58+
# {
59+
# "connector_connection_last": "2024-05-18T21:29:30.5308288Z",
60+
# "connector_state": "active",
61+
# "connector_name": "Connector2",
62+
# "connector_version": "6.2301.1.0"
63+
# },
64+
# ...
65+
# ]
66+
67+
68+
def parse_ms_intune_cert_connectors(string_table: StringTable) -> Section:
69+
parsed = {}
70+
for item in json.loads("".join(string_table[0])):
71+
parsed[item["connector_name"]] = item
72+
return parsed
73+
74+
75+
def discover_ms_intune_cert_connectors(section: Section) -> DiscoveryResult:
76+
for group in section:
77+
yield Service(item=group)
78+
79+
80+
def check_ms_intune_cert_connectors(item: str, section: Section) -> CheckResult:
81+
connector = section.get(item)
82+
if not connector:
83+
return
84+
85+
connector_connection_last = connector["connector_connection_last"]
86+
connector_state = connector["connector_state"]
87+
connector_version = connector["connector_version"]
88+
89+
connector_connection_last_datetime = datetime.fromisoformat(connector_connection_last)
90+
connector_connection_last_timestamp = connector_connection_last_datetime.timestamp()
91+
connector_connection_last_timestamp_render = render.datetime(int(connector_connection_last_timestamp))
92+
93+
result_summary = f"State: {connector_state}"
94+
95+
result_details = (
96+
f"State: {connector_state}"
97+
f"\\nLast connected: {connector_connection_last_timestamp_render}"
98+
f"\\nConnector version: {connector_version}"
99+
)
100+
101+
if connector_state != "active":
102+
yield Result(
103+
state=State.CRIT,
104+
summary=result_summary,
105+
details=result_details,
106+
)
107+
else:
108+
yield Result(
109+
state=State.OK,
110+
summary=result_summary,
111+
details=result_details,
112+
)
113+
114+
115+
agent_section_ms_intune_cert_connectors = AgentSection(
116+
name="ms_intune_cert_connectors",
117+
parse_function=parse_ms_intune_cert_connectors,
118+
)
119+
120+
121+
check_plugin_ms_intune_cert_connectors = CheckPlugin(
122+
name="ms_intune_cert_connectors",
123+
service_name="Intune connector %s",
124+
discovery_function=discover_ms_intune_cert_connectors,
125+
check_function=check_ms_intune_cert_connectors,
126+
)

0 commit comments

Comments
 (0)