xref: /openbmc/openbmc-test-automation/ffdc/docs/plugin.md (revision 48c5967fe3d40f69c21e40e0f444f710d00bfe0b)
1### Plugin
2
3Plugin feature for the log collector is to load a user python functions at runtime by the engine and execute it.
4
5The design infrastructure allows user to extend or call their existing python scripts without needing to expose
6the implementation.  This enriches the log collection and mechanize the work flow as per user driven as per
7their requirement,
8
9### Understanding Plugin
10The plugin works like any stand-alone piece of python script or library function.
11
12The main components in plugin infrastructure are:
13
14- plugin directory
15- plugin directive in YAML
16- plugin parser in the collector engine
17
18### Plugin Directory
19Python module script are added or copied to `plugins` directory and the log engine loads these plugins during
20runtime and on demand from the YAML else they are not invoked automatically.
21
22Example:
23```
24plugins/
25├── foo_func.py
26├── ssh_execution.py
27└── telnet_execution.py
28```
29
30### Plugin Template Example
31
32plugins/foo_func.py
33```
34# Sample for documentation plugin
35
36def print_vars(var):
37    print(var)
38
39def return_vars():
40    return 1
41```
42
43You can add your own plugin modules to extend further.
44
45Test your plugin:
46```
47python3 plugins/foo_func.py
48```
49
50### YAML Syntax
51
52```
53    - plugin:
54        - plugin_name: plugin.foo_func.print_vars
55        - plugin_args:
56               - "Hello plugin"
57    - plugin:
58        -plugin_name:  return_value = plugin.foo_func.return_vars
59        - plugin_args:
60```
61
62### Plugin execution output for sample
63
64
65```
66        [PLUGIN-START]
67        Call func: plugin.foo_func.print_vars("Hello plugin")
68        Hello plugin
69        return: None
70        [PLUGIN-END]
71
72        [PLUGIN-START]
73        Call func: plugin.foo_func.return_vars()
74        return: 1
75        [PLUGIN-END]
76```
77