From ceebbf6b6398037183e0e172c62e1b3e2e3f08c9 Mon Sep 17 00:00:00 2001 From: zqr10159 Date: Mon, 15 May 2023 00:28:42 +0800 Subject: [PATCH] [feature]Support config email server on web-ui --- .../impl/EmailAlertNotifyHandlerImpl.java | 15 +- .../manager/config/MailConfigProperties.java | 3 +- .../controller/MailConfigController.java | 55 ------- .../NoticeSenderConfigController.java | 56 +++++++ .../{MailConfig.java => NoticeSender.java} | 15 +- .../manager/service/GeneralConfigService.java | 7 + .../AbstractGeneralConfigServiceImpl.java | 21 ++- .../impl/MailGeneralConfigServiceImpl.java | 12 +- manager/src/main/resources/application.yml | 17 +-- web-app/src/app/pojo/NoticeSender.ts | 15 ++ .../alert-notice/alert-notice.component.html | 143 +++++++++++++++++- .../alert-notice/alert-notice.component.ts | 142 ++++++++++++++++- .../service/notice-receiver.service.spec.ts | 6 +- .../src/app/service/notice-sender.service.ts | 33 ++++ web-app/src/assets/i18n/en-US.json | 14 ++ web-app/src/assets/i18n/zh-CN.json | 14 ++ web-app/src/assets/i18n/zh-TW.json | 14 ++ 17 files changed, 488 insertions(+), 94 deletions(-) delete mode 100644 manager/src/main/java/org/dromara/hertzbeat/manager/controller/MailConfigController.java create mode 100644 manager/src/main/java/org/dromara/hertzbeat/manager/controller/NoticeSenderConfigController.java rename manager/src/main/java/org/dromara/hertzbeat/manager/pojo/dto/{MailConfig.java => NoticeSender.java} (73%) create mode 100644 web-app/src/app/pojo/NoticeSender.ts create mode 100644 web-app/src/app/service/notice-sender.service.ts diff --git a/manager/src/main/java/org/dromara/hertzbeat/manager/component/alerter/impl/EmailAlertNotifyHandlerImpl.java b/manager/src/main/java/org/dromara/hertzbeat/manager/component/alerter/impl/EmailAlertNotifyHandlerImpl.java index 80ab78d0fc5..639a3a08e5c 100644 --- a/manager/src/main/java/org/dromara/hertzbeat/manager/component/alerter/impl/EmailAlertNotifyHandlerImpl.java +++ b/manager/src/main/java/org/dromara/hertzbeat/manager/component/alerter/impl/EmailAlertNotifyHandlerImpl.java @@ -27,10 +27,9 @@ import org.dromara.hertzbeat.manager.component.alerter.AlertNotifyHandler; import org.dromara.hertzbeat.manager.config.MailConfigProperties; import org.dromara.hertzbeat.manager.dao.GeneralConfigDao; -import org.dromara.hertzbeat.manager.pojo.dto.MailConfig; +import org.dromara.hertzbeat.manager.pojo.dto.NoticeSender; import org.dromara.hertzbeat.manager.service.MailService; import org.dromara.hertzbeat.manager.support.exception.AlertNoticeException; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.mail.javamail.JavaMailSender; import org.springframework.mail.javamail.JavaMailSenderImpl; @@ -80,12 +79,12 @@ public void send(NoticeReceiver receiver, Alert alert) throws AlertNoticeExcepti //若启用数据库配置 if (enabled == true) { String content = generalConfigFoundByType.getContent(); - MailConfig mailConfigByfind = objectMapper.readValue(content, MailConfig.class); - sender.setHost(mailConfigByfind.getHost()); - sender.setPort(mailConfigByfind.getPort()); - sender.setUsername(mailConfigByfind.getUsername()); - sender.setPassword(mailConfigByfind.getPassword()); - emailFromUser = mailConfigByfind.getUsername(); + NoticeSender noticeSenderByfind = objectMapper.readValue(content, NoticeSender.class); + sender.setHost(noticeSenderByfind.getEmailHost()); + sender.setPort(noticeSenderByfind.getEmailPort()); + sender.setUsername(noticeSenderByfind.getEmailUsername()); + sender.setPassword(noticeSenderByfind.getEmailPassword()); + emailFromUser = noticeSenderByfind.getEmailUsername(); } //若启用yml配置 else { diff --git a/manager/src/main/java/org/dromara/hertzbeat/manager/config/MailConfigProperties.java b/manager/src/main/java/org/dromara/hertzbeat/manager/config/MailConfigProperties.java index 2efa272bb50..074bc68157b 100644 --- a/manager/src/main/java/org/dromara/hertzbeat/manager/config/MailConfigProperties.java +++ b/manager/src/main/java/org/dromara/hertzbeat/manager/config/MailConfigProperties.java @@ -27,7 +27,6 @@ public class MailConfigProperties { private String username; private String password; private Integer port; - private String defaultEncoding; @Bean public JavaMailSender javaMailSender() { @@ -42,7 +41,7 @@ public JavaMailSender javaMailSender() { props.put("spring.mail.smtp.socketFactory.port", port); props.put("spring.mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); props.put("spring.mail.debug", "false"); - props.put("spring.mail.default-encoding", defaultEncoding); + props.put("spring.mail.default-encoding", "UTF-8"); return mailSender; } diff --git a/manager/src/main/java/org/dromara/hertzbeat/manager/controller/MailConfigController.java b/manager/src/main/java/org/dromara/hertzbeat/manager/controller/MailConfigController.java deleted file mode 100644 index f45795d4ad7..00000000000 --- a/manager/src/main/java/org/dromara/hertzbeat/manager/controller/MailConfigController.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.dromara.hertzbeat.manager.controller; - -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -import lombok.extern.slf4j.Slf4j; -import org.dromara.hertzbeat.common.entity.dto.Message; -import org.dromara.hertzbeat.manager.pojo.dto.MailConfig; -import org.dromara.hertzbeat.manager.service.impl.MailGeneralConfigServiceImpl; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - - -import javax.validation.Valid; - -import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; - -/** - * Alert sender Configuration API - * 告警发送端配置API - * - * @author zqr10159 - * - */ -@RestController -@RequestMapping(value = "/api/config", produces = {APPLICATION_JSON_VALUE}) -@Tag(name = "Alert sender Configuration API | 告警发送端配置API") -@Slf4j -public class MailConfigController { - @Autowired - private MailGeneralConfigServiceImpl mailConfigService; - - @PostMapping(path = "/mail/save") - @Operation(summary = "Save the mail server config", description = "保存邮件服务器配置") - public ResponseEntity> saveOrUpdateMailConfig( - @RequestBody @Valid MailConfig mailConfig - ) { - mailConfigService.saveConfig(mailConfig, mailConfig.isEnabled()); - return ResponseEntity.ok(new Message<>("邮件服务器配置保存成功|The mail server configuration is saved successfully")); - } - - @GetMapping(path = "/mail/get") - @Operation(summary = "Get the mail server config", description = "获取邮件服务器配置") - public ResponseEntity> getMailConfig(){ - MailConfig mailConfig = mailConfigService.getConfig(); - return ResponseEntity.ok(new Message<>(mailConfig)); - } - - @DeleteMapping(path = "/mail/delete") - @Operation(summary = "Delete the mail server config", description = "删除邮件服务器配置") - public ResponseEntity> deleteMailConfig(){ - mailConfigService.deleteConfig(); - return ResponseEntity.ok(new Message<>("邮件服务器配置删除成功|The mail server configuration is deleted")); - } -} \ No newline at end of file diff --git a/manager/src/main/java/org/dromara/hertzbeat/manager/controller/NoticeSenderConfigController.java b/manager/src/main/java/org/dromara/hertzbeat/manager/controller/NoticeSenderConfigController.java new file mode 100644 index 00000000000..d038ba62a26 --- /dev/null +++ b/manager/src/main/java/org/dromara/hertzbeat/manager/controller/NoticeSenderConfigController.java @@ -0,0 +1,56 @@ +package org.dromara.hertzbeat.manager.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; +import org.dromara.hertzbeat.common.entity.dto.Message; +import org.dromara.hertzbeat.manager.pojo.dto.NoticeSender; +import org.dromara.hertzbeat.manager.service.impl.MailGeneralConfigServiceImpl; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + + +import javax.validation.Valid; + +import java.util.List; + +import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; + +/** + * Alert sender Configuration API + * 告警发送端配置API + * + * @author zqr10159 + * + */ +@RestController +@RequestMapping(value = "/api/config", produces = {APPLICATION_JSON_VALUE}) +@Tag(name = "Alert sender Configuration API | 告警发送端配置API") +@Slf4j +public class NoticeSenderConfigController { + @Autowired + private MailGeneralConfigServiceImpl mailConfigService; + + @PostMapping(path = "/sender") + @Operation(summary = "Save the sender config", description = "保存发送端配置") + public ResponseEntity> saveOrUpdateConfig( + @RequestBody @Valid NoticeSender noticeSender) { + mailConfigService.saveConfig(noticeSender, noticeSender.isEmailEnable()); + return ResponseEntity.ok(new Message<>("发送端配置保存成功|The sender configuration is saved successfully")); + } + + @GetMapping(path = "/senders") + @Operation(summary = "Get the sender config", description = "获取发送端配置") + public ResponseEntity>> getConfig(){ + List senders = mailConfigService.getConfigs(); + return ResponseEntity.ok(new Message<>(senders)); + } + + @DeleteMapping(path = "/sender/{id}") + @Operation(summary = "Delete the sender config", description = "删除发送端配置") + public ResponseEntity> deleteConfig(){ + mailConfigService.deleteConfig(); + return ResponseEntity.ok(new Message<>("发送端配置删除成功|The sender configuration is deleted")); + } +} \ No newline at end of file diff --git a/manager/src/main/java/org/dromara/hertzbeat/manager/pojo/dto/MailConfig.java b/manager/src/main/java/org/dromara/hertzbeat/manager/pojo/dto/NoticeSender.java similarity index 73% rename from manager/src/main/java/org/dromara/hertzbeat/manager/pojo/dto/MailConfig.java rename to manager/src/main/java/org/dromara/hertzbeat/manager/pojo/dto/NoticeSender.java index b093a122c99..f3dee2bc1d0 100644 --- a/manager/src/main/java/org/dromara/hertzbeat/manager/pojo/dto/MailConfig.java +++ b/manager/src/main/java/org/dromara/hertzbeat/manager/pojo/dto/NoticeSender.java @@ -8,26 +8,29 @@ /** * @description: 邮件账号配置dto + * * @author zqr * @date 2023/5/7 19:56 * @version 1.0 */ @Data -public class MailConfig { +public class NoticeSender { + @NotNull(message = "类型不能为空|Type cannot be empty") + private Integer type; @NotBlank(message = "邮件主机不能为空|Mail host cannot be empty") - private String host; + private String emailHost; @NotBlank(message = "用户名不能为空|Username cannot be empty") @Email - private String username; + private String emailUsername; @NotBlank(message = "密码不能为空|Password cannot be empty") - private String password; + private String emailPassword; @NotNull(message = "邮件端口不能为空|Mail port cannot be null") @Max(message = "邮件端口不得大于65535|Mail port must be less than or equal to 65535", value = 65535) @Min(message = "邮件端口不得小于1|Mail port must be greater than or equal to 1", value = 1) - private Integer port; + private Integer emailPort; - private boolean enabled; + private boolean emailEnable; } diff --git a/manager/src/main/java/org/dromara/hertzbeat/manager/service/GeneralConfigService.java b/manager/src/main/java/org/dromara/hertzbeat/manager/service/GeneralConfigService.java index d7ca22cc7d6..3d8d6069f5e 100644 --- a/manager/src/main/java/org/dromara/hertzbeat/manager/service/GeneralConfigService.java +++ b/manager/src/main/java/org/dromara/hertzbeat/manager/service/GeneralConfigService.java @@ -1,5 +1,7 @@ package org.dromara.hertzbeat.manager.service; +import java.util.List; + /** * ConfigService接口,提供配置的增删查改操作 * ConfigService interface provides CRUD operations for configurations. @@ -24,4 +26,9 @@ public interface GeneralConfigService { * Get a configuration. */ T getConfig(); + /* + * 获取所有配置 + * Get all configurations. + */ + List getConfigs(); } \ No newline at end of file diff --git a/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/AbstractGeneralConfigServiceImpl.java b/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/AbstractGeneralConfigServiceImpl.java index 9afc8f06f25..eda3f323fae 100644 --- a/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/AbstractGeneralConfigServiceImpl.java +++ b/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/AbstractGeneralConfigServiceImpl.java @@ -9,6 +9,9 @@ import org.dromara.hertzbeat.manager.service.GeneralConfigService; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; +import java.util.List; + @Slf4j abstract class AbstractGeneralConfigServiceImpl implements GeneralConfigService { protected final GeneralConfigDao generalConfigDao; @@ -62,9 +65,25 @@ public T getConfig() { try { return objectMapper.readValue(generalConfig.getContent(), getTypeReference()); } catch (JsonProcessingException e) { - throw new RuntimeException("获取设备失败|Get configuration failed"); + throw new RuntimeException("获取配置失败|Get configuration failed"); + } + } + + @Override + public List getConfigs() { + List configs = generalConfigDao.findAll(); + List result = new ArrayList<>(); + for (GeneralConfig config : configs) { + try { + T t = objectMapper.readValue(config.getContent(), getTypeReference()); + result.add(t); + } catch (JsonProcessingException e) { + throw new RuntimeException("获取配置失败|Get configuration failed"); + } } + return result; } + protected abstract TypeReference getTypeReference(); } diff --git a/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/MailGeneralConfigServiceImpl.java b/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/MailGeneralConfigServiceImpl.java index 770d18fff83..bad13c2eb52 100644 --- a/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/MailGeneralConfigServiceImpl.java +++ b/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/MailGeneralConfigServiceImpl.java @@ -3,29 +3,29 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import org.dromara.hertzbeat.manager.dao.GeneralConfigDao; -import org.dromara.hertzbeat.manager.pojo.dto.MailConfig; +import org.dromara.hertzbeat.manager.pojo.dto.NoticeSender; import org.springframework.stereotype.Service; import java.lang.reflect.Type; @Service -public class MailGeneralConfigServiceImpl extends AbstractGeneralConfigServiceImpl { +public class MailGeneralConfigServiceImpl extends AbstractGeneralConfigServiceImpl { public MailGeneralConfigServiceImpl(GeneralConfigDao generalConfigDao, ObjectMapper objectMapper) { super(generalConfigDao, objectMapper, (byte) 2); } @Override - public void saveConfig(MailConfig config, boolean enabled) { - super.saveConfig(config, config.isEnabled()); + public void saveConfig(NoticeSender config, boolean enabled) { + super.saveConfig(config, config.isEmailEnable()); } @Override - protected TypeReference getTypeReference() { + protected TypeReference getTypeReference() { return new TypeReference<>() { @Override public Type getType() { - return MailConfig.class; + return NoticeSender.class; } }; } diff --git a/manager/src/main/resources/application.yml b/manager/src/main/resources/application.yml index 3c2de16854d..1f5540c054c 100644 --- a/manager/src/main/resources/application.yml +++ b/manager/src/main/resources/application.yml @@ -87,19 +87,14 @@ spring: # Attention: this is mail server address. # 请注意此为邮件服务器地址:qq邮箱为 smtp.qq.com qq企业邮箱为 smtp.exmail.qq.com host: smtp.qq.com - username: example@tancloud.cn + username: tancloud@qq.com # Attention: this is not email account password, this requires an email authorization code # 请注意此非邮箱账户密码 此需填写邮箱授权码 - password: example - port: 465 - default-encoding: UTF-8 - properties: - mail: - smtp: - socketFactoryClass: javax.net.ssl.SSLSocketFactory - ssl: - enable: true - debug: false + password: yourpassword + #Attention: Tencent mail smtps 465,smtp 587 + #请注意腾讯邮箱465为smtps,587为smtp + port: 587 + warehouse: store: diff --git a/web-app/src/app/pojo/NoticeSender.ts b/web-app/src/app/pojo/NoticeSender.ts new file mode 100644 index 00000000000..bdf662d0817 --- /dev/null +++ b/web-app/src/app/pojo/NoticeSender.ts @@ -0,0 +1,15 @@ +export class NoticeSender { + id!: number; + name!: string; + // 通知信息方式: 1-短信 2-邮箱 + type: number = 2; + emailHost!: string; + emailPort!: number; + emailUsername!: string; + emailPassword!: string; + emailEnable!: boolean; + creator!: string; + modifier!: string; + gmtCreate!: number; + gmtUpdate!: number; +} diff --git a/web-app/src/app/routes/alert/alert-notice/alert-notice.component.html b/web-app/src/app/routes/alert/alert-notice/alert-notice.component.html index 4ac2e51a519..82f50a68cd0 100644 --- a/web-app/src/app/routes/alert/alert-notice/alert-notice.component.html +++ b/web-app/src/app/routes/alert/alert-notice/alert-notice.component.html @@ -17,9 +17,76 @@ + + +
+ + + +
+ + + + {{ 'alert.notice.sender.type' | i18n }} + {{ 'alert.notice.sender.config' | i18n }} + {{ 'alert.notice.sender.enable' | i18n }} + {{ 'common.edit' | i18n }} + + + + + + + + {{ 'alert.notice.sender.mail' | i18n }} + + + + 邮箱服务器地址:{{ data.emailHost }}
邮箱账号:{{ data.emailUsername }}
+ + + {{ data.emailEnable ? '已启用' : '未启用' }} + + + + + + + +
+
+ + + +
+
+ + {{ 'alert.notice.sender.type' | i18n }} + + + + + + + + {{ 'alert.notice.sender.mail.host' | i18n }} + + + + + + {{ + 'alert.notice.sender.mail.port' | i18n + }} + + + + + + {{ + 'alert.notice.sender.mail.username' | i18n + }} + + + + + + {{ + 'alert.notice.sender.mail.password' | i18n + }} + + + + + + {{ 'alert.notice.rule.enable' | i18n }} + + + + +
+
+
diff --git a/web-app/src/app/routes/alert/alert-notice/alert-notice.component.ts b/web-app/src/app/routes/alert/alert-notice/alert-notice.component.ts index 9dd035857be..91d4e90b703 100644 --- a/web-app/src/app/routes/alert/alert-notice/alert-notice.component.ts +++ b/web-app/src/app/routes/alert/alert-notice/alert-notice.component.ts @@ -7,8 +7,10 @@ import { finalize } from 'rxjs/operators'; import { NoticeReceiver } from '../../../pojo/NoticeReceiver'; import { NoticeRule, TagItem } from '../../../pojo/NoticeRule'; +import { NoticeSender } from '../../../pojo/NoticeSender'; import { NoticeReceiverService } from '../../../service/notice-receiver.service'; import { NoticeRuleService } from '../../../service/notice-rule.service'; +import { NoticeSenderService } from '../../../service/notice-sender.service'; import { TagService } from '../../../service/tag.service'; @Component({ @@ -20,24 +22,33 @@ export class AlertNoticeComponent implements OnInit { constructor( private notifySvc: NzNotificationService, private noticeReceiverSvc: NoticeReceiverService, + private noticeSenderSvc: NoticeSenderService, private modal: NzModalService, private noticeRuleSvc: NoticeRuleService, private tagService: TagService, - @Inject(ALAIN_I18N_TOKEN) private i18nSvc: I18NService + + @Inject(ALAIN_I18N_TOKEN) private i18nSvc: I18NService ) {} receivers!: NoticeReceiver[]; receiverTableLoading: boolean = true; rules!: NoticeRule[]; ruleTableLoading: boolean = true; + senders!: NoticeSender[]; + senderTableLoading: boolean = true; + ngOnInit(): void { this.loadReceiversTable(); this.loadRulesTable(); + this.loadSendersTable() } syncReceiver() { this.loadReceiversTable(); } + syncSender() { + this.loadSendersTable(); + } syncRule() { this.loadRulesTable(); } @@ -61,6 +72,26 @@ export class AlertNoticeComponent implements OnInit { } ); } + + loadSendersTable() { + this.senderTableLoading = true; + let senderInit$ = this.noticeSenderSvc.getSenders().subscribe( + message => { + this.senderTableLoading = false; + if (message.code === 0) { + this.senders = message.data; + } else { + console.warn(message.msg); + } + senderInit$.unsubscribe(); + }, + error => { + console.error(error.msg); + this.senderTableLoading = false; + senderInit$.unsubscribe(); + } + ); + } loadRulesTable() { this.ruleTableLoading = true; let rulesInit$ = this.noticeRuleSvc.getNoticeRules().subscribe( @@ -92,6 +123,17 @@ export class AlertNoticeComponent implements OnInit { nzOnOk: () => this.deleteOneNoticeReceiver(receiveId) }); } + onDeleteOneNoticeSender(senderId: number) { + this.modal.confirm({ + nzTitle: this.i18nSvc.fanyi('common.confirm.delete'), + nzOkText: this.i18nSvc.fanyi('common.button.ok'), + nzCancelText: this.i18nSvc.fanyi('common.button.cancel'), + nzOkDanger: true, + nzOkType: 'primary', + nzClosable: false, + nzOnOk: () => this.deleteOneNoticeSender(senderId) + }); + } deleteOneNoticeReceiver(receiveId: number) { const deleteReceiver$ = this.noticeReceiverSvc @@ -115,6 +157,28 @@ export class AlertNoticeComponent implements OnInit { } ); } + deleteOneNoticeSender(senderId: number) { + const deleteSender$ = this.noticeSenderSvc + .deleteSender(senderId) + .pipe( + finalize(() => { + deleteSender$.unsubscribe(); + }) + ) + .subscribe( + message => { + if (message.code === 0) { + this.notifySvc.success(this.i18nSvc.fanyi('common.notify.delete-success'), ''); + this.loadSendersTable(); + } else { + this.notifySvc.error(this.i18nSvc.fanyi('common.notify.delete-fail'), message.msg); + } + }, + error => { + this.notifySvc.error(this.i18nSvc.fanyi('common.notify.delete-fail'), error.msg); + } + ); + } onDeleteOneNoticeRule(ruleId: number) { this.modal.confirm({ @@ -254,6 +318,82 @@ export class AlertNoticeComponent implements OnInit { ); } } + // start 新增或修改通知发送端配置弹出框 + isManageSenderModalVisible: boolean = false; + isManageSenderModalAdd: boolean = true; + isManageSenderModalOkLoading: boolean = false; + sender!: NoticeSender; + + onNewNoticeSender() { + this.sender = new NoticeSender(); + this.isManageSenderModalVisible = true; + this.isManageSenderModalAdd = true; + } + onEditOneNoticeSender(sender: NoticeSender) { + this.sender = sender; + this.isManageSenderModalVisible = true; + this.isManageSenderModalAdd = false; + } + + onManageSenderModalCancel() { + this.isManageSenderModalVisible = false; + } + onManageSenderModalOk() { + this.isManageSenderModalOkLoading = true; + if (this.isManageSenderModalAdd) { + const modalOk$ = this.noticeSenderSvc + .newSender(this.sender) + .pipe( + finalize(() => { + modalOk$.unsubscribe(); + this.isManageSenderModalOkLoading = false; + }) + ) + .subscribe( + message => { + if (message.code === 0) { + this.isManageSenderModalVisible = false; + this.notifySvc.success(this.i18nSvc.fanyi('common.notify.new-success'), this.i18nSvc.fanyi('alert.notice.sender.next'), { + nzDuration: 15000 + }); + this.loadSendersTable(); + } else { + this.notifySvc.error(this.i18nSvc.fanyi('common.notify.new-fail'), message.msg); + } + }, + error => { + this.isManageSenderModalVisible = false; + this.notifySvc.error(this.i18nSvc.fanyi('common.notify.new-fail'), error.msg); + } + ); + } else { + const modalOk$ = this.noticeSenderSvc + .editSender(this.sender) + .pipe( + finalize(() => { + modalOk$.unsubscribe(); + this.isManageSenderModalOkLoading = false; + }) + ) + .subscribe( + message => { + if (message.code === 0) { + this.isManageSenderModalVisible = false; + this.notifySvc.success(this.i18nSvc.fanyi('common.notify.edit-success'), this.i18nSvc.fanyi('alert.notice.sender.next'), { + nzDuration: 15000 + }); + this.loadSendersTable(); + } else { + this.notifySvc.error(this.i18nSvc.fanyi('common.notify.edit-fail'), message.msg); + } + }, + error => { + this.isManageSenderModalVisible = false; + this.notifySvc.error(this.i18nSvc.fanyi('common.notify.edit-fail'), error.msg); + } + ); + } + } // start 新增或修改通知策略弹出框 isManageRuleModalVisible: boolean = false; diff --git a/web-app/src/app/service/notice-receiver.service.spec.ts b/web-app/src/app/service/notice-receiver.service.spec.ts index d1d1dfb537d..cafaf358323 100644 --- a/web-app/src/app/service/notice-receiver.service.spec.ts +++ b/web-app/src/app/service/notice-receiver.service.spec.ts @@ -1,13 +1,13 @@ import { TestBed } from '@angular/core/testing'; -import { NoticeReceiverService } from './notice-receiver.service'; +import { NoticeReceiverMailService } from './notice-receiver.service'; describe('NoticeReceiverService', () => { - let service: NoticeReceiverService; + let service: NoticeReceiverMailService; beforeEach(() => { TestBed.configureTestingModule({}); - service = TestBed.inject(NoticeReceiverService); + service = TestBed.inject(NoticeReceiverMailService); }); it('should be created', () => { diff --git a/web-app/src/app/service/notice-sender.service.ts b/web-app/src/app/service/notice-sender.service.ts new file mode 100644 index 00000000000..4e314fe62c5 --- /dev/null +++ b/web-app/src/app/service/notice-sender.service.ts @@ -0,0 +1,33 @@ +import { HttpClient } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { Observable } from 'rxjs'; + +import { Message } from '../pojo/Message'; +import { NoticeSender } from '../pojo/NoticeSender'; + +const notice_sender_save_uri = '/config/sender'; +const notice_sender_get_uri = '/config/senders'; +const notice_sender_delete_uri = '/config/sender'; + +@Injectable({ + providedIn: 'root' +}) +export class NoticeSenderService { + constructor(private http: HttpClient) {} + + public newSender(body: NoticeSender): Observable> { + return this.http.post>(notice_sender_save_uri, body); + } + + public editSender(body: NoticeSender): Observable> { + return this.http.post>(notice_sender_save_uri, body); + } + + public deleteSender(senderId: number): Observable> { + return this.http.delete>(`${notice_sender_delete_uri}/${senderId}`); + } + + public getSenders(): Observable> { + return this.http.get>(notice_sender_get_uri); + } +} diff --git a/web-app/src/assets/i18n/en-US.json b/web-app/src/assets/i18n/en-US.json index ed6e237404e..ddecaaa101d 100644 --- a/web-app/src/assets/i18n/en-US.json +++ b/web-app/src/assets/i18n/en-US.json @@ -226,6 +226,20 @@ "alert.notice.send-test": "Send Alert Test Msg", "alert.notice.send-test.notify.success": "Send Alert Test Success!", "alert.notice.send-test.notify.failed": "Send Alert Test Failed!", + "alert.notice.sender": "Server Sender Configuration", + "alert.notice.sender.next": "Please configure your 'Recipients' next!", + "alert.notice.sender.new": "New Server Configuration", + "alert.notice.sender.edit": "Edit Server Configuration", + "alert.notice.sender.delete": "Delete Server Configuration", + "alert.notice.sender.type": "Configuration Type", + "alert.notice.sender.config": "Configuration", + "alert.notice.sender.enable": "isEnabled", + "alert.notice.sender.mail": "Email", + "alert.notice.sender.mail.host": "Email Server Address", + "alert.notice.sender.mail.username": "Email Account", + "alert.notice.sender.mail.password": "Email Password", + "alert.notice.sender.mail.port": "Email Port", + "alert.notice.sender.mail.enable": "Enable Email Configuration", "dashboard.alerts.title": "Recently Alerts List", "dashboard.alerts.title-no": "Recently Pending Alerts", "dashboard.alerts.no": "No Pending Alerts", diff --git a/web-app/src/assets/i18n/zh-CN.json b/web-app/src/assets/i18n/zh-CN.json index 33c718c2559..a64dd0de138 100644 --- a/web-app/src/assets/i18n/zh-CN.json +++ b/web-app/src/assets/i18n/zh-CN.json @@ -226,6 +226,20 @@ "alert.notice.send-test": "发送告警测试", "alert.notice.send-test.notify.success": "触发告警测试成功!", "alert.notice.send-test.notify.failed": "触发告警测试失败!", + "alert.notice.sender": "消息发送服务端设置", + "alert.notice.sender.next": "下一步请配置您的[消息接收人]!", + "alert.notice.sender.new": "新增服务端配置", + "alert.notice.sender.edit": "编辑服务端配置", + "alert.notice.sender.delete": "删除服务端配置", + "alert.notice.sender.type": "配置类型", + "alert.notice.sender.config": "配置", + "alert.notice.sender.enable": "是否启用", + "alert.notice.sender.mail": "邮箱", + "alert.notice.sender.mail.host": "邮箱服务器地址", + "alert.notice.sender.mail.username": "邮箱账号", + "alert.notice.sender.mail.password": "邮箱密码", + "alert.notice.sender.mail.port": "邮箱端口", + "alert.notice.sender.mail.enable": "是否启用邮箱配置", "dashboard.alerts.title": "最近告警列表", "dashboard.alerts.title-no": "最近未处理告警", "dashboard.alerts.no": "暂无未处理告警", diff --git a/web-app/src/assets/i18n/zh-TW.json b/web-app/src/assets/i18n/zh-TW.json index b009a91afac..ffa48bebe55 100644 --- a/web-app/src/assets/i18n/zh-TW.json +++ b/web-app/src/assets/i18n/zh-TW.json @@ -226,6 +226,20 @@ "alert.notice.send-test": "發送告警測試", "alert.notice.send-test.notify.success": "觸發告警測試成功!", "alert.notice.send-test.notify.failed": "觸發告警測試失敗!", + "alert.notice.sender": "訊息傳送伺服器設定", + "alert.notice.sender.next": "請配置您的[訊息接收人]!", + "alert.notice.sender.new": "新增伺服器設定", + "alert.notice.sender.edit": "編輯伺服器設定", + "alert.notice.sender.delete": "刪除伺服器設定", + "alert.notice.sender.type": "設定類型", + "alert.notice.sender.config": "設定", + "alert.notice.sender.enable": "是否啟用", + "alert.notice.sender.mail": "電子郵件", + "alert.notice.sender.mail.host": "郵件伺服器地址", + "alert.notice.sender.mail.username": "郵件帳號", + "alert.notice.sender.mail.password": "郵件密碼", + "alert.notice.sender.mail.port": "郵件端口", + "alert.notice.sender.mail.enable": "啟用郵件設定", "dashboard.alerts.title": "最近告警列表", "dashboard.alerts.title-no": "最近未處理告警", "dashboard.alerts.no": "暫無未處理告警",