mirror of
https://github.com/grafana/grafana.git
synced 2024-11-30 12:44:10 -06:00
30 lines
708 B
Go
30 lines
708 B
Go
package models
|
|
|
|
import (
|
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
|
)
|
|
|
|
func GetQueriesFromDashboard(dashboard *simplejson.Json) map[int64][]*simplejson.Json {
|
|
result := make(map[int64][]*simplejson.Json)
|
|
|
|
for _, panelObj := range dashboard.Get("panels").MustArray() {
|
|
panel := simplejson.NewFromAny(panelObj)
|
|
|
|
var panelQueries []*simplejson.Json
|
|
|
|
for _, queryObj := range panel.Get("targets").MustArray() {
|
|
query := simplejson.NewFromAny(queryObj)
|
|
|
|
if _, ok := query.CheckGet("datasource"); !ok {
|
|
query.Set("datasource", panel.Get("datasource"))
|
|
}
|
|
|
|
panelQueries = append(panelQueries, query)
|
|
}
|
|
|
|
result[panel.Get("id").MustInt64()] = panelQueries
|
|
}
|
|
|
|
return result
|
|
}
|