auth api
This commit is contained in:
parent
c773e7b9e8
commit
310497242b
|
@ -31,7 +31,7 @@ func (alert *AlertAPI) Init() {
|
||||||
|
|
||||||
api.HandleAPIMethod(api.GET, "/alerting/channel/:channel_id", alert.RequirePermission(alert.getChannel, enum.PermissionAlertChannelRead))
|
api.HandleAPIMethod(api.GET, "/alerting/channel/:channel_id", alert.RequirePermission(alert.getChannel, enum.PermissionAlertChannelRead))
|
||||||
api.HandleAPIMethod(api.POST, "/alerting/channel", alert.RequirePermission(alert.createChannel, enum.PermissionAlertChannelWrite))
|
api.HandleAPIMethod(api.POST, "/alerting/channel", alert.RequirePermission(alert.createChannel, enum.PermissionAlertChannelWrite))
|
||||||
api.HandleAPIMethod(api.DELETE, "/alerting/channel/:channel_id", alert.RequirePermission(alert.deleteChannel, enum.PermissionAlertChannelWrite))
|
api.HandleAPIMethod(api.DELETE, "/alerting/channel", alert.RequirePermission(alert.deleteChannel, enum.PermissionAlertChannelWrite))
|
||||||
api.HandleAPIMethod(api.PUT, "/alerting/channel/:channel_id", alert.RequirePermission(alert.updateChannel, enum.PermissionAlertChannelWrite))
|
api.HandleAPIMethod(api.PUT, "/alerting/channel/:channel_id", alert.RequirePermission(alert.updateChannel, enum.PermissionAlertChannelWrite))
|
||||||
api.HandleAPIMethod(api.GET, "/alerting/channel/_search", alert.RequirePermission(alert.searchChannel, enum.PermissionAlertChannelRead))
|
api.HandleAPIMethod(api.GET, "/alerting/channel/_search", alert.RequirePermission(alert.searchChannel, enum.PermissionAlertChannelRead))
|
||||||
|
|
||||||
|
|
|
@ -107,21 +107,32 @@ func (h *AlertAPI) updateChannel(w http.ResponseWriter, req *http.Request, ps ht
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *AlertAPI) deleteChannel(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
func (h *AlertAPI) deleteChannel(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
id := ps.MustGetParameter("channel_id")
|
reqBody := struct {
|
||||||
|
ChannelIDs []string `json:"ids"`
|
||||||
obj := alerting.Channel{}
|
}{}
|
||||||
obj.ID = id
|
err := h.DecodeJSON(req, &reqBody)
|
||||||
|
if err != nil {
|
||||||
exists, err := orm.Get(&obj)
|
h.WriteError(w, err.Error(), http.StatusInternalServerError)
|
||||||
if !exists || err != nil {
|
log.Error(err)
|
||||||
h.WriteJSON(w, util.MapStr{
|
|
||||||
"_id": id,
|
|
||||||
"result": "not_found",
|
|
||||||
}, http.StatusNotFound)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if len(reqBody.ChannelIDs) == 0 {
|
||||||
|
if err != nil {
|
||||||
|
h.WriteError(w, "channel ids required", http.StatusInternalServerError)
|
||||||
|
log.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
err = orm.Delete(&obj)
|
queryDsl := util.MapStr{
|
||||||
|
"query": util.MapStr{
|
||||||
|
"terms": util.MapStr{
|
||||||
|
"id": reqBody.ChannelIDs,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
err = orm.DeleteBy(alerting.Channel{}, util.MustToJSONBytes(queryDsl))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.WriteError(w, err.Error(), http.StatusInternalServerError)
|
h.WriteError(w, err.Error(), http.StatusInternalServerError)
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
|
@ -129,7 +140,7 @@ func (h *AlertAPI) deleteChannel(w http.ResponseWriter, req *http.Request, ps ht
|
||||||
}
|
}
|
||||||
|
|
||||||
h.WriteJSON(w, util.MapStr{
|
h.WriteJSON(w, util.MapStr{
|
||||||
"_id": obj.ID,
|
"ids": reqBody.ChannelIDs ,
|
||||||
"result": "deleted",
|
"result": "deleted",
|
||||||
}, 200)
|
}, 200)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
package index_management
|
package index_management
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
log "github.com/cihub/seelog"
|
||||||
httprouter "infini.sh/framework/core/api/router"
|
httprouter "infini.sh/framework/core/api/router"
|
||||||
"infini.sh/framework/core/elastic"
|
"infini.sh/framework/core/elastic"
|
||||||
"infini.sh/framework/core/util"
|
"infini.sh/framework/core/util"
|
||||||
"net/http"
|
"net/http"
|
||||||
log "github.com/cihub/seelog"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (handler APIHandler) HandleGetMappingsAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
func (handler APIHandler) HandleGetMappingsAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
|
@ -39,7 +40,17 @@ func (handler APIHandler) HandleGetMappingsAction(w http.ResponseWriter, req *ht
|
||||||
func (handler APIHandler) HandleGetIndicesAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
func (handler APIHandler) HandleGetIndicesAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
targetClusterID := ps.ByName("id")
|
targetClusterID := ps.ByName("id")
|
||||||
client := elastic.GetClient(targetClusterID)
|
client := elastic.GetClient(targetClusterID)
|
||||||
catIndices, err := client.GetIndices("")
|
//filter indices
|
||||||
|
allowedIndices, hasAllPrivilege := handler.GetAllowedIndices(req, targetClusterID)
|
||||||
|
if !hasAllPrivilege && len(allowedIndices) == 0 {
|
||||||
|
handler.WriteJSON(w, []interface{}{} , http.StatusOK)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
strIndices := ""
|
||||||
|
if !hasAllPrivilege {
|
||||||
|
strIndices = strings.Join(allowedIndices, ",")
|
||||||
|
}
|
||||||
|
catIndices, err := client.GetIndices(strIndices)
|
||||||
resBody := util.MapStr{}
|
resBody := util.MapStr{}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
|
|
|
@ -35,7 +35,7 @@ func Init(cfg *config.AppConfig) {
|
||||||
api.HandleAPIMethod(api.GET, path.Join(pathPrefix, "rebuild/_search"), handler.HandleGetRebuildListAction)
|
api.HandleAPIMethod(api.GET, path.Join(pathPrefix, "rebuild/_search"), handler.HandleGetRebuildListAction)
|
||||||
api.HandleAPIMethod(api.DELETE, path.Join(pathPrefix, "rebuild/:id"), handler.HandleDeleteRebuildAction)
|
api.HandleAPIMethod(api.DELETE, path.Join(pathPrefix, "rebuild/:id"), handler.HandleDeleteRebuildAction)
|
||||||
|
|
||||||
api.HandleAPIMethod(api.GET, path.Join(esPrefix, "_cat/indices"), handler.HandleGetIndicesAction)
|
api.HandleAPIMethod(api.GET, path.Join(esPrefix, "_cat/indices"), handler.RequireLogin(handler.HandleGetIndicesAction))
|
||||||
api.HandleAPIMethod(api.GET, path.Join(esPrefix, "index/:index/_mappings"), handler.HandleGetMappingsAction)
|
api.HandleAPIMethod(api.GET, path.Join(esPrefix, "index/:index/_mappings"), handler.HandleGetMappingsAction)
|
||||||
api.HandleAPIMethod(api.GET, path.Join(esPrefix, "index/:index/_settings"), handler.HandleGetSettingsAction)
|
api.HandleAPIMethod(api.GET, path.Join(esPrefix, "index/:index/_settings"), handler.HandleGetSettingsAction)
|
||||||
api.HandleAPIMethod(api.PUT, path.Join(esPrefix, "index/:index/_settings"),handler.HandleUpdateSettingsAction)
|
api.HandleAPIMethod(api.PUT, path.Join(esPrefix, "index/:index/_settings"),handler.HandleUpdateSettingsAction)
|
||||||
|
|
|
@ -45,6 +45,7 @@ func (engine *Engine) GenerateQuery(rule *alerting.Rule, filterParam *alerting.F
|
||||||
return nil, fmt.Errorf("metric items should not be empty")
|
return nil, fmt.Errorf("metric items should not be empty")
|
||||||
}
|
}
|
||||||
basicAggs := util.MapStr{}
|
basicAggs := util.MapStr{}
|
||||||
|
//todo bucket sort (es 6.1) bucket script (es 2.0)
|
||||||
for _, metricItem := range rule.Metrics.Items {
|
for _, metricItem := range rule.Metrics.Items {
|
||||||
metricAggs := engine.generateAgg(&metricItem)
|
metricAggs := engine.generateAgg(&metricItem)
|
||||||
if err = util.MergeFields(basicAggs, metricAggs, true); err != nil {
|
if err = util.MergeFields(basicAggs, metricAggs, true); err != nil {
|
||||||
|
|
Loading…
Reference in New Issue