| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538 |
- // Copyright 2019 Yunion
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- package models
- import (
- "context"
- "golang.org/x/text/language"
- comapi "yunion.io/x/onecloud/pkg/apis/compute"
- api "yunion.io/x/onecloud/pkg/apis/notify"
- schapi "yunion.io/x/onecloud/pkg/apis/scheduledtask"
- "yunion.io/x/onecloud/pkg/i18n"
- )
- type SEventDisplay struct {
- sEvenWebhookMsg
- ResourceTypeDisplay string
- ActionDisplay string
- AdvanceDays int
- }
- type sEvenWebhookMsg struct {
- ResourceType string `json:"resource_type"`
- Action string `json:"action"`
- ResourceDetails map[string]interface{} `json:"resource_details"`
- }
- func languageTag(lang string) language.Tag {
- var langStr string
- if lang == api.TEMPLATE_LANG_CN {
- langStr = "zh-CN"
- } else {
- langStr = "en"
- }
- t, _ := language.Parse(langStr)
- return t
- }
- var action2Topic = make(map[string]string, 0)
- func init() {
- action2Topic[string(api.ActionRebuildRoot)] = string(api.ActionUpdate)
- action2Topic[string(api.ActionResetPassword)] = string(api.ActionUpdate)
- action2Topic[string(api.ActionChangeIpaddr)] = string(api.ActionUpdate)
- }
- var specFieldTrans = map[string]i18n.Table{}
- func init() {
- var spI18nTable = i18n.Table{}
- spI18nTable.Set(comapi.TRIGGER_ALARM, i18n.NewTableEntry().EN("alarm").CN("告警"))
- spI18nTable.Set(comapi.TRIGGER_TIMING, i18n.NewTableEntry().EN("timing").CN("定时"))
- spI18nTable.Set(comapi.TRIGGER_CYCLE, i18n.NewTableEntry().EN("cycle").CN("周期"))
- spI18nTable.Set(comapi.ACTION_ADD, i18n.NewTableEntry().EN("add").CN("增加"))
- spI18nTable.Set(comapi.ACTION_REMOVE, i18n.NewTableEntry().EN("remove").CN("减少"))
- spI18nTable.Set(comapi.ACTION_SET, i18n.NewTableEntry().EN("set as").CN("设置为"))
- spI18nTable.Set(comapi.UNIT_ONE, i18n.NewTableEntry().EN("").CN("个"))
- spI18nTable.Set(comapi.UNIT_PERCENT, i18n.NewTableEntry().EN("%").CN("%"))
- var stI18nTable = i18n.Table{}
- stI18nTable.Set(schapi.ST_RESOURCE_SERVER, i18n.NewTableEntry().EN("virtual machine").CN("虚拟机"))
- stI18nTable.Set(schapi.ST_RESOURCE_CLOUDACCOUNT, i18n.NewTableEntry().EN("cloud account").CN("云账号"))
- stI18nTable.Set(schapi.ST_RESOURCE_OPERATION_RESTART, i18n.NewTableEntry().EN("restart").CN("重启"))
- stI18nTable.Set(schapi.ST_RESOURCE_OPERATION_STOP, i18n.NewTableEntry().EN("stop").CN("关机"))
- stI18nTable.Set(schapi.ST_RESOURCE_OPERATION_START, i18n.NewTableEntry().EN("start").CN("开机"))
- stI18nTable.Set(schapi.ST_RESOURCE_OPERATION_SYNC, i18n.NewTableEntry().EN("sync").CN("同步"))
- specFieldTrans[api.TOPIC_RESOURCE_SCALINGPOLICY] = spI18nTable
- specFieldTrans[api.TOPIC_RESOURCE_SCHEDULEDTASK] = stI18nTable
- }
- var (
- notifyclientI18nTable = i18n.Table{}
- )
- func setI18nTable(t i18n.Table, elems ...sI18nElme) {
- for i := range elems {
- t.Set(elems[i].k, i18n.NewTableEntry().EN(elems[i].en).CN(elems[i].cn))
- }
- }
- func getLangSuffix(ctx context.Context) string {
- return notifyclientI18nTable.Lookup(ctx, tempalteLang)
- }
- const (
- tempalteLang = "lang"
- )
- type sI18nElme struct {
- k string
- en string
- cn string
- }
- func init() {
- setI18nTable(notifyclientI18nTable,
- sI18nElme{
- tempalteLang,
- api.TEMPLATE_LANG_EN,
- api.TEMPLATE_LANG_CN,
- },
- sI18nElme{
- api.TOPIC_RESOURCE_HOST,
- "host",
- "宿主机",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_SERVER,
- "virtual machine",
- "虚拟机",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_SCALINGGROUP,
- "scaling group",
- "弹性伸缩组",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_SCALINGPOLICY,
- "scaling policy",
- "弹性伸缩策略",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_IMAGE,
- "image",
- "系统镜像",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_DISK,
- "disk",
- "硬盘",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_SNAPSHOT,
- "snapshot",
- "硬盘快照",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_INSTANCESNAPSHOT,
- "instance snapshot",
- "主机快照",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_NETWORK,
- "network",
- "IP子网",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_EIP,
- "EIP",
- "弹性公网IP",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_SECGROUP,
- "security group",
- "安全组",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_LOADBALANCER,
- "loadbalancer instance",
- "负载均衡实例",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_LOADBALANCERACL,
- "loadbalancer ACL",
- "负载均衡访问控制",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_LOADBALANCERCERTIFICATE,
- "loadbalancer certificate",
- "负载均衡证书",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_LOADBALANCERLISTENER,
- "loadbalancer listener",
- "负载均衡监听",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_LOADBALANCERBACKEDNGROUP,
- "loadbalancer backendgroup",
- "负载均衡服务器组",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_BUCKET,
- "object storage bucket",
- "对象存储桶",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_DBINSTANCE,
- "RDS instance",
- "RDS实例",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_ELASTICCACHE,
- "Redis instance",
- "Redis实例",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_SCHEDULEDTASK,
- "scheduled task",
- "定时任务",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_BAREMETAL,
- "baremetal",
- "裸金属",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_SNAPSHOTPOLICY,
- "snapshot policy",
- "快照策略",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_VPC,
- "VPC",
- "VPC",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_DNSZONE,
- "DNS zone",
- "DNS zone",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_DNSRECORDSET,
- "DNS record",
- "DNS 记录",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_NATGATEWAY,
- "nat gateway",
- "nat网关",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_WEBAPP,
- "webapp",
- "应用程序服务",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_CDNDOMAIN,
- "CDN domain",
- "CDN domain",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_FILESYSTEM,
- "file system",
- "文件系统",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_WAF,
- "WAF",
- "WAF",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_KAFKA,
- "Kafka",
- "Kafka",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_ELASTICSEARCH,
- "Elasticsearch",
- "Elasticsearch",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_MONGODB,
- "MongoDB",
- "MongoDB",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_DB_TABLE_RECORD,
- "database table record",
- "数据库记录",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_VM_INTEGRITY_CHECK,
- "vm server integrity check",
- "虚拟主机完整性校验",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_ACTION_LOG,
- "action log",
- "操作日志",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_PROJECT,
- "project",
- "项目",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_CLOUDPODS_COMPONENT,
- "cloudpods component",
- "cloudpods服务组件",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_USER,
- "user",
- "用户",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_CLOUDPHONE,
- "cloudphone",
- "云手机",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_ACCOUNT_STATUS,
- "account",
- "云账号",
- },
- sI18nElme{
- api.TOPIC_RESOURCE_SERVICE,
- "service",
- "服务",
- },
- sI18nElme{
- string(api.ActionCreate),
- "created",
- "创建",
- },
- sI18nElme{
- string(api.ActionUpdate),
- "update",
- "更新",
- },
- sI18nElme{
- string(api.ActionDelete),
- "deleted",
- "删除",
- },
- sI18nElme{
- string(api.ActionRebuildRoot),
- "rebuilded root",
- "重装系统",
- },
- sI18nElme{
- string(api.ActionResetPassword),
- "reseted password",
- "重置密码",
- },
- sI18nElme{
- string(api.ActionChangeConfig),
- "changed config",
- "更改配置",
- },
- sI18nElme{
- string(api.ActionResize),
- "resize",
- "扩容",
- },
- sI18nElme{
- string(api.ActionExpiredRelease),
- "expired and released",
- "到期释放",
- },
- sI18nElme{
- string(api.ActionExecute),
- "executed",
- "生效执行",
- },
- sI18nElme{
- string(api.ActionPendingDelete),
- "added to the recycle bin",
- "加入回收站",
- },
- sI18nElme{
- string(api.ActionSyncCreate),
- "sync_create",
- "同步新建",
- },
- sI18nElme{
- string(api.ActionSyncUpdate),
- "sync_update",
- "同步更新",
- },
- sI18nElme{
- string(api.ActionSyncDelete),
- "sync_delete",
- "同步删除",
- },
- sI18nElme{
- string(api.ActionMigrate),
- "migrate",
- "迁移",
- },
- sI18nElme{
- string(api.ActionOffline),
- "offline",
- "离线",
- },
- sI18nElme{
- string(api.ActionHostDown),
- "host_down",
- "宿主机宕机",
- },
- sI18nElme{
- string(api.ActionHostDownAutoMigrate),
- "host_down_auto_migrate",
- "宿主机宕机自动迁移",
- },
- sI18nElme{
- string(api.ActionSystemException),
- "exception",
- "异常",
- },
- sI18nElme{
- string(api.ResultFailed),
- "failed",
- "失败",
- },
- sI18nElme{
- string(api.ResultSucceed),
- "successfully",
- "成功",
- },
- sI18nElme{
- string(api.ActionAttach),
- "attach",
- "挂载",
- },
- sI18nElme{
- string(api.ActionDetach),
- "detach",
- "卸载",
- },
- sI18nElme{
- string(api.ActionCreateBackupServer),
- "add_backup_server",
- "添加主机备份",
- },
- sI18nElme{
- string(api.ActionStart),
- "start",
- "开机",
- },
- sI18nElme{
- string(api.ActionStop),
- "stop",
- "关机",
- },
- sI18nElme{
- string(api.ActionRestart),
- "restart",
- "重启",
- },
- sI18nElme{
- string(api.ActionReset),
- "reset",
- "重置",
- },
- sI18nElme{
- string(api.ActionChangeIpaddr),
- "change_ipaddr",
- "修改IP地址",
- },
- sI18nElme{
- string(api.ActionChecksumTest),
- "checksum_test",
- "一致性检查",
- },
- sI18nElme{
- string(api.ActionCleanData),
- "clean_data",
- "清理数据",
- },
- sI18nElme{
- string(api.ActionDelBackupServer),
- "delete_backup_server",
- "删除主机备份",
- },
- sI18nElme{
- string(api.ActionMysqlOutOfSync),
- "mysql_out_of_sync",
- "数据库不一致",
- },
- sI18nElme{
- string(api.ActionNetOutOfSync),
- "net_out_of_sync",
- "网络拓扑不一致",
- },
- sI18nElme{
- string(api.ActionServerPanicked),
- "server_panicked",
- "主机崩溃",
- },
- sI18nElme{
- string(api.ActionServiceAbnormal),
- "service_abnormal",
- "服务异常",
- },
- sI18nElme{
- string(api.ActionPasswordExpireSoon),
- "password_expire_soon",
- "密码即将过期",
- },
- sI18nElme{
- string(api.ActionSystemPanic),
- "panic",
- "系统崩溃",
- },
- sI18nElme{
- string(api.ActionExceedCount),
- "exceed_count",
- "超过数量",
- },
- sI18nElme{
- string(api.ActionIsolatedDeviceCreate),
- "isolated_device_create",
- "新增透传设备",
- },
- sI18nElme{
- string(api.ActionIsolatedDeviceUpdate),
- "isolated_device_update",
- "修改透传设备",
- },
- sI18nElme{
- string(api.ActionIsolatedDeviceDelete),
- "isolated_device_delete",
- "删除透传设备",
- },
- sI18nElme{
- string(api.ActionStatusChanged),
- "status_changed",
- "状态变更",
- },
- )
- }
|