The SysCapture plugin system allows for extending functionality through plugins. Each plugin is a self-contained module with its own configuration and implementation.
plugins/
├── sample/
│ ├── plugin.json # Plugin configuration
│ └── plugin.go # Plugin implementation
└── other-plugin/
├── plugin.json
└── plugin.go
Create a plugin.json file in your plugin directory:
{
"name": "my-plugin",
"version": "1.0.0",
"description": "My plugin description",
"author": "Your Name",
"enabled": true,
"dependencies": ["other-plugin"],
"settings": {
"interval": "30s",
"maxRetries": 3,
"debugMode": false
}
}Create a Go file implementing the Plugin interface:
package myplugin
import (
"github.com/nodebytehosting/syscapture/internal/plugin"
)
type MyPlugin struct {
*plugin.BasePlugin
// Add custom fields here
}
func NewPlugin(config *plugin.PluginConfig) (*MyPlugin, error) {
// Validate settings
// Initialize plugin
return &MyPlugin{
BasePlugin: plugin.NewBasePlugin(config),
}, nil
}
func (p *MyPlugin) Start() error {
p.Logger().Info("Starting plugin")
return nil
}
func (p *MyPlugin) Stop() error {
p.Logger().Info("Stopping plugin")
return nil
}Plugins must implement the following interface:
type Plugin interface {
Name() string
Version() string
Description() string
IsEnabled() bool
State() PluginState
Logger() Logger
Init(logger Logger) error
Start() error
Stop() error
}- Discovery: The system scans the
plugins/directory - Loading: Each plugin's configuration is loaded and validated
- Initialization: Plugins are initialized with required dependencies
- Starting: Plugins are started in dependency order
- Running: Plugins perform their tasks
- Stopping: Plugins are stopped in reverse dependency order
- Cleanup: Resources are released
name: Unique plugin identifierversion: Plugin versiondescription: Plugin descriptionenabled: Whether the plugin should be loaded
author: Plugin authordependencies: List of required pluginssettings: Custom plugin settings
-
Error Handling
if err != nil { return fmt.Errorf("plugin error: %w", err) }
-
Logging
p.Logger().Info("Plugin message") p.Logger().Debug("Debug information") p.Logger().Error("Error: %v", err)
-
Resource Management
func (p *MyPlugin) Stop() error { // Clean up resources close(p.stopChan) return nil }
// filepath: /plugins/example/plugin.go
package example
import (
"github.com/nodebytehosting/syscapture/internal/plugin"
)
type ExamplePlugin struct {
*plugin.BasePlugin
}
func NewPlugin(config *plugin.PluginConfig) (*ExamplePlugin, error) {
return &ExamplePlugin{
BasePlugin: plugin.NewBasePlugin(config),
}, nil
}// filepath: /plugins/example/plugin.json
{
"name": "example",
"version": "1.0.0",
"description": "Example plugin",
"enabled": true,
"settings": {
"customSetting": "value"
}
}-
Enable debug mode in plugin configuration:
{ "settings": { "debugMode": true } } -
Check plugin status:
status, err := pluginManager.GetPluginStatus("plugin-name")
-
View plugin events:
events := pluginManager.GetEvents()
-
Plugin Not Loading
- Check plugin.json syntax
- Verify plugin directory structure
- Check dependencies are available
-
Plugin Fails to Start
- Check required settings
- Verify dependencies are started
- Check logs for errors
-
Plugin Crashes
- Implement proper error handling
- Use debug mode for detailed logging
- Check resource cleanup