add get widget api
This commit is contained in:
parent
47733e63c8
commit
b349c66b14
1
main.go
1
main.go
|
@ -133,6 +133,7 @@ func main() {
|
||||||
orm.RegisterSchemaWithIndexName(alerting.Channel{}, "channel")
|
orm.RegisterSchemaWithIndexName(alerting.Channel{}, "channel")
|
||||||
orm.RegisterSchemaWithIndexName(insight.Visualization{}, "visualization")
|
orm.RegisterSchemaWithIndexName(insight.Visualization{}, "visualization")
|
||||||
orm.RegisterSchemaWithIndexName(insight.Dashboard{}, "dashboard")
|
orm.RegisterSchemaWithIndexName(insight.Dashboard{}, "dashboard")
|
||||||
|
orm.RegisterSchemaWithIndexName(insight.Widget{}, "widget")
|
||||||
orm.RegisterSchemaWithIndexName(task1.Task{}, "task")
|
orm.RegisterSchemaWithIndexName(task1.Task{}, "task")
|
||||||
orm.RegisterSchemaWithIndexName(model.Layout{}, "layout")
|
orm.RegisterSchemaWithIndexName(model.Layout{}, "layout")
|
||||||
orm.RegisterSchemaWithIndexName(model.Notification{}, "notification")
|
orm.RegisterSchemaWithIndexName(model.Notification{}, "notification")
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
/* Copyright © INFINI Ltd. All rights reserved.
|
||||||
|
* Web: https://infinilabs.com
|
||||||
|
* Email: hello#infini.ltd */
|
||||||
|
|
||||||
|
package insight
|
||||||
|
|
||||||
|
import "infini.sh/framework/core/orm"
|
||||||
|
|
||||||
|
type Widget struct {
|
||||||
|
orm.ORMObjectBase
|
||||||
|
Formatter string `json:"formatter" elastic_mapping:"formatter: { type: keyword }"`
|
||||||
|
Series [] WidgetSeriesItem `json:"series" elastic_mapping:"series: { type: object,enabled:false }"`
|
||||||
|
Title string `json:"title" elastic_mapping:"title: { type: text }"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type WidgetSeriesItem struct {
|
||||||
|
Metric WidgetMetric `json:"metric"`
|
||||||
|
Queries WidgetQuery `json:"queries"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type WidgetQuery struct {
|
||||||
|
ClusterId string `json:"cluster_id"`
|
||||||
|
Indices []string `json:"indices"`
|
||||||
|
Query string `json:"query"`
|
||||||
|
TimeField string `json:"time_field"`
|
||||||
|
}
|
||||||
|
type WidgetMetric struct {
|
||||||
|
BucketSize string `json:"bucket_size"`
|
||||||
|
FormatType string `json:"format_type"`
|
||||||
|
Formula string `json:"formula"`
|
||||||
|
Groups []struct {
|
||||||
|
Field string `json:"field"`
|
||||||
|
Limit int `json:"limit"`
|
||||||
|
} `json:"groups"`
|
||||||
|
Items []struct {
|
||||||
|
Field string `json:"field"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Statistic string `json:"statistic"`
|
||||||
|
} `json:"items"`
|
||||||
|
}
|
|
@ -28,4 +28,5 @@ func InitAPI() {
|
||||||
api.HandleAPIMethod(api.DELETE, "/insight/dashboard/:dashboard_id", insight.deleteDashboard)
|
api.HandleAPIMethod(api.DELETE, "/insight/dashboard/:dashboard_id", insight.deleteDashboard)
|
||||||
api.HandleAPIMethod(api.GET, "/insight/dashboard/_search", insight.searchDashboard)
|
api.HandleAPIMethod(api.GET, "/insight/dashboard/_search", insight.searchDashboard)
|
||||||
api.HandleAPIMethod(api.POST, "/elasticsearch/:id/map_label/_render", insight.renderMapLabelTemplate)
|
api.HandleAPIMethod(api.POST, "/elasticsearch/:id/map_label/_render", insight.renderMapLabelTemplate)
|
||||||
|
api.HandleAPIMethod(api.GET, "/insight/widget/:widget_id", insight.getWidget)
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
/* Copyright © INFINI Ltd. All rights reserved.
|
||||||
|
* Web: https://infinilabs.com
|
||||||
|
* Email: hello#infini.ltd */
|
||||||
|
|
||||||
|
package insight
|
||||||
|
|
||||||
|
import (
|
||||||
|
"infini.sh/console/model/insight"
|
||||||
|
httprouter "infini.sh/framework/core/api/router"
|
||||||
|
"infini.sh/framework/core/orm"
|
||||||
|
"infini.sh/framework/core/util"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (h *InsightAPI) getWidget(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
|
id := ps.MustGetParameter("widget_id")
|
||||||
|
|
||||||
|
obj := insight.Widget{}
|
||||||
|
obj.ID = id
|
||||||
|
|
||||||
|
exists, err := orm.Get(&obj)
|
||||||
|
if !exists || err != nil {
|
||||||
|
h.WriteJSON(w, util.MapStr{
|
||||||
|
"_id": id,
|
||||||
|
"found": false,
|
||||||
|
}, http.StatusNotFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
h.WriteJSON(w, util.MapStr{
|
||||||
|
"found": true,
|
||||||
|
"_id": id,
|
||||||
|
"_source": obj,
|
||||||
|
}, 200)
|
||||||
|
}
|
Loading…
Reference in New Issue