2014-12-29 06:36:08 -06:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2021-11-02 07:42:55 -05:00
|
|
|
"context"
|
2022-04-15 07:01:58 -05:00
|
|
|
"net/http"
|
2014-12-29 06:36:08 -06:00
|
|
|
"strconv"
|
|
|
|
|
2021-10-05 08:54:26 -05:00
|
|
|
"github.com/grafana/grafana/pkg/models"
|
2015-02-27 15:29:00 -06:00
|
|
|
"github.com/grafana/grafana/pkg/plugins"
|
2021-10-05 08:54:26 -05:00
|
|
|
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
2022-06-27 11:23:15 -05:00
|
|
|
"github.com/grafana/grafana/pkg/services/datasources"
|
2022-10-07 05:39:14 -05:00
|
|
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
2022-03-16 08:37:19 -05:00
|
|
|
"github.com/grafana/grafana/pkg/services/licensing"
|
2022-03-18 14:49:13 -05:00
|
|
|
"github.com/grafana/grafana/pkg/services/pluginsettings"
|
2022-08-10 14:47:03 -05:00
|
|
|
"github.com/grafana/grafana/pkg/services/secrets/kvstore"
|
2015-02-05 03:37:13 -06:00
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
2021-10-05 08:54:26 -05:00
|
|
|
"github.com/grafana/grafana/pkg/tsdb/grafanads"
|
|
|
|
"github.com/grafana/grafana/pkg/util"
|
2014-12-29 06:36:08 -06:00
|
|
|
)
|
|
|
|
|
2022-03-18 14:49:13 -05:00
|
|
|
func (hs *HTTPServer) GetFrontendSettings(c *models.ReqContext) {
|
|
|
|
settings, err := hs.getFrontendSettingsMap(c)
|
|
|
|
if err != nil {
|
|
|
|
c.JsonApiErr(400, "Failed to get frontend settings", err)
|
|
|
|
return
|
2015-08-16 13:52:30 -05:00
|
|
|
}
|
2015-02-28 02:46:37 -06:00
|
|
|
|
2022-04-15 07:01:58 -05:00
|
|
|
c.JSON(http.StatusOK, settings)
|
2020-09-07 15:10:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// getFrontendSettingsMap returns a json object with all the settings needed for front end initialisation.
|
|
|
|
func (hs *HTTPServer) getFrontendSettingsMap(c *models.ReqContext) (map[string]interface{}, error) {
|
2022-08-11 06:28:55 -05:00
|
|
|
enabledPlugins, err := hs.enabledPlugins(c.Req.Context(), c.OrgID)
|
2020-09-07 15:10:06 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-02-25 03:00:21 -06:00
|
|
|
|
2021-12-14 04:16:13 -06:00
|
|
|
pluginsToPreload := make([]*plugins.PreloadPlugin, 0)
|
2021-11-01 04:53:33 -05:00
|
|
|
for _, app := range enabledPlugins[plugins.App] {
|
2020-09-07 15:10:06 -05:00
|
|
|
if app.Preload {
|
2021-12-14 04:16:13 -06:00
|
|
|
pluginsToPreload = append(pluginsToPreload, &plugins.PreloadPlugin{
|
2021-11-10 04:54:58 -06:00
|
|
|
Path: app.Module,
|
|
|
|
Version: app.Info.Version,
|
|
|
|
})
|
2020-09-07 15:10:06 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-28 05:24:42 -06:00
|
|
|
dataSources, err := hs.getFSDataSources(c, enabledPlugins)
|
2020-09-07 15:10:06 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
defaultDS := "-- Grafana --"
|
|
|
|
for n, ds := range dataSources {
|
2021-12-14 04:16:13 -06:00
|
|
|
if ds.IsDefault {
|
2020-09-07 15:10:06 -05:00
|
|
|
defaultDS = n
|
|
|
|
}
|
2014-12-29 06:36:08 -06:00
|
|
|
}
|
|
|
|
|
2021-12-14 04:16:13 -06:00
|
|
|
panels := make(map[string]plugins.PanelDTO)
|
2021-11-01 04:53:33 -05:00
|
|
|
for _, panel := range enabledPlugins[plugins.Panel] {
|
|
|
|
if panel.State == plugins.AlphaRelease && !hs.Cfg.PluginsEnableAlpha {
|
2018-10-09 10:47:43 -05:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2022-10-07 05:39:14 -05:00
|
|
|
hideFromList := panel.HideFromList
|
|
|
|
if panel.ID == "flamegraph" {
|
|
|
|
hideFromList = !hs.Features.IsEnabled(featuremgmt.FlagFlameGraph)
|
|
|
|
}
|
|
|
|
|
2021-12-14 04:16:13 -06:00
|
|
|
panels[panel.ID] = plugins.PanelDTO{
|
|
|
|
ID: panel.ID,
|
|
|
|
Name: panel.Name,
|
|
|
|
Info: panel.Info,
|
|
|
|
Module: panel.Module,
|
|
|
|
BaseURL: panel.BaseURL,
|
|
|
|
SkipDataQuery: panel.SkipDataQuery,
|
2022-10-07 05:39:14 -05:00
|
|
|
HideFromList: hideFromList,
|
2021-12-14 04:16:13 -06:00
|
|
|
ReleaseState: string(panel.State),
|
|
|
|
Signature: string(panel.Signature),
|
|
|
|
Sort: getPanelSort(panel.ID),
|
2015-11-21 06:46:18 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-17 00:39:50 -05:00
|
|
|
hideVersion := hs.Cfg.AnonymousHideVersion && !c.IsSignedIn
|
|
|
|
version := setting.BuildVersion
|
|
|
|
commit := setting.BuildCommit
|
|
|
|
buildstamp := setting.BuildStamp
|
|
|
|
|
|
|
|
if hideVersion {
|
|
|
|
version = ""
|
|
|
|
commit = ""
|
|
|
|
buildstamp = 0
|
|
|
|
}
|
|
|
|
|
2021-10-05 08:54:26 -05:00
|
|
|
hasAccess := accesscontrol.HasAccess(hs.AccessControl, c)
|
2022-09-02 07:20:10 -05:00
|
|
|
secretsManagerPluginEnabled := kvstore.EvaluateRemoteSecretsPlugin(c.Req.Context(), hs.secretsPluginManager, hs.Cfg) == nil
|
2021-10-05 08:54:26 -05:00
|
|
|
|
2014-12-29 06:36:08 -06:00
|
|
|
jsonObj := map[string]interface{}{
|
2021-09-15 06:00:38 -05:00
|
|
|
"defaultDatasource": defaultDS,
|
|
|
|
"datasources": dataSources,
|
|
|
|
"minRefreshInterval": setting.MinRefreshInterval,
|
|
|
|
"panels": panels,
|
|
|
|
"appUrl": hs.Cfg.AppURL,
|
|
|
|
"appSubUrl": hs.Cfg.AppSubURL,
|
|
|
|
"allowOrgCreate": (setting.AllowUserOrgCreate && c.IsSignedIn) || c.IsGrafanaAdmin,
|
|
|
|
"authProxyEnabled": setting.AuthProxyEnabled,
|
|
|
|
"ldapEnabled": hs.Cfg.LDAPEnabled,
|
2022-07-27 09:10:47 -05:00
|
|
|
"jwtHeaderName": hs.Cfg.JWTAuthHeaderName,
|
|
|
|
"jwtUrlLogin": hs.Cfg.JWTAuthURLLogin,
|
2021-09-15 06:00:38 -05:00
|
|
|
"alertingEnabled": setting.AlertingEnabled,
|
|
|
|
"alertingErrorOrTimeout": setting.AlertingErrorOrTimeout,
|
|
|
|
"alertingNoDataOrNullValues": setting.AlertingNoDataOrNullValues,
|
|
|
|
"alertingMinInterval": setting.AlertingMinInterval,
|
|
|
|
"liveEnabled": hs.Cfg.LiveMaxConnections != 0,
|
|
|
|
"autoAssignOrg": setting.AutoAssignOrg,
|
|
|
|
"verifyEmailEnabled": setting.VerifyEmailEnabled,
|
|
|
|
"sigV4AuthEnabled": setting.SigV4AuthEnabled,
|
2022-08-11 09:12:57 -05:00
|
|
|
"azureAuthEnabled": setting.AzureAuthEnabled,
|
2022-05-16 05:45:41 -05:00
|
|
|
"rbacEnabled": hs.Cfg.RBACEnabled,
|
2021-09-15 06:00:38 -05:00
|
|
|
"exploreEnabled": setting.ExploreEnabled,
|
2022-03-29 10:27:53 -05:00
|
|
|
"helpEnabled": setting.HelpEnabled,
|
|
|
|
"profileEnabled": setting.ProfileEnabled,
|
2022-01-28 10:55:09 -06:00
|
|
|
"queryHistoryEnabled": hs.Cfg.QueryHistoryEnabled,
|
2021-09-15 06:00:38 -05:00
|
|
|
"googleAnalyticsId": setting.GoogleAnalyticsId,
|
2022-09-20 05:13:14 -05:00
|
|
|
"googleAnalytics4Id": setting.GoogleAnalytics4Id,
|
2022-11-09 08:09:19 -06:00
|
|
|
"GoogleAnalytics4SendManualPageViews": setting.GoogleAnalytics4SendManualPageViews,
|
2021-09-15 06:00:38 -05:00
|
|
|
"rudderstackWriteKey": setting.RudderstackWriteKey,
|
|
|
|
"rudderstackDataPlaneUrl": setting.RudderstackDataPlaneUrl,
|
2021-12-06 08:42:29 -06:00
|
|
|
"rudderstackSdkUrl": setting.RudderstackSdkUrl,
|
|
|
|
"rudderstackConfigUrl": setting.RudderstackConfigUrl,
|
2022-04-14 08:18:03 -05:00
|
|
|
"feedbackLinksEnabled": hs.Cfg.FeedbackLinksEnabled,
|
2021-09-15 06:00:38 -05:00
|
|
|
"applicationInsightsConnectionString": hs.Cfg.ApplicationInsightsConnectionString,
|
|
|
|
"applicationInsightsEndpointUrl": hs.Cfg.ApplicationInsightsEndpointUrl,
|
|
|
|
"disableLoginForm": setting.DisableLoginForm,
|
|
|
|
"disableUserSignUp": !setting.AllowUserSignUp,
|
|
|
|
"loginHint": setting.LoginHint,
|
|
|
|
"passwordHint": setting.PasswordHint,
|
|
|
|
"externalUserMngInfo": setting.ExternalUserMngInfo,
|
|
|
|
"externalUserMngLinkUrl": setting.ExternalUserMngLinkUrl,
|
|
|
|
"externalUserMngLinkName": setting.ExternalUserMngLinkName,
|
|
|
|
"viewersCanEdit": setting.ViewersCanEdit,
|
2022-02-16 10:14:33 -06:00
|
|
|
"angularSupportEnabled": hs.Cfg.AngularSupportEnabled,
|
2021-09-15 06:00:38 -05:00
|
|
|
"editorsCanAdmin": hs.Cfg.EditorsCanAdmin,
|
|
|
|
"disableSanitizeHtml": hs.Cfg.DisableSanitizeHtml,
|
|
|
|
"pluginsToPreload": pluginsToPreload,
|
2022-09-15 11:06:09 -05:00
|
|
|
"auth": map[string]interface{}{
|
|
|
|
"OAuthSkipOrgRoleUpdateSync": hs.Cfg.OAuthSkipOrgRoleUpdateSync,
|
|
|
|
"SAMLSkipOrgRoleSync": hs.Cfg.SectionWithEnvOverrides("auth.saml").Key("skip_org_role_sync").MustBool(false),
|
2022-10-12 06:33:33 -05:00
|
|
|
"LDAPSkipOrgRoleSync": hs.Cfg.LDAPSkipOrgRoleSync,
|
2022-09-20 10:48:40 -05:00
|
|
|
"DisableSyncLock": hs.Cfg.DisableSyncLock,
|
2022-09-15 11:06:09 -05:00
|
|
|
},
|
2015-01-05 03:46:58 -06:00
|
|
|
"buildInfo": map[string]interface{}{
|
2020-06-17 00:39:50 -05:00
|
|
|
"hideVersion": hideVersion,
|
|
|
|
"version": version,
|
|
|
|
"commit": commit,
|
|
|
|
"buildstamp": buildstamp,
|
2020-01-27 02:24:44 -06:00
|
|
|
"edition": hs.License.Edition(),
|
2022-01-31 09:06:16 -06:00
|
|
|
"latestVersion": hs.grafanaUpdateChecker.LatestVersion(),
|
|
|
|
"hasUpdate": hs.grafanaUpdateChecker.UpdateAvailable(),
|
2016-05-17 08:00:48 -05:00
|
|
|
"env": setting.Env,
|
2019-11-01 08:56:12 -05:00
|
|
|
},
|
|
|
|
"licenseInfo": map[string]interface{}{
|
2022-01-24 09:08:05 -06:00
|
|
|
"expiry": hs.License.Expiry(),
|
|
|
|
"stateInfo": hs.License.StateInfo(),
|
2022-03-16 08:37:19 -05:00
|
|
|
"licenseUrl": hs.License.LicenseURL(hasAccess(accesscontrol.ReqGrafanaAdmin, licensing.PageAccess)),
|
2022-01-24 09:08:05 -06:00
|
|
|
"edition": hs.License.Edition(),
|
|
|
|
"enabledFeatures": hs.License.EnabledFeatures(),
|
2015-01-05 03:46:58 -06:00
|
|
|
},
|
2022-01-26 11:44:20 -06:00
|
|
|
"featureToggles": hs.Features.GetEnabled(c.Req.Context()),
|
2022-09-02 07:20:10 -05:00
|
|
|
"rendererAvailable": hs.RenderService.IsAvailable(c.Req.Context()),
|
2021-06-04 06:33:49 -05:00
|
|
|
"rendererVersion": hs.RenderService.Version(),
|
2022-08-10 14:47:03 -05:00
|
|
|
"secretsManagerPluginEnabled": secretsManagerPluginEnabled,
|
2021-05-27 05:45:06 -05:00
|
|
|
"http2Enabled": hs.Cfg.Protocol == setting.HTTP2Scheme,
|
|
|
|
"sentry": hs.Cfg.Sentry,
|
2022-06-28 02:25:30 -05:00
|
|
|
"grafanaJavascriptAgent": hs.Cfg.GrafanaJavascriptAgent,
|
2021-05-27 05:45:06 -05:00
|
|
|
"pluginCatalogURL": hs.Cfg.PluginCatalogURL,
|
2021-08-04 04:49:05 -05:00
|
|
|
"pluginAdminEnabled": hs.Cfg.PluginAdminEnabled,
|
2021-05-31 05:30:32 -05:00
|
|
|
"pluginAdminExternalManageEnabled": hs.Cfg.PluginAdminEnabled && hs.Cfg.PluginAdminExternalManageEnabled,
|
2021-11-15 08:51:16 -06:00
|
|
|
"pluginCatalogHiddenPlugins": hs.Cfg.PluginCatalogHiddenPlugins,
|
2021-05-27 05:45:06 -05:00
|
|
|
"expressionsEnabled": hs.Cfg.ExpressionsEnabled,
|
|
|
|
"awsAllowedAuthProviders": hs.Cfg.AWSAllowedAuthProviders,
|
|
|
|
"awsAssumeRoleEnabled": hs.Cfg.AWSAssumeRoleEnabled,
|
2021-05-12 09:23:37 -05:00
|
|
|
"azure": map[string]interface{}{
|
|
|
|
"cloud": hs.Cfg.Azure.Cloud,
|
|
|
|
"managedIdentityEnabled": hs.Cfg.Azure.ManagedIdentityEnabled,
|
|
|
|
},
|
2021-05-26 12:27:28 -05:00
|
|
|
"caching": map[string]bool{
|
|
|
|
"enabled": hs.Cfg.SectionWithEnvOverrides("caching").Key("enabled").MustBool(true),
|
|
|
|
},
|
2021-11-17 15:45:05 -06:00
|
|
|
"recordedQueries": map[string]bool{
|
2022-01-27 10:09:39 -06:00
|
|
|
"enabled": hs.Cfg.SectionWithEnvOverrides("recorded_queries").Key("enabled").MustBool(true),
|
2021-11-17 15:45:05 -06:00
|
|
|
},
|
2022-03-22 15:30:45 -05:00
|
|
|
"reporting": map[string]bool{
|
|
|
|
"enabled": hs.Cfg.SectionWithEnvOverrides("reporting").Key("enabled").MustBool(true),
|
|
|
|
},
|
2021-11-15 08:51:16 -06:00
|
|
|
"unifiedAlertingEnabled": hs.Cfg.UnifiedAlerting.Enabled,
|
2022-08-01 08:01:14 -05:00
|
|
|
"unifiedAlerting": map[string]interface{}{
|
|
|
|
"minInterval": hs.Cfg.UnifiedAlerting.MinInterval.String(),
|
|
|
|
},
|
2022-11-22 03:08:40 -06:00
|
|
|
"oauth": hs.getEnabledOAuthProviders(),
|
|
|
|
"samlEnabled": hs.samlEnabled(),
|
|
|
|
"samlName": hs.samlName(),
|
|
|
|
"tokenExpirationDayLimit": hs.Cfg.SATokenExpirationDayLimit,
|
2021-07-21 15:48:20 -05:00
|
|
|
}
|
|
|
|
|
2022-02-16 11:49:50 -06:00
|
|
|
if hs.ThumbService != nil {
|
|
|
|
jsonObj["dashboardPreviews"] = hs.ThumbService.GetDashboardPreviewsSetupSettings(c)
|
|
|
|
}
|
|
|
|
|
2021-07-21 15:48:20 -05:00
|
|
|
if hs.Cfg.GeomapDefaultBaseLayerConfig != nil {
|
|
|
|
jsonObj["geomapDefaultBaseLayerConfig"] = hs.Cfg.GeomapDefaultBaseLayerConfig
|
|
|
|
}
|
|
|
|
if !hs.Cfg.GeomapEnableCustomBaseLayers {
|
|
|
|
jsonObj["geomapDisableCustomBaseLayer"] = true
|
2014-12-29 06:36:08 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return jsonObj, nil
|
|
|
|
}
|
2015-02-18 07:06:44 -06:00
|
|
|
|
2022-03-18 14:49:13 -05:00
|
|
|
func (hs *HTTPServer) getFSDataSources(c *models.ReqContext, enabledPlugins EnabledPlugins) (map[string]plugins.DataSourceDTO, error) {
|
2022-06-27 11:23:15 -05:00
|
|
|
orgDataSources := make([]*datasources.DataSource, 0)
|
2022-08-11 06:28:55 -05:00
|
|
|
if c.OrgID != 0 {
|
|
|
|
query := datasources.GetDataSourcesQuery{OrgId: c.OrgID, DataSourceLimit: hs.Cfg.DataSourceLimit}
|
2022-08-10 08:04:51 -05:00
|
|
|
err := hs.DataSourcesService.GetDataSources(c.Req.Context(), &query)
|
2022-03-18 14:49:13 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-10-18 14:44:33 -05:00
|
|
|
if c.IsPublicDashboardView {
|
|
|
|
// If RBAC is enabled, it will filter out all datasources for a public user, so we need to skip it
|
|
|
|
orgDataSources = query.Result
|
|
|
|
} else {
|
|
|
|
filtered, err := hs.filterDatasourcesByQueryPermission(c.Req.Context(), c.SignedInUser, query.Result)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
orgDataSources = filtered
|
2022-03-18 14:49:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dataSources := make(map[string]plugins.DataSourceDTO)
|
|
|
|
|
|
|
|
for _, ds := range orgDataSources {
|
|
|
|
url := ds.Url
|
|
|
|
|
2022-06-27 11:23:15 -05:00
|
|
|
if ds.Access == datasources.DS_ACCESS_PROXY {
|
2022-03-18 14:49:13 -05:00
|
|
|
url = "/api/datasources/proxy/" + strconv.FormatInt(ds.Id, 10)
|
|
|
|
}
|
|
|
|
|
|
|
|
dsDTO := plugins.DataSourceDTO{
|
|
|
|
ID: ds.Id,
|
|
|
|
UID: ds.Uid,
|
|
|
|
Type: ds.Type,
|
|
|
|
Name: ds.Name,
|
|
|
|
URL: url,
|
|
|
|
IsDefault: ds.IsDefault,
|
|
|
|
Access: string(ds.Access),
|
2022-08-26 05:27:28 -05:00
|
|
|
ReadOnly: ds.ReadOnly,
|
2022-03-18 14:49:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
plugin, exists := enabledPlugins.Get(plugins.DataSource, ds.Type)
|
|
|
|
if !exists {
|
|
|
|
c.Logger.Error("Could not find plugin definition for data source", "datasource_type", ds.Type)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
dsDTO.Preload = plugin.Preload
|
|
|
|
dsDTO.Module = plugin.Module
|
|
|
|
dsDTO.PluginMeta = &plugins.PluginMetaDTO{
|
|
|
|
JSONData: plugin.JSONData,
|
|
|
|
Signature: plugin.Signature,
|
|
|
|
Module: plugin.Module,
|
|
|
|
BaseURL: plugin.BaseURL,
|
|
|
|
}
|
|
|
|
|
|
|
|
if ds.JsonData == nil {
|
|
|
|
dsDTO.JSONData = make(map[string]interface{})
|
|
|
|
} else {
|
|
|
|
dsDTO.JSONData = ds.JsonData.MustMap()
|
|
|
|
}
|
|
|
|
|
2022-06-27 11:23:15 -05:00
|
|
|
if ds.Access == datasources.DS_ACCESS_DIRECT {
|
2022-03-18 14:49:13 -05:00
|
|
|
if ds.BasicAuth {
|
2022-04-25 11:57:45 -05:00
|
|
|
password, err := hs.DataSourcesService.DecryptedBasicAuthPassword(c.Req.Context(), ds)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-03-18 14:49:13 -05:00
|
|
|
dsDTO.BasicAuth = util.GetBasicAuthHeader(
|
|
|
|
ds.BasicAuthUser,
|
2022-04-25 11:57:45 -05:00
|
|
|
password,
|
2022-03-18 14:49:13 -05:00
|
|
|
)
|
|
|
|
}
|
|
|
|
if ds.WithCredentials {
|
|
|
|
dsDTO.WithCredentials = ds.WithCredentials
|
|
|
|
}
|
|
|
|
|
2022-06-27 11:23:15 -05:00
|
|
|
if ds.Type == datasources.DS_INFLUXDB_08 {
|
2022-04-25 11:57:45 -05:00
|
|
|
password, err := hs.DataSourcesService.DecryptedPassword(c.Req.Context(), ds)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-03-18 14:49:13 -05:00
|
|
|
dsDTO.Username = ds.User
|
2022-04-25 11:57:45 -05:00
|
|
|
dsDTO.Password = password
|
2022-03-18 14:49:13 -05:00
|
|
|
dsDTO.URL = url + "/db/" + ds.Database
|
|
|
|
}
|
|
|
|
|
2022-06-27 11:23:15 -05:00
|
|
|
if ds.Type == datasources.DS_INFLUXDB {
|
2022-04-25 11:57:45 -05:00
|
|
|
password, err := hs.DataSourcesService.DecryptedPassword(c.Req.Context(), ds)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-03-18 14:49:13 -05:00
|
|
|
dsDTO.Username = ds.User
|
2022-04-25 11:57:45 -05:00
|
|
|
dsDTO.Password = password
|
2022-03-18 14:49:13 -05:00
|
|
|
dsDTO.URL = url
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-27 11:23:15 -05:00
|
|
|
if (ds.Type == datasources.DS_INFLUXDB) || (ds.Type == datasources.DS_ES) {
|
2022-03-18 14:49:13 -05:00
|
|
|
dsDTO.Database = ds.Database
|
|
|
|
}
|
|
|
|
|
2022-06-27 11:23:15 -05:00
|
|
|
if ds.Type == datasources.DS_PROMETHEUS {
|
2022-03-18 14:49:13 -05:00
|
|
|
// add unproxied server URL for link to Prometheus web UI
|
|
|
|
ds.JsonData.Set("directUrl", ds.Url)
|
|
|
|
}
|
|
|
|
|
|
|
|
dataSources[ds.Name] = dsDTO
|
|
|
|
}
|
|
|
|
|
|
|
|
// add data sources that are built in (meaning they are not added via data sources page, nor have any entry in
|
|
|
|
// the datasource table)
|
|
|
|
for _, ds := range hs.pluginStore.Plugins(c.Req.Context(), plugins.DataSource) {
|
|
|
|
if ds.BuiltIn {
|
|
|
|
dto := plugins.DataSourceDTO{
|
|
|
|
Type: string(ds.Type),
|
|
|
|
Name: ds.Name,
|
|
|
|
JSONData: make(map[string]interface{}),
|
|
|
|
PluginMeta: &plugins.PluginMetaDTO{
|
|
|
|
JSONData: ds.JSONData,
|
|
|
|
Signature: ds.Signature,
|
|
|
|
Module: ds.Module,
|
|
|
|
BaseURL: ds.BaseURL,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
if ds.Name == grafanads.DatasourceName {
|
|
|
|
dto.ID = grafanads.DatasourceID
|
|
|
|
dto.UID = grafanads.DatasourceUID
|
|
|
|
}
|
|
|
|
dataSources[ds.Name] = dto
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return dataSources, nil
|
|
|
|
}
|
|
|
|
|
2016-10-26 10:42:39 -05:00
|
|
|
func getPanelSort(id string) int {
|
|
|
|
sort := 100
|
|
|
|
switch id {
|
2021-01-10 10:41:20 -06:00
|
|
|
case "timeseries":
|
2021-05-05 06:19:14 -05:00
|
|
|
sort = 1
|
2021-05-03 09:49:09 -05:00
|
|
|
case "barchart":
|
2021-05-05 06:19:14 -05:00
|
|
|
sort = 2
|
2021-05-03 09:49:09 -05:00
|
|
|
case "stat":
|
2021-05-05 06:19:14 -05:00
|
|
|
sort = 3
|
2021-05-03 09:49:09 -05:00
|
|
|
case "gauge":
|
2021-05-05 06:19:14 -05:00
|
|
|
sort = 4
|
2021-05-03 09:49:09 -05:00
|
|
|
case "bargauge":
|
2021-05-05 06:19:14 -05:00
|
|
|
sort = 5
|
2021-05-03 09:49:09 -05:00
|
|
|
case "table":
|
2021-05-05 06:19:14 -05:00
|
|
|
sort = 6
|
2021-05-03 09:49:09 -05:00
|
|
|
case "singlestat":
|
2021-05-05 06:19:14 -05:00
|
|
|
sort = 7
|
2021-05-03 09:49:09 -05:00
|
|
|
case "piechart":
|
2021-05-05 06:19:14 -05:00
|
|
|
sort = 8
|
2021-05-17 15:00:04 -05:00
|
|
|
case "state-timeline":
|
2019-02-15 14:33:36 -06:00
|
|
|
sort = 9
|
2021-03-25 02:33:13 -05:00
|
|
|
case "heatmap":
|
2020-01-17 02:43:17 -06:00
|
|
|
sort = 10
|
2021-05-29 13:24:14 -05:00
|
|
|
case "status-history":
|
2021-01-10 10:41:20 -06:00
|
|
|
sort = 11
|
2021-05-20 10:36:20 -05:00
|
|
|
case "histogram":
|
2021-01-10 10:41:20 -06:00
|
|
|
sort = 12
|
2021-05-20 10:36:20 -05:00
|
|
|
case "graph":
|
2021-03-25 02:33:13 -05:00
|
|
|
sort = 13
|
2021-05-20 10:36:20 -05:00
|
|
|
case "text":
|
2021-05-03 09:49:09 -05:00
|
|
|
sort = 14
|
2021-05-20 10:36:20 -05:00
|
|
|
case "alertlist":
|
2021-05-05 06:19:14 -05:00
|
|
|
sort = 15
|
2021-05-20 10:36:20 -05:00
|
|
|
case "dashlist":
|
2021-05-17 15:00:04 -05:00
|
|
|
sort = 16
|
2021-05-20 10:36:20 -05:00
|
|
|
case "news":
|
|
|
|
sort = 17
|
2016-10-26 10:42:39 -05:00
|
|
|
}
|
|
|
|
return sort
|
|
|
|
}
|
|
|
|
|
2021-11-01 04:53:33 -05:00
|
|
|
// EnabledPlugins represents a mapping from plugin types (panel, data source, etc.) to plugin IDs to plugins
|
2021-11-17 05:04:22 -06:00
|
|
|
// For example ["panel"] -> ["piechart"] -> {pie chart plugin DTO}
|
|
|
|
type EnabledPlugins map[plugins.Type]map[string]plugins.PluginDTO
|
2021-11-01 04:53:33 -05:00
|
|
|
|
2021-11-17 05:04:22 -06:00
|
|
|
func (ep EnabledPlugins) Get(pluginType plugins.Type, pluginID string) (plugins.PluginDTO, bool) {
|
2021-11-01 04:53:33 -05:00
|
|
|
if _, exists := ep[pluginType][pluginID]; exists {
|
|
|
|
return ep[pluginType][pluginID], true
|
|
|
|
}
|
|
|
|
|
2021-11-17 05:04:22 -06:00
|
|
|
return plugins.PluginDTO{}, false
|
2021-11-01 04:53:33 -05:00
|
|
|
}
|
|
|
|
|
2021-11-02 07:42:55 -05:00
|
|
|
func (hs *HTTPServer) enabledPlugins(ctx context.Context, orgID int64) (EnabledPlugins, error) {
|
2021-11-01 04:53:33 -05:00
|
|
|
ep := make(EnabledPlugins)
|
|
|
|
|
2021-11-02 07:42:55 -05:00
|
|
|
pluginSettingMap, err := hs.pluginSettings(ctx, orgID)
|
2021-11-01 04:53:33 -05:00
|
|
|
if err != nil {
|
|
|
|
return ep, err
|
|
|
|
}
|
|
|
|
|
2021-11-17 05:04:22 -06:00
|
|
|
apps := make(map[string]plugins.PluginDTO)
|
|
|
|
for _, app := range hs.pluginStore.Plugins(ctx, plugins.App) {
|
2021-11-01 04:53:33 -05:00
|
|
|
if b, exists := pluginSettingMap[app.ID]; exists {
|
|
|
|
app.Pinned = b.Pinned
|
|
|
|
apps[app.ID] = app
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ep[plugins.App] = apps
|
|
|
|
|
2021-11-17 05:04:22 -06:00
|
|
|
dataSources := make(map[string]plugins.PluginDTO)
|
|
|
|
for _, ds := range hs.pluginStore.Plugins(ctx, plugins.DataSource) {
|
2021-11-01 04:53:33 -05:00
|
|
|
if _, exists := pluginSettingMap[ds.ID]; exists {
|
|
|
|
dataSources[ds.ID] = ds
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ep[plugins.DataSource] = dataSources
|
|
|
|
|
2021-11-17 05:04:22 -06:00
|
|
|
panels := make(map[string]plugins.PluginDTO)
|
|
|
|
for _, p := range hs.pluginStore.Plugins(ctx, plugins.Panel) {
|
2021-11-01 04:53:33 -05:00
|
|
|
if _, exists := pluginSettingMap[p.ID]; exists {
|
|
|
|
panels[p.ID] = p
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ep[plugins.Panel] = panels
|
|
|
|
|
|
|
|
return ep, nil
|
|
|
|
}
|
|
|
|
|
2022-09-21 05:20:11 -05:00
|
|
|
func (hs *HTTPServer) pluginSettings(ctx context.Context, orgID int64) (map[string]*pluginsettings.InfoDTO, error) {
|
|
|
|
pluginSettings := make(map[string]*pluginsettings.InfoDTO)
|
2021-11-01 04:53:33 -05:00
|
|
|
|
2021-11-05 09:07:53 -05:00
|
|
|
// fill settings from database
|
2022-03-18 14:49:13 -05:00
|
|
|
if pss, err := hs.PluginSettings.GetPluginSettings(ctx, &pluginsettings.GetArgs{OrgID: orgID}); err != nil {
|
2021-11-05 09:07:53 -05:00
|
|
|
return nil, err
|
|
|
|
} else {
|
|
|
|
for _, ps := range pss {
|
2022-03-18 14:49:13 -05:00
|
|
|
pluginSettings[ps.PluginID] = ps
|
2021-11-05 09:07:53 -05:00
|
|
|
}
|
2021-11-01 04:53:33 -05:00
|
|
|
}
|
|
|
|
|
2021-11-05 09:07:53 -05:00
|
|
|
// fill settings from app plugins
|
2021-11-17 05:04:22 -06:00
|
|
|
for _, plugin := range hs.pluginStore.Plugins(ctx, plugins.App) {
|
2021-11-05 09:07:53 -05:00
|
|
|
// ignore settings that already exist
|
|
|
|
if _, exists := pluginSettings[plugin.ID]; exists {
|
2021-11-01 04:53:33 -05:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2021-11-05 09:07:53 -05:00
|
|
|
// add new setting which is enabled depending on if AutoEnabled: true
|
2022-09-21 05:20:11 -05:00
|
|
|
pluginSetting := &pluginsettings.InfoDTO{
|
|
|
|
PluginID: plugin.ID,
|
|
|
|
OrgID: orgID,
|
|
|
|
Enabled: plugin.AutoEnabled,
|
|
|
|
Pinned: plugin.AutoEnabled,
|
|
|
|
PluginVersion: plugin.Info.Version,
|
2021-11-01 04:53:33 -05:00
|
|
|
}
|
|
|
|
|
2021-11-05 09:07:53 -05:00
|
|
|
pluginSettings[plugin.ID] = pluginSetting
|
|
|
|
}
|
|
|
|
|
|
|
|
// fill settings from all remaining plugins (including potential app child plugins)
|
2021-11-17 05:04:22 -06:00
|
|
|
for _, plugin := range hs.pluginStore.Plugins(ctx) {
|
2021-11-05 09:07:53 -05:00
|
|
|
// ignore settings that already exist
|
|
|
|
if _, exists := pluginSettings[plugin.ID]; exists {
|
|
|
|
continue
|
2021-11-01 04:53:33 -05:00
|
|
|
}
|
|
|
|
|
2021-11-05 09:07:53 -05:00
|
|
|
// add new setting which is enabled by default
|
2022-09-21 05:20:11 -05:00
|
|
|
pluginSetting := &pluginsettings.InfoDTO{
|
|
|
|
PluginID: plugin.ID,
|
|
|
|
OrgID: orgID,
|
|
|
|
Enabled: true,
|
|
|
|
Pinned: false,
|
|
|
|
PluginVersion: plugin.Info.Version,
|
2021-11-05 09:07:53 -05:00
|
|
|
}
|
2021-11-01 04:53:33 -05:00
|
|
|
|
2021-11-05 09:07:53 -05:00
|
|
|
// if plugin is included in an app, check app settings
|
|
|
|
if plugin.IncludedInAppID != "" {
|
|
|
|
// app child plugins are disabled unless app is enabled
|
|
|
|
pluginSetting.Enabled = false
|
|
|
|
if p, exists := pluginSettings[plugin.IncludedInAppID]; exists {
|
|
|
|
pluginSetting.Enabled = p.Enabled
|
2021-11-01 04:53:33 -05:00
|
|
|
}
|
|
|
|
}
|
2021-11-05 09:07:53 -05:00
|
|
|
pluginSettings[plugin.ID] = pluginSetting
|
2021-11-01 04:53:33 -05:00
|
|
|
}
|
|
|
|
|
2021-11-05 09:07:53 -05:00
|
|
|
return pluginSettings, nil
|
2021-11-01 04:53:33 -05:00
|
|
|
}
|
2022-11-15 03:50:37 -06:00
|
|
|
|
|
|
|
func (hs *HTTPServer) getEnabledOAuthProviders() map[string]interface{} {
|
|
|
|
providers := make(map[string]interface{})
|
|
|
|
for key, oauth := range hs.SocialService.GetOAuthInfoProviders() {
|
|
|
|
providers[key] = map[string]string{
|
|
|
|
"name": oauth.Name,
|
|
|
|
"icon": oauth.Icon,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return providers
|
|
|
|
}
|