From 59a2a01b95eb9a95d5d16d393e3bf6bb16cf089c Mon Sep 17 00:00:00 2001 From: Jian Qiu Date: Mon, 13 Mar 2023 09:59:31 +0800 Subject: [PATCH] fix: add vm integrity check notify (#16205) Co-authored-by: Qiu Jian --- .../local-templates/content@cn/CHECKSUM_TEST_FAILED.tmpl | 3 +++ pkg/apis/notify/const.go | 1 + pkg/cloudcommon/notifyclient/notify.go | 6 ++++++ pkg/notify/models/event_template.go | 5 +++++ pkg/notify/models/topic.go | 2 ++ 5 files changed, 17 insertions(+) diff --git a/build/notify/root/opt/yunion/share/local-templates/content@cn/CHECKSUM_TEST_FAILED.tmpl b/build/notify/root/opt/yunion/share/local-templates/content@cn/CHECKSUM_TEST_FAILED.tmpl index 8960c10731..36faed4577 100644 --- a/build/notify/root/opt/yunion/share/local-templates/content@cn/CHECKSUM_TEST_FAILED.tmpl +++ b/build/notify/root/opt/yunion/share/local-templates/content@cn/CHECKSUM_TEST_FAILED.tmpl @@ -11,3 +11,6 @@ {{- if eq .resource_type "image" }} 镜像{{ $d.name }}完整性校验失败 {{- end -}} +{{- if eq .resource_type "vm_integrity" }} +主机{{ $d.name }}完整性校验失败 +{{- end -}} diff --git a/pkg/apis/notify/const.go b/pkg/apis/notify/const.go index f92ba5828f..fac3795ed1 100644 --- a/pkg/apis/notify/const.go +++ b/pkg/apis/notify/const.go @@ -136,6 +136,7 @@ const ( TOPIC_RESOURCE_WORKER = "worker" TOPIC_RESOURCE_NET = "net" TOPIC_RESOURCE_SERVICE = "service" + TOPIC_RESOURCE_VM_INTEGRITY_CHECK = "vm_integrity" SUBSCRIBER_TYPE_ROLE = "role" SUBSCRIBER_TYPE_ROBOT = "robot" diff --git a/pkg/cloudcommon/notifyclient/notify.go b/pkg/cloudcommon/notifyclient/notify.go index 57cb21b461..d5c791f04f 100644 --- a/pkg/cloudcommon/notifyclient/notify.go +++ b/pkg/cloudcommon/notifyclient/notify.go @@ -433,3 +433,9 @@ func FetchNotifyAdminRecipients(ctx context.Context, region string, users []stri } } } + +func NotifyVmIntegrity(ctx context.Context, name string) { + data := jsonutils.NewDict() + data.Add(jsonutils.NewString(name), "name") + SystemExceptionNotifyWithResult(ctx, api.ActionChecksumTest, api.TOPIC_RESOURCE_DB_TABLE_RECORD, api.ResultFailed, data) +} diff --git a/pkg/notify/models/event_template.go b/pkg/notify/models/event_template.go index 785d4a77dd..26ab6ea4d1 100644 --- a/pkg/notify/models/event_template.go +++ b/pkg/notify/models/event_template.go @@ -509,6 +509,11 @@ func init() { "database table record", "数据库记录", }, + sI18nElme{ + api.TOPIC_RESOURCE_VM_INTEGRITY_CHECK, + "vm server integrity check", + "虚拟主机完整性校验", + }, sI18nElme{ api.TOPIC_RESOURCE_ACTION_LOG, "action log", diff --git a/pkg/notify/models/topic.go b/pkg/notify/models/topic.go index d6c2da7357..e23fe1da71 100644 --- a/pkg/notify/models/topic.go +++ b/pkg/notify/models/topic.go @@ -332,6 +332,7 @@ func (sm *STopicManager) InitializeData() error { case DefaultChecksumTestFailed: t.addResources( notify.TOPIC_RESOURCE_DB_TABLE_RECORD, + notify.TOPIC_RESOURCE_VM_INTEGRITY_CHECK, notify.TOPIC_RESOURCE_CLOUDPODS_COMPONENT, notify.TOPIC_RESOURCE_SNAPSHOT, notify.TOPIC_RESOURCE_IMAGE, @@ -682,6 +683,7 @@ func init() { notify.TOPIC_RESOURCE_ACCOUNT_STATUS: 38, notify.TOPIC_RESOURCE_NET: 39, notify.TOPIC_RESOURCE_SERVICE: 40, + notify.TOPIC_RESOURCE_VM_INTEGRITY_CHECK: 41, }, ) converter.registerAction(