Merge pull request #10311 from zhaoxiangchun/automated-cherry-pick-of-#10310-upstream-release-3.7

Automated cherry pick of #10310: bugfix(monitor): 导出信息中添加全局字典配置
This commit is contained in:
Zexi Li
2021-03-04 16:54:29 +08:00
committed by GitHub
+26 -2
View File
@@ -26,6 +26,7 @@ import (
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/auth"
"yunion.io/x/onecloud/pkg/mcclient/modules"
"yunion.io/x/onecloud/pkg/mcclient/modules/yunionconf"
merrors "yunion.io/x/onecloud/pkg/monitor/errors"
"yunion.io/x/onecloud/pkg/monitor/validators"
"yunion.io/x/onecloud/pkg/util/logclient"
@@ -365,15 +366,38 @@ func (manager *SCommonAlertManager) GetExportExtraKeys(ctx context.Context, keys
tenant.GetProjectDomain())))
}
} else {
tenant, err := db.TenantCacheManager.FetchTenantById(ctx, rowMap["domain_id"])
tenant, err := db.TenantCacheManager.FetchDomainById(ctx, rowMap["domain_id"])
if err == nil {
res.Set("tenant", jsonutils.NewString(tenant.GetProjectDomain()))
dictionaryVal := GetGlobalSettingsDictionary(ctx, "domain")
res.Set("tenant", jsonutils.NewString(fmt.Sprintf("%s%s", tenant.GetProjectDomain(), dictionaryVal)))
}
}
}
return res
}
func GetGlobalSettingsDictionary(ctx context.Context, param string) (val string) {
s := auth.GetAdminSession(ctx, "", "")
globalSettings, err := yunionconf.Parameters.GetGlobalSettings(s, jsonutils.NewDict())
if err != nil {
log.Errorf("GetGlobalSettings err:%v", err)
return
}
dictionary, err := globalSettings.Get("value", "dictionary")
if err != nil {
log.Errorf("can not get dictionary:%s", globalSettings.String())
return
}
lang := i18n.Lang(ctx)
switch lang {
case language.English:
val, _ = dictionary.GetString("en", param)
default:
val, _ = dictionary.GetString("zh", param)
}
return
}
func (man *SCommonAlertManager) CustomizeFilterList(
ctx context.Context, q *sqlchemy.SQuery,
userCred mcclient.TokenCredential, query jsonutils.JSONObject) (