The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/pkg/plugins/queries.go

72 lines
1.5 KiB

package plugins
import (
"github.com/grafana/grafana/pkg/bus"
m "github.com/grafana/grafana/pkg/models"
)
func GetOrgAppSettings(orgId int64) (map[string]*m.AppSettings, error) {
query := m.GetAppSettingsQuery{OrgId: orgId}
if err := bus.Dispatch(&query); err != nil {
return nil, err
}
orgAppsMap := make(map[string]*m.AppSettings)
for _, orgApp := range query.Result {
orgAppsMap[orgApp.AppId] = orgApp
}
return orgAppsMap, nil
}
func GetEnabledPlugins(orgId int64) (*EnabledPlugins, error) {
enabledPlugins := NewEnabledPlugins()
orgApps, err := GetOrgAppSettings(orgId)
if err != nil {
return nil, err
}
enabledApps := make(map[string]bool)
for appId, installedApp := range Apps {
var app AppPlugin
app = *installedApp
// check if the app is stored in the DB for this org and if so, use the
// state stored there.
if b, ok := orgApps[appId]; ok {
app.Enabled = b.Enabled
app.Pinned = b.Pinned
}
if app.Enabled {
enabledApps[app.Id] = true
enabledPlugins.Apps = append(enabledPlugins.Apps, &app)
}
}
isPluginEnabled := func(appId string) bool {
if appId == "" {
return true
}
_, ok := enabledApps[appId]
return ok
}
// add all plugins that are not part of an App.
for dsId, ds := range DataSources {
if isPluginEnabled(ds.IncludedInAppId) {
enabledPlugins.DataSources[dsId] = ds
}
}
for _, panel := range Panels {
if isPluginEnabled(panel.IncludedInAppId) {
enabledPlugins.Panels = append(enabledPlugins.Panels, panel)
}
}
return &enabledPlugins, nil
}