Skip to content

Commit 4d35e1f

Browse files
committed
Merge branch 'development' into alex_devenum
2 parents bcce6ec + 14dbe50 commit 4d35e1f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+544
-436
lines changed
File renamed without changes.

EXTENDING.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,5 +131,4 @@ if __name__ == "__main__":
131131
```
132132

133133
## external plugins
134-
External plugins can be added and installed in the same env as node-scraper plugins. Find an
135-
example of an external plugin in **`/docs/node-scraper-external`**
134+
External plugins can be added and installed in the same env as node-scraper plugins. See -> [docs/node-scraper-external/README.md](docs/node-scraper-external/README.md)

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ system debug.
1919
- [Plugin config: `--plugin-configs` command](#plugin-config---plugin-configs-command)
2020
- [Reference config: `gen-reference-config` command](#reference-config-gen-reference-config-command)
2121
- **Extending Node Scraper (integration & external plugins)** → See [EXTENDING.md](EXTENDING.md)
22+
- **Full view of the plugins with the associated collectors & analyzers as well as the commands
23+
invoked by collectors** -> See [docs/PLUGIN_DOC.md](docs/PLUGIN_DOC.md)
2224

2325
## Installation
2426
### Install From Source
25-
Node Scraper requires Python 3.10+ for installation. After cloning this repository,
27+
Node Scraper requires Python 3.9+ for installation. After cloning this repository,
2628
call dev-setup.sh script with 'source'. This script creates an editable install of Node Scraper in
2729
a python virtual environment and also configures the pre-commit hooks for the project.
2830

docs/PLUGIN_DOC.md

Lines changed: 194 additions & 200 deletions
Large diffs are not rendered by default.

docs/generate_plugin_doc_bundle.py

Lines changed: 106 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
import pkgutil
3737
import sys
3838
from pathlib import Path
39-
from typing import Any, Iterable, List, Type
39+
from typing import Any, Iterable, List, Optional, Type
4040

41-
LINK_BASE_DEFAULT = "../"
41+
LINK_BASE_DEFAULT = "https://github.com/amd/node-scraper/blob/HEAD/"
4242
REL_ROOT_DEFAULT = "nodescraper/plugins/inband"
4343
DEFAULT_ROOT_PACKAGE = "nodescraper.plugins"
4444

@@ -50,7 +50,7 @@ def get_attr(obj: Any, name: str, default: Any = None) -> Any:
5050
return default
5151

5252

53-
def _slice_from_rel_root(p: Path, rel_root: str | None) -> str | None:
53+
def _slice_from_rel_root(p: Path, rel_root: Optional[str]) -> Optional[str]:
5454
if not rel_root:
5555
return None
5656
parts = list(p.parts)
@@ -63,7 +63,7 @@ def _slice_from_rel_root(p: Path, rel_root: str | None) -> str | None:
6363
return None
6464

6565

66-
def setup_link(class_data, link_base: str, rel_root: str | None) -> str:
66+
def setup_link(class_data, link_base: str, rel_root: Optional[str]) -> str:
6767
try:
6868
file_location = Path(inspect.getfile(class_data)).resolve()
6969
except Exception:
@@ -80,7 +80,7 @@ def setup_link(class_data, link_base: str, rel_root: str | None) -> str:
8080
return base + rel_path
8181

8282

83-
def get_own_doc(cls: type) -> str | None:
83+
def get_own_doc(cls: type) -> Optional[str]:
8484
"""
8585
Return only the __doc__ defined in the class itself, ignore inheritance.
8686
"""
@@ -224,6 +224,57 @@ def add_cmd(s: Any):
224224
return cmds
225225

226226

227+
def extract_regexes_and_args_from_analyzer(
228+
analyzer_cls: type, args_cls: Optional[type]
229+
) -> List[str]:
230+
"""Extract regex patterns and analyzer args from analyzer class"""
231+
if not inspect.isclass(analyzer_cls):
232+
return []
233+
234+
output: List[str] = []
235+
236+
# Check for ERROR_REGEX class variable (used by RegexAnalyzer subclasses like DmesgAnalyzer)
237+
error_regex = get_attr(analyzer_cls, "ERROR_REGEX", None)
238+
if error_regex and isinstance(error_regex, list):
239+
output.append("**Built-in Regexes:**")
240+
for item in error_regex:
241+
# ErrorRegex objects have regex, message, event_category attributes
242+
if hasattr(item, "regex"):
243+
pattern = getattr(item.regex, "pattern", None)
244+
message = getattr(item, "message", "")
245+
if pattern:
246+
# Truncate long patterns
247+
pattern_str = pattern if len(pattern) < 50 else pattern[:47] + "..."
248+
output.append(f"- {message}: `{pattern_str}`")
249+
elif hasattr(item, "pattern"):
250+
pattern_str = item.pattern if len(item.pattern) < 50 else item.pattern[:47] + "..."
251+
output.append(f"- `{pattern_str}`")
252+
253+
# Check for other regex-related attributes
254+
for attr in dir(analyzer_cls):
255+
if "REGEX" in attr.upper() and not attr.startswith("_"):
256+
val = get_attr(analyzer_cls, attr, default=None)
257+
if val is None or attr == "ERROR_REGEX":
258+
continue
259+
260+
if hasattr(val, "pattern"):
261+
output.append(f"**{attr}**: `{val.pattern}`")
262+
elif isinstance(val, str):
263+
output.append(f"**{attr}**: `{val}`")
264+
265+
# Extract analyzer args if provided
266+
if inspect.isclass(args_cls):
267+
anns = get_attr(args_cls, "__annotations__", {}) or {}
268+
if anns:
269+
output.append("**Analyzer Args:**")
270+
for key, value in anns.items():
271+
# Format the type annotation
272+
type_str = str(value).replace("typing.", "")
273+
output.append(f"- `{key}`: {type_str}")
274+
275+
return output
276+
277+
227278
def md_header(text: str, level: int = 2) -> str:
228279
return f"{'#' * level} {text}\n\n"
229280

@@ -257,7 +308,20 @@ def class_vars_dump(cls: type, exclude: set) -> List[str]:
257308
continue
258309
if callable(val) or isinstance(val, (staticmethod, classmethod, property)):
259310
continue
260-
out.append(f"**{name}**: `{val}`")
311+
312+
# Format list values with each item on a new line
313+
if isinstance(val, list) and len(val) > 0:
314+
val_str = str(val)
315+
if len(val_str) > 200:
316+
formatted_items = []
317+
for item in val:
318+
formatted_items.append(f" {item}")
319+
formatted_list = "[\n" + ",\n".join(formatted_items) + "\n]"
320+
out.append(f"**{name}**: `{formatted_list}`")
321+
else:
322+
out.append(f"**{name}**: `{val}`")
323+
else:
324+
out.append(f"**{name}**: `{val}`")
261325
return out
262326

263327

@@ -279,14 +343,20 @@ def generate_plugin_table_rows(plugins: List[type]) -> List[List[str]]:
279343
seen.add(key)
280344
uniq.append(c)
281345
cmds = uniq
346+
347+
# Extract regexes and args from analyzer
348+
regex_and_args = []
349+
if inspect.isclass(an):
350+
regex_and_args = extract_regexes_and_args_from_analyzer(an, args)
351+
282352
rows.append(
283353
[
284-
f"{p.__module__}.{p.__name__}",
354+
p.__name__,
355+
"<br>".join(cmds).replace("|", "\\|") if cmds else "-",
356+
"<br>".join(regex_and_args).replace("|", "\\|") if regex_and_args else "-",
285357
link_anchor(dm, "model") if inspect.isclass(dm) else "-",
286358
link_anchor(col, "collector") if inspect.isclass(col) else "-",
287359
link_anchor(an, "analyzer") if inspect.isclass(an) else "-",
288-
link_anchor(args, "args") if inspect.isclass(args) else "-",
289-
"<br>".join(cmds) if cmds else "-",
290360
]
291361
)
292362
return rows
@@ -302,14 +372,15 @@ def render_table(headers: List[str], rows: List[List[str]]) -> str:
302372
return "".join(out)
303373

304374

305-
def render_collector_section(col: type, link_base: str, rel_root: str | None) -> str:
375+
def render_collector_section(col: type, link_base: str, rel_root: Optional[str]) -> str:
306376
hdr = md_header(f"Collector Class {col.__name__}", 2)
307377
desc = sanitize_doc(get_own_doc(col) or "")
308378
s = hdr
309379
if desc:
310380
s += md_header("Description", 3) + desc + "\n\n"
311381
s += md_kv("Bases", str(bases_list(col)))
312-
s += md_kv("Link to code", setup_link(col, link_base, rel_root))
382+
_url = setup_link(col, link_base, rel_root)
383+
s += md_kv("Link to code", f"[{Path(_url).name}]({_url})")
313384

314385
exclude = {"__doc__", "__module__", "__weakref__", "__dict__"}
315386
cv = class_vars_dump(col, exclude)
@@ -334,60 +405,56 @@ def render_collector_section(col: type, link_base: str, rel_root: str | None) ->
334405
return s
335406

336407

337-
def render_analyzer_section(an: type, link_base: str, rel_root: str | None) -> str:
408+
def render_analyzer_section(an: type, link_base: str, rel_root: Optional[str]) -> str:
338409
hdr = md_header(f"Data Analyzer Class {an.__name__}", 2)
339410
desc = sanitize_doc(get_own_doc(an) or "")
340411
s = hdr
341412
if desc:
342413
s += md_header("Description", 3) + desc + "\n\n"
343414
s += md_kv("Bases", str(bases_list(an)))
344-
s += md_kv("Link to code", setup_link(an, link_base, rel_root))
415+
_url = setup_link(an, link_base, rel_root)
416+
s += md_kv("Link to code", f"[{Path(_url).name}]({_url})")
345417

346418
exclude = {"__doc__", "__module__", "__weakref__", "__dict__"}
347419
cv = class_vars_dump(an, exclude)
348420
if cv:
349421
s += md_header("Class Variables", 3) + md_list(cv)
350422

351-
req = get_attr(an, "REQUIRED_DATA", None)
352-
s += md_header("Required Data", 3)
353-
if req:
354-
if isinstance(req, (list, tuple)):
355-
s += ", ".join(getattr(m, "__name__", str(m)) for m in req) + "\n\n"
356-
else:
357-
s += getattr(req, "__name__", str(req)) + "\n\n"
358-
else:
359-
s += "-\n\n"
423+
# Add regex patterns if present (pass None for args_cls since we don't have context here)
424+
regex_info = extract_regexes_and_args_from_analyzer(an, None)
425+
if regex_info:
426+
s += md_header("Regex Patterns", 3)
427+
if len(regex_info) > 10:
428+
s += f"*{len(regex_info)} items defined*\n\n"
429+
s += md_list(regex_info)
360430

361431
return s
362432

363433

364-
def render_model_section(model: type, link_base: str, rel_root: str | None) -> str:
434+
def render_model_section(model: type, link_base: str, rel_root: Optional[str]) -> str:
365435
hdr = md_header(f"{model.__name__} Model", 2)
366436
desc = sanitize_doc(get_own_doc(model) or "")
367437
s = hdr
368438
if desc:
369439
s += md_header("Description", 3) + desc + "\n\n"
370-
s += md_kv("Link to code", setup_link(model, link_base, rel_root))
440+
_url = setup_link(model, link_base, rel_root)
441+
s += md_kv("Link to code", f"[{Path(_url).name}]({_url})")
371442
s += md_kv("Bases", str(bases_list(model)))
372443
anns = annotations_for_model(model)
373444
if anns:
374445
s += md_header("Model annotations and fields", 3) + md_list(anns)
375446
return s
376447

377448

378-
def render_analyzer_args_section(args_cls: type, link_base: str, rel_root: str | None) -> str:
449+
def render_analyzer_args_section(args_cls: type, link_base: str, rel_root: Optional[str]) -> str:
379450
hdr = md_header(f"Analyzer Args Class {args_cls.__name__}", 2)
380451
desc = sanitize_doc(get_own_doc(args_cls) or "")
381452
s = hdr
382453
if desc:
383454
s += md_header("Description", 3) + desc + "\n\n"
384455
s += md_kv("Bases", str(bases_list(args_cls)))
385-
s += md_kv("Link to code", setup_link(args_cls, link_base, rel_root))
386-
387-
exclude = {"__doc__", "__module__", "__weakref__", "__dict__"}
388-
cv = class_vars_dump(args_cls, exclude)
389-
if cv:
390-
s += md_header("Class Variables", 3) + md_list(cv)
456+
_url = setup_link(args_cls, link_base, rel_root)
457+
s += md_kv("Link to code", f"[{Path(_url).name}]({_url})")
391458

392459
anns = get_attr(args_cls, "__annotations__", {}) or {}
393460
if anns:
@@ -429,7 +496,14 @@ def all_subclasses(cls: Type) -> set[type]:
429496
plugins.sort(key=lambda c: f"{c.__module__}.{c.__name__}".lower())
430497

431498
rows = generate_plugin_table_rows(plugins)
432-
headers = ["Plugin", "DataModel", "Collector", "Analyzer", "AnalyzerArgs", "Cmd(s)"]
499+
headers = [
500+
"Plugin",
501+
"Collection",
502+
"Analysis",
503+
"DataModel",
504+
"Collector",
505+
"Analyzer",
506+
]
433507

434508
collectors, analyzers, models, args_classes = [], [], [], []
435509
seen_c, seen_a, seen_m, seen_args = set(), set(), set(), set()

nodescraper/base/inbandcollectortask.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#
2525
###############################################################################
2626
import logging
27-
from typing import Generic, Optional
27+
from typing import Generic, Optional, Union
2828

2929
from nodescraper.connection.inband import InBandConnection
3030
from nodescraper.connection.inband.inband import BaseFileArtifact, CommandArtifact
@@ -49,7 +49,7 @@ def __init__(
4949
connection: InBandConnection,
5050
logger: Optional[logging.Logger] = None,
5151
system_interaction_level: SystemInteractionLevel = SystemInteractionLevel.INTERACTIVE,
52-
max_event_priority_level: EventPriority | str = EventPriority.CRITICAL,
52+
max_event_priority_level: Union[EventPriority, str] = EventPriority.CRITICAL,
5353
parent: Optional[str] = None,
5454
task_result_hooks: Optional[list[TaskResultHook]] = None,
5555
**kwargs,

nodescraper/base/regexanalyzer.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#
2525
###############################################################################
2626
import re
27+
from typing import Union
2728

2829
from pydantic import BaseModel
2930

@@ -36,7 +37,7 @@
3637
class ErrorRegex(BaseModel):
3738
regex: re.Pattern
3839
message: str
39-
event_category: str | EventCategory = EventCategory.UNKNOWN
40+
event_category: Union[str, EventCategory] = EventCategory.UNKNOWN
4041
event_priority: EventPriority = EventPriority.ERROR
4142

4243

@@ -54,14 +55,15 @@ class RegexAnalyzer(DataAnalyzer[TDataModel, TAnalyzeArg]):
5455
"""Parent class for all regex based data analyzers."""
5556

5657
def _build_regex_event(
57-
self, regex_obj: ErrorRegex, match: str | list[str], source: str
58+
self, regex_obj: ErrorRegex, match: Union[str, list[str]], source: str
5859
) -> RegexEvent:
5960
"""Build a RegexEvent object from a regex match and source.
6061
6162
Args:
6263
regex_obj (ErrorRegex): regex object containing the regex pattern, message, category, and priorit
63-
match (str | list[str]): matched content from the regex
64-
source (str): descriptor for the content where the match was found
64+
match (
65+
Union[str, list[str]]): matched content from the regex
66+
source (str): descriptor for the content where the match was found
6567
6668
Returns:
6769
RegexEvent: an instance of RegexEvent containing the match details

nodescraper/cli/cli.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,17 +264,18 @@ def build_parser(
264264
model_type_map = parser_builder.build_plugin_parser()
265265
except Exception as e:
266266
print(f"Exception building arg parsers for {plugin_name}: {str(e)}") # noqa: T201
267+
continue
267268
plugin_subparser_map[plugin_name] = (plugin_subparser, model_type_map)
268269

269270
return parser, plugin_subparser_map
270271

271272

272-
def setup_logger(log_level: str = "INFO", log_path: str | None = None) -> logging.Logger:
273+
def setup_logger(log_level: str = "INFO", log_path: Optional[str] = None) -> logging.Logger:
273274
"""set up root logger when using the CLI
274275
275276
Args:
276277
log_level (str): log level to use
277-
log_path (str | None): optional path to filesystem log location
278+
log_path (Optional[str]): optional path to filesystem log location
278279
279280
Returns:
280281
logging.Logger: logger intstance

nodescraper/cli/dynamicparserbuilder.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
#
2525
###############################################################################
2626
import argparse
27-
import types
28-
from typing import Type
27+
from typing import Optional, Type
2928

3029
from pydantic import BaseModel
3130

@@ -59,7 +58,7 @@ def build_plugin_parser(self) -> dict:
5958
}
6059

6160
# skip args where generic type has been set to None
62-
if types.NoneType in type_class_map:
61+
if type(None) in type_class_map:
6362
continue
6463

6564
model_arg = self.get_model_arg(type_class_map)
@@ -75,14 +74,14 @@ def build_plugin_parser(self) -> dict:
7574
return model_type_map
7675

7776
@classmethod
78-
def get_model_arg(cls, type_class_map: dict) -> Type[BaseModel] | None:
77+
def get_model_arg(cls, type_class_map: dict) -> Optional[Type[BaseModel]]:
7978
"""Get the first type which is a pydantic model from a type class map
8079
8180
Args:
8281
type_class_map (dict): mapping of type classes
8382
8483
Returns:
85-
Type[BaseModel] | None: pydantic model type
84+
Optional[Type[BaseModel]]: pydantic model type
8685
"""
8786
return next(
8887
(
@@ -164,7 +163,7 @@ def build_model_arg_parser(self, model: type[BaseModel], required: bool) -> list
164163
type_class.type_class: type_class for type_class in attr_data.type_classes
165164
}
166165

167-
if types.NoneType in type_class_map and len(attr_data.type_classes) == 1:
166+
if type(None) in type_class_map and len(attr_data.type_classes) == 1:
168167
continue
169168

170169
self.add_argument(type_class_map, attr.replace("_", "-"), required)

0 commit comments

Comments
 (0)