From 839df9025a377ac26e9155565d14c2f267fb532a Mon Sep 17 00:00:00 2001 From: zhaoxiangchun <1422928955@qq.com> Date: Thu, 4 Mar 2021 12:09:58 +0800 Subject: [PATCH] =?UTF-8?q?bugfix(monitor):=20=E5=AF=BC=E5=87=BA=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E4=B8=AD=E6=B7=BB=E5=8A=A0=E5=85=A8=E5=B1=80=E5=AD=97?= =?UTF-8?q?=E5=85=B8=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 域信息中添加全局字典的域配置 --- pkg/monitor/models/commonalert.go | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/pkg/monitor/models/commonalert.go b/pkg/monitor/models/commonalert.go index 47c7d917ba..ff49676a3f 100644 --- a/pkg/monitor/models/commonalert.go +++ b/pkg/monitor/models/commonalert.go @@ -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) (