|
|
|
@ -23,8 +23,7 @@ var ( |
|
|
|
StaticRoutes []*PluginStaticRoute |
|
|
|
StaticRoutes []*PluginStaticRoute |
|
|
|
Apps map[string]*AppPlugin |
|
|
|
Apps map[string]*AppPlugin |
|
|
|
Plugins map[string]*PluginBase |
|
|
|
Plugins map[string]*PluginBase |
|
|
|
//BackendDatasources map[string]*BackendDatasource
|
|
|
|
PluginTypes map[string]interface{} |
|
|
|
PluginTypes map[string]interface{} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GrafanaLatestVersion string |
|
|
|
GrafanaLatestVersion string |
|
|
|
GrafanaHasUpdate bool |
|
|
|
GrafanaHasUpdate bool |
|
|
|
@ -43,7 +42,12 @@ type PluginManager struct { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func NewPluginManager(ctx context.Context) (*PluginManager, error) { |
|
|
|
func NewPluginManager(ctx context.Context) (*PluginManager, error) { |
|
|
|
Init(ctx) |
|
|
|
err := initPlugins(ctx) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return nil, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return &PluginManager{ |
|
|
|
return &PluginManager{ |
|
|
|
log: log.New("plugins"), |
|
|
|
log: log.New("plugins"), |
|
|
|
}, nil |
|
|
|
}, nil |
|
|
|
@ -60,14 +64,14 @@ func (p *PluginManager) Run(ctx context.Context) error { |
|
|
|
return ctx.Err() |
|
|
|
return ctx.Err() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func Init(ctx context.Context) error { |
|
|
|
func initPlugins(ctx context.Context) error { |
|
|
|
plog = log.New("plugins") |
|
|
|
plog = log.New("plugins") |
|
|
|
|
|
|
|
|
|
|
|
DataSources = make(map[string]*DataSourcePlugin) |
|
|
|
DataSources = map[string]*DataSourcePlugin{} |
|
|
|
StaticRoutes = make([]*PluginStaticRoute, 0) |
|
|
|
StaticRoutes = []*PluginStaticRoute{} |
|
|
|
Panels = make(map[string]*PanelPlugin) |
|
|
|
Panels = map[string]*PanelPlugin{} |
|
|
|
Apps = make(map[string]*AppPlugin) |
|
|
|
Apps = map[string]*AppPlugin{} |
|
|
|
Plugins = make(map[string]*PluginBase) |
|
|
|
Plugins = map[string]*PluginBase{} |
|
|
|
PluginTypes = map[string]interface{}{ |
|
|
|
PluginTypes = map[string]interface{}{ |
|
|
|
"panel": PanelPlugin{}, |
|
|
|
"panel": PanelPlugin{}, |
|
|
|
"datasource": DataSourcePlugin{}, |
|
|
|
"datasource": DataSourcePlugin{}, |
|
|
|
@ -79,9 +83,8 @@ func Init(ctx context.Context) error { |
|
|
|
|
|
|
|
|
|
|
|
// check if plugins dir exists
|
|
|
|
// check if plugins dir exists
|
|
|
|
if _, err := os.Stat(setting.PluginsPath); os.IsNotExist(err) { |
|
|
|
if _, err := os.Stat(setting.PluginsPath); os.IsNotExist(err) { |
|
|
|
plog.Warn("Plugin dir does not exist", "dir", setting.PluginsPath) |
|
|
|
|
|
|
|
if err = os.MkdirAll(setting.PluginsPath, os.ModePerm); err != nil { |
|
|
|
if err = os.MkdirAll(setting.PluginsPath, os.ModePerm); err != nil { |
|
|
|
plog.Warn("Failed to create plugin dir", "dir", setting.PluginsPath, "error", err) |
|
|
|
plog.Error("Failed to create plugin dir", "dir", setting.PluginsPath, "error", err) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
plog.Info("Plugin dir created", "dir", setting.PluginsPath) |
|
|
|
plog.Info("Plugin dir created", "dir", setting.PluginsPath) |
|
|
|
scan(setting.PluginsPath) |
|
|
|
scan(setting.PluginsPath) |
|
|
|
@ -96,13 +99,18 @@ func Init(ctx context.Context) error { |
|
|
|
for _, panel := range Panels { |
|
|
|
for _, panel := range Panels { |
|
|
|
panel.initFrontendPlugin() |
|
|
|
panel.initFrontendPlugin() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for _, ds := range DataSources { |
|
|
|
for _, ds := range DataSources { |
|
|
|
if ds.Backend { |
|
|
|
if ds.Backend { |
|
|
|
ds.initBackendPlugin(ctx, plog) |
|
|
|
err := ds.initBackendPlugin(ctx, plog) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
plog.Error("Failed to init plugin.", "error", err, "plugin", ds.Id) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ds.initFrontendPlugin() |
|
|
|
ds.initFrontendPlugin() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for _, app := range Apps { |
|
|
|
for _, app := range Apps { |
|
|
|
app.initApp() |
|
|
|
app.initApp() |
|
|
|
} |
|
|
|
} |
|
|
|
|