mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(monitor): set alertdashboard scope
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"time"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
@@ -109,6 +110,36 @@ func (dash *SAlertDashBoard) CustomizeCreate(
|
||||
return dash.SScopedResourceBase.CustomizeCreate(ctx, userCred, ownerId, query, data)
|
||||
}
|
||||
|
||||
func (dash *SAlertDashBoard) PostCreate(ctx context.Context,
|
||||
userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider,
|
||||
query jsonutils.JSONObject, data jsonutils.JSONObject) {
|
||||
_, err := dash.PerformSetScope(ctx, userCred, query, data)
|
||||
if err != nil {
|
||||
log.Errorln(errors.Wrap(err, "dash PerformSetScope"))
|
||||
}
|
||||
}
|
||||
|
||||
func (dash *SAlertDashBoard) PerformSetScope(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
domainId := jsonutils.GetAnyString(data, []string{"domain_id", "domain", "project_domain_id", "project_domain"})
|
||||
projectId := jsonutils.GetAnyString(data, []string{"project_id", "project"})
|
||||
if len(domainId) == 0 && len(projectId) == 0 {
|
||||
scope, _ := data.GetString("scope")
|
||||
if len(scope) != 0 {
|
||||
switch rbacutils.TRbacScope(scope) {
|
||||
case rbacutils.ScopeSystem:
|
||||
|
||||
case rbacutils.ScopeDomain:
|
||||
domainId = userCred.GetProjectDomainId()
|
||||
data.(*jsonutils.JSONDict).Set("domain_id", jsonutils.NewString(domainId))
|
||||
case rbacutils.ScopeProject:
|
||||
projectId = userCred.GetProjectId()
|
||||
data.(*jsonutils.JSONDict).Set("project_id", jsonutils.NewString(projectId))
|
||||
}
|
||||
}
|
||||
}
|
||||
return db.PerformSetScope(ctx, dash, userCred, data)
|
||||
}
|
||||
|
||||
func (man *SAlertDashBoardManager) ListItemFilter(
|
||||
ctx context.Context, q *sqlchemy.SQuery,
|
||||
userCred mcclient.TokenCredential,
|
||||
|
||||
@@ -213,8 +213,8 @@ func (man *SAlertPanelManager) FetchCustomizeColumns(
|
||||
return rows
|
||||
}
|
||||
|
||||
func (dash *SAlertPanel) GetMoreDetails(out monitor.PanelDetails) (monitor.PanelDetails, error) {
|
||||
setting, err := dash.GetSettings()
|
||||
func (panel *SAlertPanel) GetMoreDetails(out monitor.PanelDetails) (monitor.PanelDetails, error) {
|
||||
setting, err := panel.GetSettings()
|
||||
if err != nil {
|
||||
return out, err
|
||||
}
|
||||
@@ -224,17 +224,19 @@ func (dash *SAlertPanel) GetMoreDetails(out monitor.PanelDetails) (monitor.Panel
|
||||
|
||||
out.CommonAlertMetricDetails = make([]*monitor.CommonAlertMetricDetails, len(setting.Conditions))
|
||||
for i, cond := range setting.Conditions {
|
||||
metricDetails := dash.GetCommonAlertMetricDetailsFromAlertCondition(i, cond)
|
||||
metricDetails := panel.GetCommonAlertMetricDetailsFromAlertCondition(i, &cond)
|
||||
out.CommonAlertMetricDetails[i] = metricDetails
|
||||
setting.Conditions[i] = cond
|
||||
}
|
||||
panel.Settings = jsonutils.Marshal(setting)
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (dash *SAlertPanel) GetCommonAlertMetricDetailsFromAlertCondition(index int,
|
||||
cond monitor.AlertCondition) *monitor.
|
||||
cond *monitor.AlertCondition) *monitor.
|
||||
CommonAlertMetricDetails {
|
||||
metricDetails := new(monitor.CommonAlertMetricDetails)
|
||||
getCommonAlertMetricDetailsFromCondition(&cond, metricDetails)
|
||||
getCommonAlertMetricDetailsFromCondition(cond, metricDetails)
|
||||
return metricDetails
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user