Skip to content

Commit 3d80fdb

Browse files
committed
added sample file for integrationg
1 parent c954643 commit 3d80fdb

File tree

1 file changed

+81
-5
lines changed

1 file changed

+81
-5
lines changed

README.md

Lines changed: 81 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ system debug.
1010
- [Example: Remote Execution](#example-remote-execution)
1111
- [Example connection_config.json](#example-connection_configjson)
1212
- [Subcommmands](#subcommmands)
13+
- [Configs](#plugin-configs)
1314
- [Plugin Configs](#plugin-configs)
1415

1516

@@ -83,7 +84,7 @@ To use remote execution, specify `--sys-location REMOTE` and provide a connectio
8384
node-scraper --sys-name <remote_host> --sys-location REMOTE --connection-config ./connection_config.json run-plugins DmesgPlugin
8485
```
8586
86-
##### Example connection_config.json
87+
##### Example: connection_config.json
8788
8889
```json
8990
{
@@ -101,7 +102,7 @@ node-scraper --sys-name <remote_host> --sys-location REMOTE --connection-config
101102
- If using SSH keys, specify `key_filename` instead of `password`.
102103
- The remote user must have permissions to run the requested plugins and access required files. If needed, use the `--skip-sudo` argument to skip plugins requiring sudo.
103104
104-
### Subcommmands
105+
### Subcommands
105106
106107
Plugins to run can be specified in two ways, using a plugin JSON config file or using the
107108
'run-plugins' sub command. These two options are not mutually exclusive and can be used together.
@@ -221,7 +222,7 @@ This will generate a new file '/<path_to_node-scraper_logs>/summary.csv' file. T
221222
contain the results from all 'nodescraper.csv' files from '/<path_to_node-scarper_logs>'.
222223
223224
224-
### Plugin Configs
225+
### Configs
225226
A plugin JSON config should follow the structure of the plugin config model defined here.
226227
The globals field is a dictionary of global key-value pairs; values in globals will be passed to
227228
any plugin that supports the corresponding key. The plugins field should be a dictionary mapping
@@ -248,7 +249,7 @@ tabular format to the console.
248249
}
249250
```
250251
251-
1. **'--plugin-configs' command**
252+
1. Plugin config: **'--plugin-configs' command**
252253
A plugin config can be used to compare the system data against the config specifications:
253254
```sh
254255
node-scraper --plugin-configs plugin_config.json
@@ -306,7 +307,7 @@ Here is an example of a comprehensive plugin config that specifies analyzer args
306307
}
307308
```
308309
309-
2. **'gen-reference-config' command**
310+
2. Reference config: **'gen-reference-config' command**
310311
This command can be used to generate a reference config that is populated with current system
311312
configurations. Plugins that use analyzer args (where applicable) will be populated with system
312313
data.
@@ -352,3 +353,78 @@ node-scraper gen-plugin-config --gen-reference-config-from-logs scraper_logs_<pa
352353
```
353354
This will generate a reference config that includes plugins with logged results in
354355
'scraper_log_<path>' and save the new config to 'custom_output_dir/reference_config.json'.
356+
357+
358+
## nodescraper integration
359+
Nodescraper can be integrated inside another Python tool by leveraging its classes and functionality.
360+
See bellow for a comprehensive example on how to create plugins and run the associated data
361+
collection and analysis.
362+
Sample run command:
363+
```
364+
python3 sample.py
365+
```
366+
367+
Sample.py file:
368+
```
369+
import logging
370+
import sys
371+
from nodescraper.plugins.inband.bios.bios_plugin import BiosPlugin
372+
from nodescraper.plugins.inband.bios.analyzer_args import BiosAnalyzerArgs
373+
from nodescraper.plugins.inband.kernel.kernel_plugin import KernelPlugin
374+
from nodescraper.plugins.inband.kernel.analyzer_args import KernelAnalyzerArgs
375+
from nodescraper.pluginregistry import PluginRegistry
376+
from nodescraper.models.systeminfo import SystemInfo, OSFamily
377+
from nodescraper.enums import EventPriority
378+
from nodescraper.resultcollators.tablesummary import TableSummary
379+
380+
def main():
381+
382+
#setting up my custom logger
383+
log_level = "INFO"
384+
handlers = [logging.StreamHandler(stream=sys.stdout)]
385+
logging.basicConfig(
386+
force=True,
387+
level=log_level,
388+
format="%(asctime)25s %(levelname)10s %(name)25s | %(message)s",
389+
datefmt="%Y-%m-%d %H:%M:%S %Z",
390+
handlers=handlers,
391+
encoding="utf-8",
392+
)
393+
logging.root.setLevel(logging.INFO)
394+
logging.getLogger("paramiko").setLevel(logging.ERROR)
395+
logger = logging.getLogger("nodescraper")
396+
397+
#setting up system info
398+
system_info = SystemInfo(name="test_host",
399+
platform="X",
400+
os_familty=OSFamily.LINUX,
401+
sku="some_sku")
402+
403+
#initiate plugins
404+
bios_plugin = BiosPlugin(system_info=system_info, logger=logger)
405+
kernel_plugin = KernelPlugin(system_info=system_info, logger=logger)
406+
407+
#launch data collection
408+
_ = bios_plugin.collect()
409+
_ = kernel_plugin.collect()
410+
411+
#launch data analysis
412+
bios_plugin.analyze(analysis_args=BiosAnalyzerArgs(exp_bios_version="XYZ"))
413+
kernel_plugin.analyze(analysis_args=KernelAnalyzerArgs(exp_kernel="ABC"))
414+
415+
#log plugin data models
416+
logger.info(kernel_plugin.data.model_dump())
417+
logger.info(bios_plugin.data.model_dump())
418+
419+
#alternate method
420+
all_res = []
421+
422+
#launch plugin collection & analysis
423+
bios_result = bios_plugin.run(analysis_args={"exp_bios_version":"ABC"})
424+
all_res.append(bios_result)
425+
table_summary = TableSummary()
426+
table_summary.collate_results(all_res, None)
427+
428+
if __name__ == "__main__":
429+
main()
430+
```

0 commit comments

Comments
 (0)