grafana/pkg/api/admin.go

44 lines
993 B
Go
Raw Normal View History

package api
import (
"strings"
2016-01-24 23:18:17 -06:00
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/middleware"
2016-01-24 23:18:17 -06:00
m "github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/setting"
)
func AdminGetSettings(c *middleware.Context) {
settings := make(map[string]interface{})
for _, section := range setting.Cfg.Sections() {
jsonSec := make(map[string]interface{})
settings[section.Name()] = jsonSec
for _, key := range section.Keys() {
keyName := key.Name()
value := key.Value()
if strings.Contains(keyName, "secret") || strings.Contains(keyName, "password") || (strings.Contains(keyName, "provider_config")) {
value = "************"
}
jsonSec[keyName] = value
}
}
c.JSON(200, settings)
}
2016-01-24 13:01:33 -06:00
func AdminGetStats(c *middleware.Context) {
2016-01-24 23:18:17 -06:00
statsQuery := m.GetAdminStatsQuery{}
2016-01-24 13:01:33 -06:00
2016-01-24 23:18:17 -06:00
if err := bus.Dispatch(&statsQuery); err != nil {
c.JsonApiErr(500, "Failed to get admin stats from database", err)
return
}
c.JSON(200, statsQuery.Result)
2016-01-24 13:01:33 -06:00
}