From 2ccc7b070d0f732ecb7492f64a1bcad0e81d7e80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=A6=E4=B9=A0=E4=BB=A3=E7=A0=81=E7=9A=84=E5=B0=8F?= =?UTF-8?q?=E7=99=BD?= <8145789+learning-code@user.noreply.gitee.com> Date: Fri, 18 Feb 2022 05:11:59 +0000 Subject: [PATCH 1/5] =?UTF-8?q?!4=20=E6=96=B0=E5=A2=9Econtroller=E5=B1=82?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=85=A5=E5=8F=82=E9=99=90=E5=AE=9A=E4=BF=AE?= =?UTF-8?q?=E9=A5=B0=E7=AC=A6=20*=20feature:=20=E6=96=B0=E5=A2=9Econtrolle?= =?UTF-8?q?r=E6=8E=A5=E5=8F=A3=E5=85=A5=E5=8F=82=E9=99=90=E5=AE=9A?= =?UTF-8?q?=E4=BF=AE=E9=A5=B0=E7=AC=A6=20#I4U9BT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manager/controller/AccountController.java | 2 +- .../usthe/manager/controller/AppController.java | 4 ++-- .../manager/controller/MonitorController.java | 4 ++-- .../manager/controller/MonitorsController.java | 14 +++++++------- .../manager/controller/NoticeConfigController.java | 8 ++++---- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/manager/src/main/java/com/usthe/manager/controller/AccountController.java b/manager/src/main/java/com/usthe/manager/controller/AccountController.java index a8284d6..7d53d29 100644 --- a/manager/src/main/java/com/usthe/manager/controller/AccountController.java +++ b/manager/src/main/java/com/usthe/manager/controller/AccountController.java @@ -91,7 +91,7 @@ public class AccountController { @ApiOperation(value = "TOKEN刷新", notes = "使用刷新TOKEN重新获取TOKEN") public ResponseEntity>> refreshToken( @ApiParam(value = "刷新TOKEN", example = "xxx") - @PathVariable("refreshToken") @NotNull String refreshToken) { + @PathVariable("refreshToken") @NotNull final String refreshToken) { String userId; boolean isRefresh; try { diff --git a/manager/src/main/java/com/usthe/manager/controller/AppController.java b/manager/src/main/java/com/usthe/manager/controller/AppController.java index d6e1a96..48f544b 100644 --- a/manager/src/main/java/com/usthe/manager/controller/AppController.java +++ b/manager/src/main/java/com/usthe/manager/controller/AppController.java @@ -36,7 +36,7 @@ public class AppController { @GetMapping(path = "/{app}/params") @ApiOperation(value = "查询监控类型的参数结构", notes = "根据app查询指定监控类型的需要输入参数的结构") public ResponseEntity>> queryAppParamDefines( - @ApiParam(value = "监控类型名称", example = "api") @PathVariable("app") String app) { + @ApiParam(value = "监控类型名称", example = "api") @PathVariable("app") final String app) { List paramDefines = appService.getAppParamDefines(app.toLowerCase()); return ResponseEntity.ok(new Message<>(paramDefines)); } @@ -44,7 +44,7 @@ public class AppController { @GetMapping(path = "/{app}/define") @ApiOperation(value = "查询监控类型的结构定义", notes = "根据app查询指定监控类型的定义结构") public ResponseEntity> queryAppDefine( - @ApiParam(value = "监控类型名称", example = "api") @PathVariable("app") String app) { + @ApiParam(value = "监控类型名称", example = "api") @PathVariable("app") final String app) { Job define = appService.getAppDefine(app.toLowerCase()); return ResponseEntity.ok(new Message<>(define)); } diff --git a/manager/src/main/java/com/usthe/manager/controller/MonitorController.java b/manager/src/main/java/com/usthe/manager/controller/MonitorController.java index 7588326..ef3e7ec 100644 --- a/manager/src/main/java/com/usthe/manager/controller/MonitorController.java +++ b/manager/src/main/java/com/usthe/manager/controller/MonitorController.java @@ -64,7 +64,7 @@ public class MonitorController { @GetMapping(path = "/{id}") @ApiOperation(value = "查询监控", notes = "根据监控ID获取监控信息") public ResponseEntity> getMonitor( - @ApiParam(value = "监控ID", example = "6565463543") @PathVariable("id") long id) { + @ApiParam(value = "监控ID", example = "6565463543") @PathVariable("id") final long id) { // 获取监控信息 MonitorDto monitorDto = monitorService.getMonitorDto(id); Message.MessageBuilder messageBuilder = Message.builder(); @@ -79,7 +79,7 @@ public class MonitorController { @DeleteMapping(path = "/{id}") @ApiOperation(value = "删除监控", notes = "根据监控ID删除监控应用,监控不存在也是删除成功") public ResponseEntity> deleteMonitor( - @ApiParam(value = "监控ID", example = "6565463543") @PathVariable("id") long id) { + @ApiParam(value = "监控ID", example = "6565463543") @PathVariable("id") final long id) { // 删除监控,监控不存在或删除成功都返回成功 monitorService.deleteMonitor(id); return ResponseEntity.ok(new Message<>("Delete success")); diff --git a/manager/src/main/java/com/usthe/manager/controller/MonitorsController.java b/manager/src/main/java/com/usthe/manager/controller/MonitorsController.java index c807c32..53be6f6 100644 --- a/manager/src/main/java/com/usthe/manager/controller/MonitorsController.java +++ b/manager/src/main/java/com/usthe/manager/controller/MonitorsController.java @@ -44,12 +44,12 @@ public class MonitorsController { @GetMapping @ApiOperation(value = "查询监控列表", notes = "根据查询过滤项获取监控信息列表") public ResponseEntity>> getMonitors( - @ApiParam(value = "监控ID", example = "6565463543") @RequestParam(required = false) List ids, - @ApiParam(value = "监控类型", example = "linux") @RequestParam(required = false) String app, - @ApiParam(value = "监控名称,模糊查询", example = "linux-127.0.0.1") @RequestParam(required = false) String name, - @ApiParam(value = "监控Host,模糊查询", example = "127.0.0.1") @RequestParam(required = false) String host, - @ApiParam(value = "排序字段,默认id", example = "name") @RequestParam(defaultValue = "id") String sort, - @ApiParam(value = "排序方式,asc:升序,desc:降序", example = "desc") @RequestParam(defaultValue = "desc") String order, + @ApiParam(value = "监控ID", example = "6565463543") @RequestParam(required = false) final List ids, + @ApiParam(value = "监控类型", example = "linux") @RequestParam(required = false) final String app, + @ApiParam(value = "监控名称,模糊查询", example = "linux-127.0.0.1") @RequestParam(required = false) final String name, + @ApiParam(value = "监控Host,模糊查询", example = "127.0.0.1") @RequestParam(required = false) final String host, + @ApiParam(value = "排序字段,默认id", example = "name") @RequestParam(defaultValue = "id") final String sort, + @ApiParam(value = "排序方式,asc:升序,desc:降序", example = "desc") @RequestParam(defaultValue = "desc") final String order, @ApiParam(value = "列表当前分页", example = "0") @RequestParam(defaultValue = "0") int pageIndex, @ApiParam(value = "列表分页数量", example = "8") @RequestParam(defaultValue = "8") int pageSize) { @@ -94,7 +94,7 @@ public class MonitorsController { @GetMapping(path = "/{app}") @ApiOperation(value = "查询指定监控类型的监控列表", notes = "根据查询过滤指定监控类型的所有获取监控信息列表") public ResponseEntity>> getAppMonitors( - @ApiParam(value = "监控类型", example = "linux") @PathVariable(required = false) String app) { + @ApiParam(value = "监控类型", example = "linux") @PathVariable(required = false) final String app) { List monitors = monitorService.getAppMonitors(app); Message> message = new Message<>(monitors); return ResponseEntity.ok(message); diff --git a/manager/src/main/java/com/usthe/manager/controller/NoticeConfigController.java b/manager/src/main/java/com/usthe/manager/controller/NoticeConfigController.java index c498941..2aaf181 100644 --- a/manager/src/main/java/com/usthe/manager/controller/NoticeConfigController.java +++ b/manager/src/main/java/com/usthe/manager/controller/NoticeConfigController.java @@ -57,7 +57,7 @@ public class NoticeConfigController { @DeleteMapping(path = "/receiver/{id}") @ApiOperation(value = "删除指定接收人", notes = "删除已存在的接收人信息") public ResponseEntity> deleteNoticeReceiver( - @ApiParam(value = "接收人ID", example = "6565463543") @PathVariable("id") Long receiverId) { + @ApiParam(value = "接收人ID", example = "6565463543") @PathVariable("id") final Long receiverId) { // 不存在或删除成功都返回成功 noticeConfigService.deleteReceiver(receiverId); return ResponseEntity.ok(new Message<>("Delete success")); @@ -66,7 +66,7 @@ public class NoticeConfigController { @GetMapping(path = "/receivers") @ApiOperation(value = "查询消息通知接收人", notes = "根据查询过滤项获取消息通知接收人列表") public ResponseEntity>> getReceivers( - @ApiParam(value = "接收人名称,模糊查询", example = "tom") @RequestParam(required = false) String name) { + @ApiParam(value = "接收人名称,模糊查询", example = "tom") @RequestParam(required = false) final String name) { Specification specification = (root, query, criteriaBuilder) -> { Predicate predicate = criteriaBuilder.conjunction(); @@ -99,7 +99,7 @@ public class NoticeConfigController { @DeleteMapping(path = "/rule/{id}") @ApiOperation(value = "删除指定通知策略", notes = "删除已存在的通知策略信息") public ResponseEntity> deleteNoticeRule( - @ApiParam(value = "通知策略ID", example = "6565463543") @PathVariable("id") Long ruleId) { + @ApiParam(value = "通知策略ID", example = "6565463543") @PathVariable("id") final Long ruleId) { // 不存在或删除成功都返回成功 noticeConfigService.deleteNoticeRule(ruleId); return ResponseEntity.ok(new Message<>("Delete success")); @@ -108,7 +108,7 @@ public class NoticeConfigController { @GetMapping(path = "/rules") @ApiOperation(value = "查询消息通知策略", notes = "根据查询过滤项获取消息通知策略列表") public ResponseEntity>> getRules( - @ApiParam(value = "接收人名称,模糊查询", example = "rule1") @RequestParam(required = false) String name) { + @ApiParam(value = "接收人名称,模糊查询", example = "rule1") @RequestParam(required = false) final String name) { Specification specification = (root, query, criteriaBuilder) -> { Predicate predicate = criteriaBuilder.conjunction(); From cef82ddf3bc5034750ae612682e88597d19f4ff3 Mon Sep 17 00:00:00 2001 From: tomsun28 Date: Fri, 18 Feb 2022 18:09:18 +0800 Subject: [PATCH 2/5] =?UTF-8?q?[manager,webapp,doc]=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E9=80=9A=E8=BF=87YML=E5=AF=B9=E7=94=A8=E6=88=B7=E8=B4=A6?= =?UTF-8?q?=E6=88=B7=E6=96=B0=E5=A2=9E=E5=88=A0=E9=99=A4=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=EF=BC=8C=E5=8D=87=E7=BA=A7sureness=E7=89=88?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- home/blog/2022-02-17-hertzbeat.md | 70 +++++++++++++++++++ home/docs/start/docker-deploy.md | 2 +- home/docs/start/package-deploy.md | 2 +- manager/pom.xml | 3 +- manager/src/main/resources/sureness.yml | 24 +++---- script/assembly/server/assembly.xml | 1 + script/docker/update-docker-service.sh | 2 +- .../layout/passport/passport.component.html | 6 +- .../passport/login/login.component.html | 8 +-- 9 files changed, 94 insertions(+), 24 deletions(-) create mode 100644 home/blog/2022-02-17-hertzbeat.md diff --git a/home/blog/2022-02-17-hertzbeat.md b/home/blog/2022-02-17-hertzbeat.md new file mode 100644 index 0000000..7bda96e --- /dev/null +++ b/home/blog/2022-02-17-hertzbeat.md @@ -0,0 +1,70 @@ +--- +title: 裸辞后我做了个开源监控告警系统 +author: tom +author_title: tom +author_url: https://github.com/tomsun28 +author_image_url: https://avatars.githubusercontent.com/u/24788200?s=400&v=4 +tags: [opensource] +--- + +# 裸辞后我做了个开源监控告警系统 + +**官网: [hertzbeat.com](https://hertzBeat.com) | [tancloud.cn](https://tancloud.cn)** +**仓库: [https://github.com/dromara/hertzbeat](https://github.com/dromara/hertzbeat) | [https://gitee.com/dromara/hertzbeat](https://gitee.com/dromara/hertzbeat)** + +大家好,这里自荐一个我全职开发的监控告警项目-HertzBeat赫兹跳动,欢迎大家了解试用。 + +毕业后也投入很多业余时间也做了一些开源项目 [Sureness](https://github.com/dromara/sureness) , [Bootshiro](https://gitee.com/tomsun28/bootshiro) , [Issues-translate-action](https://github.com/usthe/issues-translate-action) , +当时上班有空就回答网友问题,下班回家写开源代码,远程帮人看问题(大年30也看过😂),还总感觉时间不够用,当时想如果不去上班能做自己热爱的该多好,开源或者技术上能帮助别人感觉是作为程序员的一种成就感吧。 +既然想做开源为啥不能全职去做呢,想着年轻就要折腾,何况还是自己很想做的。于是乎21年底放弃激励裸辞开始全职开源了,也是第一次全职创业(虽然大概率失败,但搏一搏,单车变摩托🤓) +自己在APM领域做了多年,当然这次创业加开源的方向也就是老本行监控系统,我们开发一个支持多种监控指标(更多监控类型指标正在适配中),拥有自定义监控,支持阈值告警通知等功能,面向开发者友好的开源监控项目-HertzBeat赫兹跳动。 +为了感谢老婆大人的全力支持,hertzbeat服务端口默认为**1157**(遥遥无期)-老婆叫尧尧,我个人希望未来的宝宝叫午期(没有话语权可能性不大😂) +想到很多开发者和团队拥有云上资源,可能只需要使用监控服务而并不想部署繁杂的监控系统(往往有时候那套监控系统比我们自身服务消耗的服务器资源还多😅),我们也提供了可以直接登陆使用的SAAS云监控版本-[TanCloud探云](https://console.tancloud.cn)。 +希望老铁们多多支持了解试用点赞,非常感谢。 + + +### 介绍下HertzBeat + +> HertzBeat赫兹跳动 是一个支持网站,API,PING,端口,全站,数据库等监控类型,拥有易用友好的可视化操作界面的开源监控告警项目。 + +目前还在开发初期,后面会支持更多的监控类型。数据库,操作系统,云原生,中间件,应用服务等等通用的软件监控都计划安排上。 +在监控领域,监控需求指标啊这些往往千奇百怪,作为一个面向开发者的开源软件,[自定义监控](https://hertzbeat.com/docs/advanced/extend-point) 肯定是要安排上的,大家可以只通过配置YML文件就可以自定义需要的监控类型和指标,来满足常见的个性化需求。 +HertzBeat 也是模块化的,`manager, collector, scheduler, warehouse, alerter` 各个模块解耦合,方便理解上手和定制开发。 +我们也提供了更自由化的告警阈值配置,阈值触发表达式,三种告警级别,触发次数配置,支持告警通知模版,邮件webhook等方式告警通知,实时感知业务状态。 +更多功能欢迎登陆 HertzBeat 的 [云环境TanCloud](https://console.tancloud.cn) https://console.tancloud.cn 试用发现。 +项目正在快速迭代中,欢迎参与加入进来我们一起共建项目开源生态。 + +**关于HertzBeat的云SAAS环境TanCloud - https://console.tancloud.cn** + +我们很多开发者都会有自己的服务器,博客网站,数据库,云服务等云上资源。对于我们开发者或者中小团队,如何去花最小的精力去监控我们的云上资源,它们挂了或者异常能及时通知给我们进行处理,我感觉是值得探究的。 +如果是去自己部署一套监控系统在服务器上自己用,抛开学习成本和时间成本,往往有时候,那套监控系统比我们的自身网站消耗的服务器资源还大,这让原本紧张的服务器资源就更紧张了。 + +对此,我们提供了一个SAAS云监控服务,我们开发者或者中小团队个人无需再为了监控自己的网站等云上资源,而去部署一套繁琐的监控系统。 +[登陆即可免费开始使用](https://console.tancloud.cn) https://console.tancloud.cn。目前云环境功能还在快速迭代中,租户,权限等功能都会安排上,欢迎试用提需求提意见。 + + + +老铁们可以通过演示视频来直观了解功能: https://www.bilibili.com/video/BV1Vi4y1f7i8 + + + +##### 欢迎联系交流哦 + +**微信交流群** + +加微信号 tan-cloud 或 扫描下面账号二维码拉进微信群。 +tan-cloud + +**QQ交流群** + +加QQ群号 718618151 或 扫描下面的群二维码进群, 验证信息: tancloud + +tan-cloud + +**仓库地址** + +[Github](https://github.com/dromara/hertzbeat) https://github.com/dromara/hertzbeat +[Gitee](https://gitee.com/dromara/hertzbeat) https://gitee.com/dromara/hertzbeat + +欢迎老铁们了解使用反馈意见,看到这里不妨给个Star哦,灰常感谢,弯腰!! +如果有老哥老妹觉得不错可以投入,欢迎加入进来我们一起搞哦,现在急需懂前端,后台,运维的老哥老妹你了。 diff --git a/home/docs/start/docker-deploy.md b/home/docs/start/docker-deploy.md index 6156249..0dcbe7d 100644 --- a/home/docs/start/docker-deploy.md +++ b/home/docs/start/docker-deploy.md @@ -52,6 +52,6 @@ sidebar_label: Docker方式部署 - tancloud/hertzbeat:latest : 使用拉取的HertzBeat官方发布的应用镜像来启动容器 5. 开始探索HertzBeat - 浏览器访问 http://ip:1157/console 开始使用HertzBeat进行监控告警。 + 浏览器访问 http://ip:1157/console 开始使用HertzBeat进行监控告警。默认账户密码 admin/admin **HAVE FUN** diff --git a/home/docs/start/package-deploy.md b/home/docs/start/package-deploy.md index e0112b1..af59a28 100644 --- a/home/docs/start/package-deploy.md +++ b/home/docs/start/package-deploy.md @@ -50,6 +50,6 @@ sidebar_label: 安装包方式部署 $ ./startup.sh ``` 5. 开始探索HertzBeat - 浏览器访问 http://ip:1157/console 开始使用HertzBeat进行监控告警。 + 浏览器访问 http://ip:1157/console 开始使用HertzBeat进行监控告警。默认账户密码 admin/admin **HAVE FUN** diff --git a/manager/pom.xml b/manager/pom.xml index 3e644b5..2c868ea 100644 --- a/manager/pom.xml +++ b/manager/pom.xml @@ -14,7 +14,6 @@ 8.0.16 1.26 - 1.0.5 @@ -93,7 +92,7 @@ com.usthe.sureness spring-boot-starter-sureness - 1.0.6.beta1 + 1.0.7 diff --git a/manager/src/main/resources/sureness.yml b/manager/src/main/resources/sureness.yml index 5f602c0..96dde7b 100644 --- a/manager/src/main/resources/sureness.yml +++ b/manager/src/main/resources/sureness.yml @@ -1,14 +1,14 @@ -## -- sureness.yml document dataSource-- ## +## -- sureness.yml文本数据源 -- ## -# load api resource which need be protected, config role who can access these resource. -# resources that are not configured are also authenticated and protected by default, but not authorized -# eg: /api/v2/host===post===[role2,role3,role4] means /api/v2/host===post can be access by role2,role3,role4 -# eg: /api/v1/getSource3===get===[] means /api/v1/getSource3===get can not be access by any role +# 加载到匹配字典的资源,也就是需要被保护的,设置了所支持角色访问的资源 +# 没有配置的资源也默认被认证保护,但不鉴权 +# eg: /api/v1/source1===get===[role2] 表示 /api/v2/host===post 这条资源支持 role2 这一种角色访问 +# eg: /api/v1/source2===get===[] 表示 /api/v1/source2===get 这条资源不支持任何角色访问 resourceRole: - /account/auth/refresh===post===[role1,role2,role3,role4] -# load api resource which do not need protected, means them need be excluded. -# these api resource can be access by everyone +# 需要被过滤保护的资源,不认证鉴权直接访问 +# /api/v1/source3===get 表示 /api/v1/source3===get 可以被任何人访问 无需登录认证鉴权 excludedResource: - /account/auth/**===* - /===get @@ -28,11 +28,11 @@ excludedResource: - /v2/api-docs===get - /v3/api-docs===get -# account info -# there are three account: admin, root, tom -# eg: admin has [role1,role2] ROLE, unencrypted password is admin, encrypted password is 0192023A7BBD73250516F069DF18B500 -# eg: root has role1, unencrypted password is 23456 -# eg: tom has role3, unencrypted password is 32113 +# 用户账户信息 +# 下面有 admin root tom三个账户 +# eg: admin 拥有[role1,role2]角色,明文密码为admin,加盐密码为0192023A7BBD73250516F069DF18B500 +# eg: root 拥有[role1],密码为明文23456 +# eg: tom 拥有[role3],密码为明文32113 account: - appId: admin credential: admin diff --git a/script/assembly/server/assembly.xml b/script/assembly/server/assembly.xml index a554a77..5d439f2 100644 --- a/script/assembly/server/assembly.xml +++ b/script/assembly/server/assembly.xml @@ -36,6 +36,7 @@ http://maven.apache.org/ASSEMBLY/2.0.0 "> application.yml logback-spring.xml + sureness.yml true ${file.separator}config diff --git a/script/docker/update-docker-service.sh b/script/docker/update-docker-service.sh index 21ba084..8aeb983 100644 --- a/script/docker/update-docker-service.sh +++ b/script/docker/update-docker-service.sh @@ -11,4 +11,4 @@ echo "start pull and stop and replace hertzbeat container" docker pull registry.cn-hangzhou.aliyuncs.com/tomsun28/hertzbeat:"$TAG" docker stop hertzbeat docker rm hertzbeat -docker run -d -p 11157:1157 --name hertzbeat registry.cn-hangzhou.aliyuncs.com/tomsun28/hertzbeat:"$TAG" \ No newline at end of file +docker run -d -p 11157:1157 -v /home/ubuntu/hertzbeat/application.yml:/opt/hertzbeat/config/application.yml --name hertzbeat registry.cn-hangzhou.aliyuncs.com/tomsun28/hertzbeat:"$TAG" \ No newline at end of file diff --git a/web-app/src/app/layout/passport/passport.component.html b/web-app/src/app/layout/passport/passport.component.html index d041da6..d0a77bb 100644 --- a/web-app/src/app/layout/passport/passport.component.html +++ b/web-app/src/app/layout/passport/passport.component.html @@ -4,16 +4,16 @@
- 探云 + HertzBeat
-
易用友好的高性能监控云服务
+
TanCloud-易用友好的高性能监控云服务
Copyright 2021 探云 tancloud.cn | - 赫兹跳动 hertzbeat.com + 赫兹跳动 hertzbeat.com diff --git a/web-app/src/app/routes/passport/login/login.component.html b/web-app/src/app/routes/passport/login/login.component.html index e0443d9..697ed90 100644 --- a/web-app/src/app/routes/passport/login/login.component.html +++ b/web-app/src/app/routes/passport/login/login.component.html @@ -3,16 +3,16 @@ - + - + - + - + From e6d0540813a5a7d8ea6cf8cd275cce624a41b696 Mon Sep 17 00:00:00 2001 From: tomsun28 Date: Sat, 19 Feb 2022 14:32:07 +0800 Subject: [PATCH 3/5] =?UTF-8?q?[web-app]fix=20receiver=E7=9A=84email?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E9=94=99=E8=AF=AF=EF=BC=8C=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E5=BC=B9=E5=87=BA=E6=A1=86=E5=A4=A7=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/sureness.yml | 49 +++++++++++++++++++ web-app/src/app/pojo/NoticeReceiver.ts | 2 +- .../alert-notice/alert-notice.component.html | 4 +- 3 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 script/sureness.yml diff --git a/script/sureness.yml b/script/sureness.yml new file mode 100644 index 0000000..96dde7b --- /dev/null +++ b/script/sureness.yml @@ -0,0 +1,49 @@ +## -- sureness.yml文本数据源 -- ## + +# 加载到匹配字典的资源,也就是需要被保护的,设置了所支持角色访问的资源 +# 没有配置的资源也默认被认证保护,但不鉴权 +# eg: /api/v1/source1===get===[role2] 表示 /api/v2/host===post 这条资源支持 role2 这一种角色访问 +# eg: /api/v1/source2===get===[] 表示 /api/v1/source2===get 这条资源不支持任何角色访问 +resourceRole: + - /account/auth/refresh===post===[role1,role2,role3,role4] + +# 需要被过滤保护的资源,不认证鉴权直接访问 +# /api/v1/source3===get 表示 /api/v1/source3===get 可以被任何人访问 无需登录认证鉴权 +excludedResource: + - /account/auth/**===* + - /===get + - /i18n/**===get + # web ui 静态资源 + - /console/**===get + - /**/*.html===get + - /**/*.js===get + - /**/*.css===get + - /**/*.ico===get + - /**/*.ttf===get + - /**/*.png===get + - /**/*.gif===get + - /**/*.png===* + # swagger ui 资源 + - /swagger-resources/**===get + - /v2/api-docs===get + - /v3/api-docs===get + +# 用户账户信息 +# 下面有 admin root tom三个账户 +# eg: admin 拥有[role1,role2]角色,明文密码为admin,加盐密码为0192023A7BBD73250516F069DF18B500 +# eg: root 拥有[role1],密码为明文23456 +# eg: tom 拥有[role3],密码为明文32113 +account: + - appId: admin + credential: admin + role: [role1,role2] + - appId: tom + credential: tom@123 + role: [role1,role2,role3] + - appId: lili + # 注意 Digest认证不支持加盐加密的密码账户 + # 加盐加密的密码,通过 MD5(password+salt)计算 + # 此账户的原始密码为 lili + credential: 1A676730B0C7F54654B0E09184448289 + salt: 123 + role: [role1,role2] diff --git a/web-app/src/app/pojo/NoticeReceiver.ts b/web-app/src/app/pojo/NoticeReceiver.ts index 334d7ed..0742ff1 100644 --- a/web-app/src/app/pojo/NoticeReceiver.ts +++ b/web-app/src/app/pojo/NoticeReceiver.ts @@ -4,7 +4,7 @@ export class NoticeReceiver { // 通知信息方式: 0-手机短信 1-邮箱 2-webhook 3-微信公众号 type: number = 1; phone!: string; - email!: number; + email!: string; hookUrl!: string; wechatId!: string; creator!: string; 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 e45ab99..0561ba5 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 @@ -151,7 +151,7 @@ (nzOnCancel)="onManageReceiverModalCancel()" (nzOnOk)="onManageReceiverModalOk()" nzMaskClosable="false" - nzWidth="60%" + nzWidth="40%" [nzOkLoading]="isManageReceiverModalOkLoading" >
@@ -216,7 +216,7 @@ (nzOnCancel)="onManageRuleModalCancel()" (nzOnOk)="onManageRuleModalOk()" nzMaskClosable="false" - nzWidth="60%" + nzWidth="40%" [nzOkLoading]="isManageRuleModalOkLoading" >
From 9c38da871a8f145a759471b8e03989eb2bce2d5c Mon Sep 17 00:00:00 2001 From: tomsun28 Date: Sat, 19 Feb 2022 15:02:12 +0800 Subject: [PATCH 4/5] =?UTF-8?q?[alerter,common]fixbug=E5=91=8A=E8=AD=A6?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E5=85=B3=E8=81=94=E7=9B=91=E6=8E=A7=E4=B8=8D?= =?UTF-8?q?=E5=AD=98=E5=9C=A8=E6=97=B6=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/usthe/alert/controller/AlertDefineController.java | 2 ++ .../usthe/common/entity/alerter/AlertDefineMonitorBind.java | 3 +++ 2 files changed, 5 insertions(+) diff --git a/alerter/src/main/java/com/usthe/alert/controller/AlertDefineController.java b/alerter/src/main/java/com/usthe/alert/controller/AlertDefineController.java index 33a07bb..200e23c 100644 --- a/alerter/src/main/java/com/usthe/alert/controller/AlertDefineController.java +++ b/alerter/src/main/java/com/usthe/alert/controller/AlertDefineController.java @@ -21,6 +21,7 @@ import org.springframework.web.bind.annotation.RestController; import javax.validation.Valid; import java.util.List; +import java.util.stream.Collectors; import static com.usthe.common.util.CommonConstants.MONITOR_NOT_EXIST_CODE; import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; @@ -94,6 +95,7 @@ public class AlertDefineController { public ResponseEntity>> getAlertDefineMonitorsBind( @ApiParam(value = "告警定义ID", example = "6565463543") @PathVariable("alertDefineId") long alertDefineId) { List defineBinds = alertDefineService.getBindAlertDefineMonitors(alertDefineId); + defineBinds = defineBinds.stream().filter(item -> item.getMonitor() != null).collect(Collectors.toList()); return ResponseEntity.ok(new Message<>(defineBinds)); } diff --git a/common/src/main/java/com/usthe/common/entity/alerter/AlertDefineMonitorBind.java b/common/src/main/java/com/usthe/common/entity/alerter/AlertDefineMonitorBind.java index 49d9a52..7aaee70 100644 --- a/common/src/main/java/com/usthe/common/entity/alerter/AlertDefineMonitorBind.java +++ b/common/src/main/java/com/usthe/common/entity/alerter/AlertDefineMonitorBind.java @@ -7,6 +7,8 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; +import org.hibernate.annotations.NotFound; +import org.hibernate.annotations.NotFoundAction; import javax.persistence.Column; import javax.persistence.Entity; @@ -58,5 +60,6 @@ public class AlertDefineMonitorBind { @OneToOne(fetch = FetchType.EAGER) @JoinColumn(name = "monitor_id", referencedColumnName = "id", insertable = false, updatable = false) + @NotFound(action = NotFoundAction.IGNORE) private Monitor monitor; } From ab8bd560f0a725cfddaed1611e82797f4a032f66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=A6=E4=B9=A0=E4=BB=A3=E7=A0=81=E7=9A=84=E5=B0=8F?= =?UTF-8?q?=E7=99=BD?= <8145789+learning-code@user.noreply.gitee.com> Date: Sat, 19 Feb 2022 13:59:36 +0000 Subject: [PATCH 5/5] =?UTF-8?q?!5=20=E6=96=B0=E5=A2=9E=E5=91=8A=E8=AD=A6?= =?UTF-8?q?=E9=82=AE=E4=BB=B6=E6=A8=A1=E7=89=88=20*=20Merge=20remote-track?= =?UTF-8?q?ing=20branch=20'origin/master'=20*=20fix:=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=B3=A8=E9=87=8A=EF=BC=8C=E4=BB=A5=E5=8F=8A?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E8=BE=93=E5=87=BA=20#I4U9BT=20*=20Update=20w?= =?UTF-8?q?eb-app/package.json=20*=20Update=20web-app/package.json=20*=20U?= =?UTF-8?q?pdate=20web-app/package.json=20*=20Update=20web-app/package.jso?= =?UTF-8?q?n=20*=20Update=20manager/src/main/resources/application.yml=20*?= =?UTF-8?q?=20Update=20manager/src/main/resources/application.yml=20*=20fe?= =?UTF-8?q?ature:=20=E6=96=B0=E5=A2=9E=E9=82=AE=E4=BB=B6=E5=91=8A=E8=AD=A6?= =?UTF-8?q?=E6=A8=A1=E7=89=88=20#I4U9BT=20*=20feature:=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9Econtroller=E6=8E=A5=E5=8F=A3=E5=85=A5=E5=8F=82?= =?UTF-8?q?=E9=99=90=E5=AE=9A=E4=BF=AE=E9=A5=B0=E7=AC=A6=20#I4U9BT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- manager/pom.xml | 11 + .../component/alerter/DispatchAlarm.java | 41 ++- .../usthe/manager/service/MailService.java | 24 ++ .../manager/service/impl/MailServiceImpl.java | 39 +++ manager/src/main/resources/application.yml | 10 + .../main/resources/templates/mailAlarm.html | 323 ++++++++++++++++++ 6 files changed, 432 insertions(+), 16 deletions(-) create mode 100644 manager/src/main/java/com/usthe/manager/service/MailService.java create mode 100644 manager/src/main/java/com/usthe/manager/service/impl/MailServiceImpl.java create mode 100644 manager/src/main/resources/templates/mailAlarm.html diff --git a/manager/pom.xml b/manager/pom.xml index 2c868ea..b93f1de 100644 --- a/manager/pom.xml +++ b/manager/pom.xml @@ -51,6 +51,16 @@ spring-boot-configuration-processor true + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + net.sourceforge.nekohtml + nekohtml + 1.9.22 + org.springframework.boot @@ -107,6 +117,7 @@ sureness.yml banner.txt define/** + **/*.html diff --git a/manager/src/main/java/com/usthe/manager/component/alerter/DispatchAlarm.java b/manager/src/main/java/com/usthe/manager/component/alerter/DispatchAlarm.java index 8ae7f77..fcc3ed0 100644 --- a/manager/src/main/java/com/usthe/manager/component/alerter/DispatchAlarm.java +++ b/manager/src/main/java/com/usthe/manager/component/alerter/DispatchAlarm.java @@ -7,17 +7,19 @@ import com.usthe.alert.service.AlertService; import com.usthe.common.util.CommonConstants; import com.usthe.common.entity.manager.Monitor; import com.usthe.common.entity.manager.NoticeReceiver; +import com.usthe.manager.service.MailService; import com.usthe.manager.service.MonitorService; import com.usthe.manager.service.NoticeConfigService; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.mail.SimpleMailMessage; import org.springframework.mail.javamail.JavaMailSender; +import org.springframework.mail.javamail.MimeMessageHelper; import org.springframework.stereotype.Component; import org.springframework.web.client.ResourceAccessException; import org.springframework.web.client.RestTemplate; +import javax.mail.internet.MimeMessage; import java.util.Date; import java.util.List; @@ -37,10 +39,11 @@ public class DispatchAlarm { private NoticeConfigService noticeConfigService; private JavaMailSender javaMailSender; private RestTemplate restTemplate; + private MailService mailService; public DispatchAlarm(AlerterWorkerPool workerPool, AlerterDataQueue dataQueue, - JavaMailSender javaMailSender,NoticeConfigService noticeConfigService, - AlertService alertService, MonitorService monitorService, RestTemplate restTemplate) { + JavaMailSender javaMailSender, NoticeConfigService noticeConfigService, + AlertService alertService, MonitorService monitorService, RestTemplate restTemplate, MailService mailService) { this.workerPool = workerPool; this.dataQueue = dataQueue; this.alertService = alertService; @@ -48,6 +51,7 @@ public class DispatchAlarm { this.noticeConfigService = noticeConfigService; this.javaMailSender = javaMailSender; this.restTemplate = restTemplate; + this.mailService = mailService; startDispatch(); } @@ -137,19 +141,24 @@ public class DispatchAlarm { } } - private void sendEmailAlert(NoticeReceiver receiver, Alert alert) { - SimpleMailMessage message = new SimpleMailMessage(); - message.setSubject("TanCloud探云-监控告警"); - message.setFrom("gongchao@tancloud.cn"); - message.setTo(receiver.getEmail()); - message.setSentDate(new Date()); - message.setText("探云TanCloud-监控告警\n" + - "告警目标对象: " + alert.getTarget() + "\n" + - "所属监控ID: " + alert.getMonitorId() + "\n" + - "所属监控名称: " + alert.getMonitorName() + "\n" + - "告警级别: " + alert.getPriority() + "\n" + - "告警详情: \n" + alert.getContent()); - javaMailSender.send(message); + + private void sendEmailAlert(final NoticeReceiver receiver,final Alert alert){ + try{ + MimeMessage mimeMessage = javaMailSender.createMimeMessage(); + MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage,true,"UTF-8"); + messageHelper.setSubject("TanCloud探云-监控告警"); + //设置发件人Email + messageHelper.setFrom("gongchao@tancloud.cn"); + //设定收件人Email + messageHelper.setTo(receiver.getEmail()); + messageHelper.setSentDate(new Date()); + //构建邮件模版 + String process = mailService.buildHTMLTemplate(alert); + messageHelper.setText(process,true); //设置邮件内容模版 + javaMailSender.send(mimeMessage); + }catch (Exception e){ + log.error("[邮箱告警] error,Exception information={}",e.getMessage()); + } } private List matchReceiverByNoticeRules(Alert alert) { diff --git a/manager/src/main/java/com/usthe/manager/service/MailService.java b/manager/src/main/java/com/usthe/manager/service/MailService.java new file mode 100644 index 0000000..3fb835b --- /dev/null +++ b/manager/src/main/java/com/usthe/manager/service/MailService.java @@ -0,0 +1,24 @@ +package com.usthe.manager.service; + +import com.usthe.common.entity.alerter.Alert; +import lombok.extern.slf4j.Slf4j; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Service; + +/** + * 邮箱发送服务 + * + * @author 花城 + * @version 1.0 + * @date 2022/2/19 6:11 下午 + * @Description + */ +public interface MailService { + + /** + * 构建告警邮件模版 + * @param alert 告警信息 + * @return 邮件内容 + */ + String buildHTMLTemplate(Alert alert); +} diff --git a/manager/src/main/java/com/usthe/manager/service/impl/MailServiceImpl.java b/manager/src/main/java/com/usthe/manager/service/impl/MailServiceImpl.java new file mode 100644 index 0000000..8f37032 --- /dev/null +++ b/manager/src/main/java/com/usthe/manager/service/impl/MailServiceImpl.java @@ -0,0 +1,39 @@ +package com.usthe.manager.service.impl; + +import com.usthe.common.entity.alerter.Alert; +import com.usthe.manager.service.MailService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.thymeleaf.TemplateEngine; +import org.thymeleaf.context.Context; + +import javax.annotation.Resource; + +/** + * 邮箱发送服务接口实现类 + * + * @author 花城 + * @version 1.0 + * @date 2022/2/19 6:13 下午 + * @Description + */ +@Slf4j +@Service +public class MailServiceImpl implements MailService { + + @Resource + private TemplateEngine templateEngine; + + @Override + public String buildHTMLTemplate(final Alert alert) { + //引入thymeleaf上下文参数渲染页面 + Context context = new Context(); + context.setVariable("target",alert.getTarget()); + context.setVariable("ID",alert.getMonitorId()); + context.setVariable("name",alert.getMonitorName()); + context.setVariable("priority",alert.getPriority()); + context.setVariable("content",alert.getContent()); + return templateEngine.process("mailAlarm", context); + } +} diff --git a/manager/src/main/resources/application.yml b/manager/src/main/resources/application.yml index f199836..cff7e0f 100644 --- a/manager/src/main/resources/application.yml +++ b/manager/src/main/resources/application.yml @@ -48,6 +48,16 @@ spring: socketFactoryClass: javax.net.ssl.SSLSocketFactory ssl: enable: true + debug: false + + thymeleaf: + prefix: classpath:/templates/ #prefix:指定模板所在的目录 + check-template-location: true #check-tempate-location: 检查模板路径是否存在 + cache: false #cache: 是否缓存,开发模式下设置为false,避免改了模板还要重启服务器,线上设置为true,可以提高性能。 + suffix: .html + #encoding: UTF-8 + #content-type: text/html + mode: LEGACYHTML5 warehouse: store: diff --git a/manager/src/main/resources/templates/mailAlarm.html b/manager/src/main/resources/templates/mailAlarm.html new file mode 100644 index 0000000..3589c4f --- /dev/null +++ b/manager/src/main/resources/templates/mailAlarm.html @@ -0,0 +1,323 @@ + + + + + + + + + + + + + + +
+
+


+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+ TanCloud探云-监控告警 +

+
+
+

+ 告警通知 +

+
+
+

+ Alarm notification +

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+ TanCloud探云 +

+
+
+
+ +
+
+
+
+


+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+ 告警目标对象:
+     所属监控ID:
+     所属监控名称:
+     告警级别:
+     告警详情:
+
+

+

+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


+


+ +
+
+ + + + + + + \ No newline at end of file