Skip to content

Commit d5c34ea

Browse files
committed
inital pass
1 parent 016a155 commit d5c34ea

File tree

6 files changed

+299
-0
lines changed

6 files changed

+299
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
###############################################################################
2+
#
3+
# MIT License
4+
#
5+
# Copyright (c) 2025 Advanced Micro Devices, Inc.
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in all
15+
# copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
# SOFTWARE.
24+
#
25+
###############################################################################
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
###############################################################################
2+
#
3+
# MIT License
4+
#
5+
# Copyright (c) 2025 Advanced Micro Devices, Inc.
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in all
15+
# copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
# SOFTWARE.
24+
#
25+
###############################################################################
26+
27+
from nodescraper.models import AnalyzerArgs
28+
from nodescraper.plugins.inband.kernel_module.kernel_module_data import (
29+
KernelModuleDataModel,
30+
)
31+
32+
33+
class KernelModuleAnalyzerArgs(AnalyzerArgs):
34+
modules: dict = {}
35+
modules_filter: list[str] = ["amd", "Amd"]
36+
regex_match: bool = False
37+
38+
@classmethod
39+
def build_from_model(cls, datamodel: KernelModuleDataModel) -> "KernelModuleAnalyzerArgs":
40+
"""build analyzer args from data model
41+
42+
Args:
43+
datamodel (KernelModuleDataModel): data model for plugin
44+
45+
Returns:
46+
KernelModuleAnalyzerArgs: instance of analyzer args class
47+
"""
48+
return cls(modules=datamodel.modules)
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
###############################################################################
2+
#
3+
# MIT License
4+
#
5+
# Copyright (c) 2025 Advanced Micro Devices, Inc.
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in all
15+
# copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
# SOFTWARE.
24+
#
25+
###############################################################################
26+
from typing import Optional
27+
28+
from nodescraper.enums import ExecutionStatus
29+
from nodescraper.interfaces import DataAnalyzer
30+
from nodescraper.models import TaskResult
31+
32+
from .analyzer_args import KernelModuleAnalyzerArgs
33+
from .kernel_module_data import KernelModuleDataModel
34+
35+
36+
class KernelModuleAnalyzer(DataAnalyzer[KernelModuleDataModel, KernelModuleAnalyzerArgs]):
37+
"""Check kernel matches expected versions"""
38+
39+
DATA_MODEL = KernelModuleDataModel
40+
41+
def analyze_data(
42+
self, data: KernelModuleDataModel, args: Optional[KernelModuleAnalyzerArgs] = None
43+
) -> TaskResult:
44+
"""Analyze the kernel data against expected versions.
45+
46+
Args:
47+
data (KernelModuleDataModel): KernelModule data to analyze.
48+
args (Optional[KernelModuleAnalyzerArgs], optional): KernelModule analysis arguments. Defaults to None.
49+
50+
Returns:
51+
TaskResult: Result of the analysis containing status and message.
52+
"""
53+
if not args:
54+
self.result.message = "Expected kernel not provided"
55+
self.result.status = ExecutionStatus.NOT_RAN
56+
return self.result
57+
58+
self.result = None
59+
60+
"""
61+
for kernel in args.exp_kernel:
62+
if args.regex_match:
63+
try:
64+
regex_data = re.compile(kernel)
65+
except re.error:
66+
self._log_event(
67+
category=EventCategory.RUNTIME,
68+
description="KernelModule regex is invalid",
69+
data={"regex": kernel},
70+
priority=EventPriority.ERROR,
71+
)
72+
continue
73+
if regex_data.match(data.kernel_version):
74+
self.result.message = "KernelModule matches expected"
75+
self.result.status = ExecutionStatus.OK
76+
return self.result
77+
elif data.kernel_version == kernel:
78+
self.result.message = "KernelModule matches expected"
79+
self.result.status = ExecutionStatus.OK
80+
return self.result
81+
82+
self.result.message = "KernelModule mismatch!"
83+
self.result.status = ExecutionStatus.ERROR
84+
self._log_event(
85+
category=EventCategory.OS,
86+
description=f"{self.result.message}",
87+
data={"expected": args.exp_kernel, "actual": data.kernel_version},
88+
priority=EventPriority.CRITICAL,
89+
console_log=True,
90+
)
91+
"""
92+
return self.result
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
###############################################################################
2+
#
3+
# MIT License
4+
#
5+
# Copyright (c) 2025 Advanced Micro Devices, Inc.
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in all
15+
# copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
# SOFTWARE.
24+
#
25+
###############################################################################
26+
27+
from nodescraper.models import AnalyzerArgs
28+
from nodescraper.plugins.inband.kernel_module.kernel_module_data import (
29+
KernelModuleDataModel,
30+
)
31+
32+
33+
class KernelModuleAnalyzerArgs(AnalyzerArgs):
34+
modules: dict = {}
35+
modules_filter: list[str] = ["amd", "Amd"]
36+
regex_match: bool = False
37+
38+
@classmethod
39+
def build_from_model(cls, datamodel: KernelModuleDataModel) -> "KernelModuleAnalyzerArgs":
40+
"""build analyzer args from data model
41+
42+
Args:
43+
datamodel (KernelModuleDataModel): data model for plugin
44+
45+
Returns:
46+
KernelModuleAnalyzerArgs: instance of analyzer args class
47+
"""
48+
return cls(modules=datamodel.modules)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
###############################################################################
2+
#
3+
# MIT License
4+
#
5+
# Copyright (c) 2025 Advanced Micro Devices, Inc.
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in all
15+
# copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
# SOFTWARE.
24+
#
25+
###############################################################################
26+
import os
27+
28+
from nodescraper.models import DataModel
29+
from nodescraper.utils import get_unique_filename
30+
31+
32+
class KernelModuleDataModel(DataModel):
33+
kernel_modules: dict
34+
35+
def log_model(self, log_path: str):
36+
"""Log data model to a file
37+
38+
Args:
39+
log_path (str): log path
40+
"""
41+
log_name = os.path.join(log_path, get_unique_filename(log_path, "kernel_modules.log"))
42+
with open(log_name, "w", encoding="utf-8") as log_file:
43+
log_file.write(self.kernel_modules)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
###############################################################################
2+
#
3+
# MIT License
4+
#
5+
# Copyright (c) 2025 Advanced Micro Devices, Inc.
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in all
15+
# copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
# SOFTWARE.
24+
#
25+
###############################################################################
26+
from nodescraper.base import InBandDataPlugin
27+
28+
from .analyzer_args import KernelModuleAnalyzerArgs
29+
from .kernel_module_analyzer import KernelModuleAnalyzer
30+
from .kernel_module_collector import KernelModuleCollector
31+
from .kernel_module_data import KernelModuleDataModel
32+
33+
34+
class KernelModulePlugin(InBandDataPlugin[KernelModuleDataModel, None, KernelModuleAnalyzerArgs]):
35+
"""Plugin for collection and analysis of kernel data"""
36+
37+
DATA_MODEL = KernelModuleDataModel
38+
39+
COLLECTOR = KernelModuleCollector
40+
41+
ANALYZER = KernelModuleAnalyzer
42+
43+
ANALYZER_ARGS = KernelModuleAnalyzerArgs

0 commit comments

Comments
 (0)