event_template.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package models
  15. import (
  16. "context"
  17. "golang.org/x/text/language"
  18. comapi "yunion.io/x/onecloud/pkg/apis/compute"
  19. api "yunion.io/x/onecloud/pkg/apis/notify"
  20. schapi "yunion.io/x/onecloud/pkg/apis/scheduledtask"
  21. "yunion.io/x/onecloud/pkg/i18n"
  22. )
  23. type SEventDisplay struct {
  24. sEvenWebhookMsg
  25. ResourceTypeDisplay string
  26. ActionDisplay string
  27. AdvanceDays int
  28. }
  29. type sEvenWebhookMsg struct {
  30. ResourceType string `json:"resource_type"`
  31. Action string `json:"action"`
  32. ResourceDetails map[string]interface{} `json:"resource_details"`
  33. }
  34. func languageTag(lang string) language.Tag {
  35. var langStr string
  36. if lang == api.TEMPLATE_LANG_CN {
  37. langStr = "zh-CN"
  38. } else {
  39. langStr = "en"
  40. }
  41. t, _ := language.Parse(langStr)
  42. return t
  43. }
  44. var action2Topic = make(map[string]string, 0)
  45. func init() {
  46. action2Topic[string(api.ActionRebuildRoot)] = string(api.ActionUpdate)
  47. action2Topic[string(api.ActionResetPassword)] = string(api.ActionUpdate)
  48. action2Topic[string(api.ActionChangeIpaddr)] = string(api.ActionUpdate)
  49. }
  50. var specFieldTrans = map[string]i18n.Table{}
  51. func init() {
  52. var spI18nTable = i18n.Table{}
  53. spI18nTable.Set(comapi.TRIGGER_ALARM, i18n.NewTableEntry().EN("alarm").CN("告警"))
  54. spI18nTable.Set(comapi.TRIGGER_TIMING, i18n.NewTableEntry().EN("timing").CN("定时"))
  55. spI18nTable.Set(comapi.TRIGGER_CYCLE, i18n.NewTableEntry().EN("cycle").CN("周期"))
  56. spI18nTable.Set(comapi.ACTION_ADD, i18n.NewTableEntry().EN("add").CN("增加"))
  57. spI18nTable.Set(comapi.ACTION_REMOVE, i18n.NewTableEntry().EN("remove").CN("减少"))
  58. spI18nTable.Set(comapi.ACTION_SET, i18n.NewTableEntry().EN("set as").CN("设置为"))
  59. spI18nTable.Set(comapi.UNIT_ONE, i18n.NewTableEntry().EN("").CN("个"))
  60. spI18nTable.Set(comapi.UNIT_PERCENT, i18n.NewTableEntry().EN("%").CN("%"))
  61. var stI18nTable = i18n.Table{}
  62. stI18nTable.Set(schapi.ST_RESOURCE_SERVER, i18n.NewTableEntry().EN("virtual machine").CN("虚拟机"))
  63. stI18nTable.Set(schapi.ST_RESOURCE_CLOUDACCOUNT, i18n.NewTableEntry().EN("cloud account").CN("云账号"))
  64. stI18nTable.Set(schapi.ST_RESOURCE_OPERATION_RESTART, i18n.NewTableEntry().EN("restart").CN("重启"))
  65. stI18nTable.Set(schapi.ST_RESOURCE_OPERATION_STOP, i18n.NewTableEntry().EN("stop").CN("关机"))
  66. stI18nTable.Set(schapi.ST_RESOURCE_OPERATION_START, i18n.NewTableEntry().EN("start").CN("开机"))
  67. stI18nTable.Set(schapi.ST_RESOURCE_OPERATION_SYNC, i18n.NewTableEntry().EN("sync").CN("同步"))
  68. specFieldTrans[api.TOPIC_RESOURCE_SCALINGPOLICY] = spI18nTable
  69. specFieldTrans[api.TOPIC_RESOURCE_SCHEDULEDTASK] = stI18nTable
  70. }
  71. var (
  72. notifyclientI18nTable = i18n.Table{}
  73. )
  74. func setI18nTable(t i18n.Table, elems ...sI18nElme) {
  75. for i := range elems {
  76. t.Set(elems[i].k, i18n.NewTableEntry().EN(elems[i].en).CN(elems[i].cn))
  77. }
  78. }
  79. func getLangSuffix(ctx context.Context) string {
  80. return notifyclientI18nTable.Lookup(ctx, tempalteLang)
  81. }
  82. const (
  83. tempalteLang = "lang"
  84. )
  85. type sI18nElme struct {
  86. k string
  87. en string
  88. cn string
  89. }
  90. func init() {
  91. setI18nTable(notifyclientI18nTable,
  92. sI18nElme{
  93. tempalteLang,
  94. api.TEMPLATE_LANG_EN,
  95. api.TEMPLATE_LANG_CN,
  96. },
  97. sI18nElme{
  98. api.TOPIC_RESOURCE_HOST,
  99. "host",
  100. "宿主机",
  101. },
  102. sI18nElme{
  103. api.TOPIC_RESOURCE_SERVER,
  104. "virtual machine",
  105. "虚拟机",
  106. },
  107. sI18nElme{
  108. api.TOPIC_RESOURCE_SCALINGGROUP,
  109. "scaling group",
  110. "弹性伸缩组",
  111. },
  112. sI18nElme{
  113. api.TOPIC_RESOURCE_SCALINGPOLICY,
  114. "scaling policy",
  115. "弹性伸缩策略",
  116. },
  117. sI18nElme{
  118. api.TOPIC_RESOURCE_IMAGE,
  119. "image",
  120. "系统镜像",
  121. },
  122. sI18nElme{
  123. api.TOPIC_RESOURCE_DISK,
  124. "disk",
  125. "硬盘",
  126. },
  127. sI18nElme{
  128. api.TOPIC_RESOURCE_SNAPSHOT,
  129. "snapshot",
  130. "硬盘快照",
  131. },
  132. sI18nElme{
  133. api.TOPIC_RESOURCE_INSTANCESNAPSHOT,
  134. "instance snapshot",
  135. "主机快照",
  136. },
  137. sI18nElme{
  138. api.TOPIC_RESOURCE_NETWORK,
  139. "network",
  140. "IP子网",
  141. },
  142. sI18nElme{
  143. api.TOPIC_RESOURCE_EIP,
  144. "EIP",
  145. "弹性公网IP",
  146. },
  147. sI18nElme{
  148. api.TOPIC_RESOURCE_SECGROUP,
  149. "security group",
  150. "安全组",
  151. },
  152. sI18nElme{
  153. api.TOPIC_RESOURCE_LOADBALANCER,
  154. "loadbalancer instance",
  155. "负载均衡实例",
  156. },
  157. sI18nElme{
  158. api.TOPIC_RESOURCE_LOADBALANCERACL,
  159. "loadbalancer ACL",
  160. "负载均衡访问控制",
  161. },
  162. sI18nElme{
  163. api.TOPIC_RESOURCE_LOADBALANCERCERTIFICATE,
  164. "loadbalancer certificate",
  165. "负载均衡证书",
  166. },
  167. sI18nElme{
  168. api.TOPIC_RESOURCE_LOADBALANCERLISTENER,
  169. "loadbalancer listener",
  170. "负载均衡监听",
  171. },
  172. sI18nElme{
  173. api.TOPIC_RESOURCE_LOADBALANCERBACKEDNGROUP,
  174. "loadbalancer backendgroup",
  175. "负载均衡服务器组",
  176. },
  177. sI18nElme{
  178. api.TOPIC_RESOURCE_BUCKET,
  179. "object storage bucket",
  180. "对象存储桶",
  181. },
  182. sI18nElme{
  183. api.TOPIC_RESOURCE_DBINSTANCE,
  184. "RDS instance",
  185. "RDS实例",
  186. },
  187. sI18nElme{
  188. api.TOPIC_RESOURCE_ELASTICCACHE,
  189. "Redis instance",
  190. "Redis实例",
  191. },
  192. sI18nElme{
  193. api.TOPIC_RESOURCE_SCHEDULEDTASK,
  194. "scheduled task",
  195. "定时任务",
  196. },
  197. sI18nElme{
  198. api.TOPIC_RESOURCE_BAREMETAL,
  199. "baremetal",
  200. "裸金属",
  201. },
  202. sI18nElme{
  203. api.TOPIC_RESOURCE_SNAPSHOTPOLICY,
  204. "snapshot policy",
  205. "快照策略",
  206. },
  207. sI18nElme{
  208. api.TOPIC_RESOURCE_VPC,
  209. "VPC",
  210. "VPC",
  211. },
  212. sI18nElme{
  213. api.TOPIC_RESOURCE_DNSZONE,
  214. "DNS zone",
  215. "DNS zone",
  216. },
  217. sI18nElme{
  218. api.TOPIC_RESOURCE_DNSRECORDSET,
  219. "DNS record",
  220. "DNS 记录",
  221. },
  222. sI18nElme{
  223. api.TOPIC_RESOURCE_NATGATEWAY,
  224. "nat gateway",
  225. "nat网关",
  226. },
  227. sI18nElme{
  228. api.TOPIC_RESOURCE_WEBAPP,
  229. "webapp",
  230. "应用程序服务",
  231. },
  232. sI18nElme{
  233. api.TOPIC_RESOURCE_CDNDOMAIN,
  234. "CDN domain",
  235. "CDN domain",
  236. },
  237. sI18nElme{
  238. api.TOPIC_RESOURCE_FILESYSTEM,
  239. "file system",
  240. "文件系统",
  241. },
  242. sI18nElme{
  243. api.TOPIC_RESOURCE_WAF,
  244. "WAF",
  245. "WAF",
  246. },
  247. sI18nElme{
  248. api.TOPIC_RESOURCE_KAFKA,
  249. "Kafka",
  250. "Kafka",
  251. },
  252. sI18nElme{
  253. api.TOPIC_RESOURCE_ELASTICSEARCH,
  254. "Elasticsearch",
  255. "Elasticsearch",
  256. },
  257. sI18nElme{
  258. api.TOPIC_RESOURCE_MONGODB,
  259. "MongoDB",
  260. "MongoDB",
  261. },
  262. sI18nElme{
  263. api.TOPIC_RESOURCE_DB_TABLE_RECORD,
  264. "database table record",
  265. "数据库记录",
  266. },
  267. sI18nElme{
  268. api.TOPIC_RESOURCE_VM_INTEGRITY_CHECK,
  269. "vm server integrity check",
  270. "虚拟主机完整性校验",
  271. },
  272. sI18nElme{
  273. api.TOPIC_RESOURCE_ACTION_LOG,
  274. "action log",
  275. "操作日志",
  276. },
  277. sI18nElme{
  278. api.TOPIC_RESOURCE_PROJECT,
  279. "project",
  280. "项目",
  281. },
  282. sI18nElme{
  283. api.TOPIC_RESOURCE_CLOUDPODS_COMPONENT,
  284. "cloudpods component",
  285. "cloudpods服务组件",
  286. },
  287. sI18nElme{
  288. api.TOPIC_RESOURCE_USER,
  289. "user",
  290. "用户",
  291. },
  292. sI18nElme{
  293. api.TOPIC_RESOURCE_CLOUDPHONE,
  294. "cloudphone",
  295. "云手机",
  296. },
  297. sI18nElme{
  298. api.TOPIC_RESOURCE_ACCOUNT_STATUS,
  299. "account",
  300. "云账号",
  301. },
  302. sI18nElme{
  303. api.TOPIC_RESOURCE_SERVICE,
  304. "service",
  305. "服务",
  306. },
  307. sI18nElme{
  308. string(api.ActionCreate),
  309. "created",
  310. "创建",
  311. },
  312. sI18nElme{
  313. string(api.ActionUpdate),
  314. "update",
  315. "更新",
  316. },
  317. sI18nElme{
  318. string(api.ActionDelete),
  319. "deleted",
  320. "删除",
  321. },
  322. sI18nElme{
  323. string(api.ActionRebuildRoot),
  324. "rebuilded root",
  325. "重装系统",
  326. },
  327. sI18nElme{
  328. string(api.ActionResetPassword),
  329. "reseted password",
  330. "重置密码",
  331. },
  332. sI18nElme{
  333. string(api.ActionChangeConfig),
  334. "changed config",
  335. "更改配置",
  336. },
  337. sI18nElme{
  338. string(api.ActionResize),
  339. "resize",
  340. "扩容",
  341. },
  342. sI18nElme{
  343. string(api.ActionExpiredRelease),
  344. "expired and released",
  345. "到期释放",
  346. },
  347. sI18nElme{
  348. string(api.ActionExecute),
  349. "executed",
  350. "生效执行",
  351. },
  352. sI18nElme{
  353. string(api.ActionPendingDelete),
  354. "added to the recycle bin",
  355. "加入回收站",
  356. },
  357. sI18nElme{
  358. string(api.ActionSyncCreate),
  359. "sync_create",
  360. "同步新建",
  361. },
  362. sI18nElme{
  363. string(api.ActionSyncUpdate),
  364. "sync_update",
  365. "同步更新",
  366. },
  367. sI18nElme{
  368. string(api.ActionSyncDelete),
  369. "sync_delete",
  370. "同步删除",
  371. },
  372. sI18nElme{
  373. string(api.ActionMigrate),
  374. "migrate",
  375. "迁移",
  376. },
  377. sI18nElme{
  378. string(api.ActionOffline),
  379. "offline",
  380. "离线",
  381. },
  382. sI18nElme{
  383. string(api.ActionHostDown),
  384. "host_down",
  385. "宿主机宕机",
  386. },
  387. sI18nElme{
  388. string(api.ActionHostDownAutoMigrate),
  389. "host_down_auto_migrate",
  390. "宿主机宕机自动迁移",
  391. },
  392. sI18nElme{
  393. string(api.ActionSystemException),
  394. "exception",
  395. "异常",
  396. },
  397. sI18nElme{
  398. string(api.ResultFailed),
  399. "failed",
  400. "失败",
  401. },
  402. sI18nElme{
  403. string(api.ResultSucceed),
  404. "successfully",
  405. "成功",
  406. },
  407. sI18nElme{
  408. string(api.ActionAttach),
  409. "attach",
  410. "挂载",
  411. },
  412. sI18nElme{
  413. string(api.ActionDetach),
  414. "detach",
  415. "卸载",
  416. },
  417. sI18nElme{
  418. string(api.ActionCreateBackupServer),
  419. "add_backup_server",
  420. "添加主机备份",
  421. },
  422. sI18nElme{
  423. string(api.ActionStart),
  424. "start",
  425. "开机",
  426. },
  427. sI18nElme{
  428. string(api.ActionStop),
  429. "stop",
  430. "关机",
  431. },
  432. sI18nElme{
  433. string(api.ActionRestart),
  434. "restart",
  435. "重启",
  436. },
  437. sI18nElme{
  438. string(api.ActionReset),
  439. "reset",
  440. "重置",
  441. },
  442. sI18nElme{
  443. string(api.ActionChangeIpaddr),
  444. "change_ipaddr",
  445. "修改IP地址",
  446. },
  447. sI18nElme{
  448. string(api.ActionChecksumTest),
  449. "checksum_test",
  450. "一致性检查",
  451. },
  452. sI18nElme{
  453. string(api.ActionCleanData),
  454. "clean_data",
  455. "清理数据",
  456. },
  457. sI18nElme{
  458. string(api.ActionDelBackupServer),
  459. "delete_backup_server",
  460. "删除主机备份",
  461. },
  462. sI18nElme{
  463. string(api.ActionMysqlOutOfSync),
  464. "mysql_out_of_sync",
  465. "数据库不一致",
  466. },
  467. sI18nElme{
  468. string(api.ActionNetOutOfSync),
  469. "net_out_of_sync",
  470. "网络拓扑不一致",
  471. },
  472. sI18nElme{
  473. string(api.ActionServerPanicked),
  474. "server_panicked",
  475. "主机崩溃",
  476. },
  477. sI18nElme{
  478. string(api.ActionServiceAbnormal),
  479. "service_abnormal",
  480. "服务异常",
  481. },
  482. sI18nElme{
  483. string(api.ActionPasswordExpireSoon),
  484. "password_expire_soon",
  485. "密码即将过期",
  486. },
  487. sI18nElme{
  488. string(api.ActionSystemPanic),
  489. "panic",
  490. "系统崩溃",
  491. },
  492. sI18nElme{
  493. string(api.ActionExceedCount),
  494. "exceed_count",
  495. "超过数量",
  496. },
  497. sI18nElme{
  498. string(api.ActionIsolatedDeviceCreate),
  499. "isolated_device_create",
  500. "新增透传设备",
  501. },
  502. sI18nElme{
  503. string(api.ActionIsolatedDeviceUpdate),
  504. "isolated_device_update",
  505. "修改透传设备",
  506. },
  507. sI18nElme{
  508. string(api.ActionIsolatedDeviceDelete),
  509. "isolated_device_delete",
  510. "删除透传设备",
  511. },
  512. sI18nElme{
  513. string(api.ActionStatusChanged),
  514. "status_changed",
  515. "状态变更",
  516. },
  517. )
  518. }