From 1b351e3206046f3e0479aa745c0386dc0e98bcf7 Mon Sep 17 00:00:00 2001 From: kechangqing Date: Thu, 10 Mar 2022 15:16:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E7=9F=AD=E9=93=BE=E6=8E=A5?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 实现短链接功能 --- README.md | 51 ++--- ReleaseNotes.md | 7 + doc/mysql-schema/2022-03-08/config_map.sql | 16 ++ doc/mysql-schema/2022-03-08/short_link.sql | 10 + doc/mysql-schema/frostmourne.sql | 31 +++ doc/mysql-schema/tables/config_map.sql | 16 ++ doc/mysql-schema/tables/short_link.sql | 10 + doc/wiki/template.md | 39 +++- .../controller/DataQueryController.java | 7 +- .../monitor/controller/IndexController.java | 39 ++++ .../mybatis/frostmourne/domain/ConfigMap.java | 97 +++++++++ .../mybatis/frostmourne/domain/ShortLink.java | 45 +++++ .../dynamic/ConfigMapDynamicMapper.java | 187 ++++++++++++++++++ .../dynamic/ConfigMapDynamicSqlSupport.java | 54 +++++ .../dynamic/ShortLinkDynamicMapper.java | 159 +++++++++++++++ .../dynamic/ShortLinkDynamicSqlSupport.java | 34 ++++ .../repository/IConfigMapRepository.java | 10 + .../repository/IShortLinkRepository.java | 12 ++ .../repository/impl/ConfigMapRepository.java | 25 +++ .../repository/impl/ShortLinkRepository.java | 27 +++ .../service/core/alert/AlertService.java | 18 +- .../service/core/domain/ConfigMapKeys.java | 6 + .../service/core/execute/AlarmService.java | 2 +- .../execute/GenerateShortLinkService.java | 25 +-- .../core/service/IShortLinkService.java | 6 + .../{ => impl}/ServiceInfoService.java | 3 +- .../core/service/impl/ShortLinkService.java | 29 +++ .../src/main/resources/generatorConfig.xml | 13 +- .../spi/starter/api/IFrostmourneSpiApi.java | 4 - .../spi/starter/mock/MockFrostmourneSpi.java | 5 - frostmourne-vue/src/views/alarm/edit.vue | 3 + pom.xml | 14 ++ 32 files changed, 935 insertions(+), 69 deletions(-) create mode 100644 doc/mysql-schema/2022-03-08/config_map.sql create mode 100644 doc/mysql-schema/2022-03-08/short_link.sql create mode 100644 doc/mysql-schema/tables/config_map.sql create mode 100644 doc/mysql-schema/tables/short_link.sql create mode 100644 frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/controller/IndexController.java create mode 100644 frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/domain/ConfigMap.java create mode 100644 frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/domain/ShortLink.java create mode 100644 frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/mapper/dynamic/ConfigMapDynamicMapper.java create mode 100644 frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/mapper/dynamic/ConfigMapDynamicSqlSupport.java create mode 100644 frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/mapper/dynamic/ShortLinkDynamicMapper.java create mode 100644 frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/mapper/dynamic/ShortLinkDynamicSqlSupport.java create mode 100644 frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/repository/IConfigMapRepository.java create mode 100644 frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/repository/IShortLinkRepository.java create mode 100644 frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/repository/impl/ConfigMapRepository.java create mode 100644 frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/repository/impl/ShortLinkRepository.java create mode 100644 frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/service/core/domain/ConfigMapKeys.java create mode 100644 frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/service/core/service/IShortLinkService.java rename frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/service/core/service/{ => impl}/ServiceInfoService.java (95%) create mode 100644 frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/service/core/service/impl/ShortLinkService.java diff --git a/README.md b/README.md index 604a8726..7f06718e 100644 --- a/README.md +++ b/README.md @@ -208,27 +208,8 @@ pod: ${data.result[0].metric.pod} ## 短链接服务 -为了方便使用者快速查看产生报警的日志,报警消息最后会有一个日志查询地址的短链接,打开即可看到产生报警的日志。目前默认支持的短链接 -有两种:四五短网址和百度短网址。默认短链接实现使用的是四五短网址免费版,网址: 45短网址, 默认申请的token限制很大, -调用次数有限制,你可以去45短网址申请自己token,或者你可以自己选择换别的短网址服务都行,只需要自己实现简单适配即可。 - -如果你自己申请了token,请修改配置文件 frostmourne-spi/src/main/resources/application.properties 如下配置值: - -``` -dwz.type=dwz45 -dwz45.token=t8HGzRNv9TmvqUFICNoW3SaYNA1C9OAC -``` - -如果想切换使用百度短网址,请通过修改如下配置: - -``` -dwz.type=baidu -dwz.baidu.token= -``` - -token需要自己申请。 - -> 说明:如果短链接服务出错或者不使用,报警消息里的链接将使用原链接,会比较长。 +为了方便使用者快速查看产生报警的日志,报警消息最后会有一个日志查询地址的短链接,打开即可看到产生报警的日志。在0.4版本之前支持的短链接有两种:四五短网址和百度短网址。 +在0.5版本之后,内置实现了短链接功能,所以不需要额外配置短链接服务了。 ## 用户管理和登录认证 @@ -439,28 +420,33 @@ mybatis最新推出了新的模块[mybatis-dynamic-sql](https://github.com/mybat * ~~log4j2升级至2.17.1~~ [2022-01-14] * ~~恢复通知默认改为关闭~~ [2022-02-16] * ~~解决不报警并且关闭恢复通知的时候,没有记录执行日志的问题。~~ [issue#53](https://github.com/AutohomeCorp/frostmourne/issues/53) [2022-03-07] -* elasticsearch数据监控增加kibana链接设置,如果设置kibana短链,查询链接将优先使用kibana。 -* 解决邮箱报警不支持ssl的问题 +* ~~mysql: 增加短链接表 [short_link](./doc/mysql-schema/2022-03-08/short_link.sql)~~ [2022-03-08] +* ~~elasticsearch数据监控增加查询链接配置,例如可以设置查询链接为kibana链接,查询链接将优先使用kibana链接。~~ [2022-03-09] +* ~~内置实现一个短链接功能,移除外部短链接服务依赖,解决外部短链接服务请求比较慢的问题~~ [2022-03-09] +* ~~修改短链接部分文档说明~~ [2022-03-10] +* ~~mysql: 增加配置表[config_map](./doc/mysql-schema/2022-03-08/config_map.sql)~~ [2022-03-10] +* ~~doc: 增加如何配置报警消息头的方法文档说明~~ [2022-03-10] +* 增加邮箱在线配置页面功能 +* 增加企业微信在线配置页面功能 +* 将发送消息功能从spi移到monitor; +* 移除spi模块,随着monitor功能完善,spi的存在已经成为鸡肋,移除掉可以降低调试和部署难度。 * 增加消息内容长度配置,超过长度配置部分将被截掉 -* 增加报警消息头设置 -* 报警消息增加静默说明,如:请注意,未来10分钟此监控连续报警消息将被静默 -* 内置实现一个短链接功能,移除外部短链接服务依赖,解决外部短链接服务请求比较慢的问题 -* 增加报警消息是否附带查询链接配置 * msyql监控增加表达式监控规则 -* 增加用户密码设置功能,方便没有部署ldap的团队 * Elasticsearch监控数值实现环比监控 +* 解决邮箱报警不支持ssl的问题 +* 增加用户密码设置功能,方便没有部署ldap的团队使用。配置了ldap的将优先使用ldap认证。 +* 发布0.5-RELEASE +* important breaking feature: 移除xxl-job依赖,内置实现分布式调度,减小部署难度 * 解决firefox浏览器时间显示有问题的bug * 增加报警组支持 -* Elasticsearch数据名增加traceid字段配置,可以配置为skywalking的traceId,显示skywalking traceid的时候,增加连接,跳转到skywalking对应的调用链 +* Elasticsearch数据名增加traceid字段配置,可以配置跳转链接。例如: 配置skywalking的链接将跳转到skywalking对应的调用链 * 报警消息格式增加类型: text, markdown选项 * 数据配置支持数据分组,分组类型支持两种:1. 按字段值分组,相当于ES里的Terms Aggregation; 2. 按时间分组,相当于ES里的DateHistogramAggregation * 增加[prometheus](https://github.com/prometheus/prometheus)数据监控报警支持 * 增加[skywalking](https://github.com/apache/skywalking)数据监控报警支持 * 增加[iotdb](https://github.com/apache/iotdb)数据监控报警 * 增加[loki](https://github.com/grafana/loki)数据监控报警 -* 改进消息静默功能:对报警事件数据和静默时间内的事件数据对比,如果相似度很高就静默,如果和静默时间内事件相似度不高仍然报警。这样可以避免漏报同时防止报警消息过多导致疲劳。 -* mysql数据监控增加除count外其他聚合类型支持 -* clickhouse数据监控增加除count外其他聚合类型支持 +* 改进消息静默功能:对报警事件数据和静默时间内的事件数据对比,如果相似度很高就静默,如果和静默时间内事件相似度不高仍然报警。这样可以避免漏报同时防止报警消息过多。 * influxDB数据查询除了返回数值,另外返回最新一个point详细数据用于报警消息模板 * 增加influxDB数据查询页面 * influxdb数据监控增加短链接,跳转到influxdb数据查询页面 @@ -485,7 +471,6 @@ mybatis最新推出了新的模块[mybatis-dynamic-sql](https://github.com/mybat * 增加frostmourne程序日志查询和分析功能 * 3-sigma离群点检测报警规则 * 加入时序数据异常检测算法规则(需要实验可行性,欢迎有相关经验的同僚联系) -* 移除xxl-job依赖,内置实现分布式调度,减小部署难度(待定) * 总结项目用到的知识点 ## 发版历史 diff --git a/ReleaseNotes.md b/ReleaseNotes.md index 8ad57e7b..9c2db49d 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -5,6 +5,8 @@ * 报警方式增加飞书机器人 [2021-10-30] * http监控兼容异常状态码 [2021-11-06] * 恢复通知默认改为关闭 [2022-02-16] +* elasticsearch数据监控增加查询链接配置,例如可以设置查询链接为kibana链接,查询链接将优先使用kibana链接。 [2022-03-09] +* 内置实现一个短链接功能,移除外部短链接服务依赖,解决外部短链接服务请求比较慢的问题 [2022-03-09] ### Bugfix @@ -14,9 +16,14 @@ ### Mysql * mysql: alert表增加字段feishu_robot_hook,表示飞书机器人地址 - [SQL](./doc/mysql-schema/2021-10-30/change.sql) [2021-10-30] +* mysql: 增加短链接表short_link - [SQL](./doc/mysql-schema/2022-03-08/short_link.sql) [2022-03-08] +* mysql: 增加配置表config_map - [SQL](./doc/mysql-schema/2022-03-08/config_map.sql) [2022-03-08] ### Document +* 修改短链接部分文档说明, 移除外部短链接依赖 [2022-03-10] +* 增加如何配置报警消息头的方法说明 [2022-03-10] + ### Others * log4j2升级至2.17.1 [2022-01-14] diff --git a/doc/mysql-schema/2022-03-08/config_map.sql b/doc/mysql-schema/2022-03-08/config_map.sql new file mode 100644 index 00000000..137ebfc6 --- /dev/null +++ b/doc/mysql-schema/2022-03-08/config_map.sql @@ -0,0 +1,16 @@ +DROP TABLE IF EXISTS config_map; +CREATE TABLE IF NOT EXISTS config_map +( + id BIGINT AUTO_INCREMENT PRIMARY KEY COMMENT '自增主键', + config_key VARCHAR(500) NOT NULL COMMENT '配置key', + config_value VARCHAR(1000) NOT NULL COMMENT '配置value', + creator VARCHAR(200) NOT NULL COMMENT '创建人', + create_at DATETIME NOT NULL COMMENT '创建时间', + modify_at DATETIME NOT NULL COMMENT '修改时间', + modifier VARCHAR(200) NOT NULL COMMENT '最后修改人' +) + ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4 + COMMENT = '内部配置表'; + +CREATE UNIQUE INDEX uniq_configkey ON config_map (config_key); diff --git a/doc/mysql-schema/2022-03-08/short_link.sql b/doc/mysql-schema/2022-03-08/short_link.sql new file mode 100644 index 00000000..40e57527 --- /dev/null +++ b/doc/mysql-schema/2022-03-08/short_link.sql @@ -0,0 +1,10 @@ +DROP TABLE IF EXISTS short_link; +CREATE TABLE IF NOT EXISTS short_link +( + id BIGINT AUTO_INCREMENT PRIMARY KEY COMMENT '自增主键', + long_link VARCHAR(1000) NOT NULL COMMENT '监控数据类型。(http: http监控;其他值: 关联data_name表)', + create_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间' +) + ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4 + COMMENT = '短链接表'; diff --git a/doc/mysql-schema/frostmourne.sql b/doc/mysql-schema/frostmourne.sql index 67b55d7d..2e04c5c5 100644 --- a/doc/mysql-schema/frostmourne.sql +++ b/doc/mysql-schema/frostmourne.sql @@ -369,6 +369,37 @@ CREATE TABLE IF NOT EXISTS `service_info` ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COMMENT ='服务信息'; +/*------------------------------------------- create short_link---------------------------------------------------------------------*/ +DROP TABLE IF EXISTS short_link; +CREATE TABLE IF NOT EXISTS short_link +( + id BIGINT AUTO_INCREMENT PRIMARY KEY COMMENT '自增主键', + long_link VARCHAR(1000) NOT NULL COMMENT '监控数据类型。(http: http监控;其他值: 关联data_name表)', + create_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间' +) + ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4 + COMMENT = '短链接表'; + +/*------------------------------------------- create config_map---------------------------------------------------------------------*/ +DROP TABLE IF EXISTS config_map; +CREATE TABLE IF NOT EXISTS config_map +( + id BIGINT AUTO_INCREMENT PRIMARY KEY COMMENT '自增主键', + config_key VARCHAR(500) NOT NULL COMMENT '配置key', + config_value VARCHAR(1000) NOT NULL COMMENT '配置value', + creator VARCHAR(200) NOT NULL COMMENT '创建人', + create_at DATETIME NOT NULL COMMENT '创建时间', + modify_at DATETIME NOT NULL COMMENT '修改时间', + modifier VARCHAR(200) NOT NULL COMMENT '最后修改人' +) + ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4 + COMMENT = '内部配置表'; + +CREATE UNIQUE INDEX uniq_configkey ON config_map (config_key); + + /*------------------------------------------- init data---------------------------------------------------------------------*/ INSERT INTO department_info(department_name, full_name, creator, create_at, modify_at, modifier) VALUES ('default', '默认部门', 'admin', now(), now(), 'admin'); diff --git a/doc/mysql-schema/tables/config_map.sql b/doc/mysql-schema/tables/config_map.sql new file mode 100644 index 00000000..137ebfc6 --- /dev/null +++ b/doc/mysql-schema/tables/config_map.sql @@ -0,0 +1,16 @@ +DROP TABLE IF EXISTS config_map; +CREATE TABLE IF NOT EXISTS config_map +( + id BIGINT AUTO_INCREMENT PRIMARY KEY COMMENT '自增主键', + config_key VARCHAR(500) NOT NULL COMMENT '配置key', + config_value VARCHAR(1000) NOT NULL COMMENT '配置value', + creator VARCHAR(200) NOT NULL COMMENT '创建人', + create_at DATETIME NOT NULL COMMENT '创建时间', + modify_at DATETIME NOT NULL COMMENT '修改时间', + modifier VARCHAR(200) NOT NULL COMMENT '最后修改人' +) + ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4 + COMMENT = '内部配置表'; + +CREATE UNIQUE INDEX uniq_configkey ON config_map (config_key); diff --git a/doc/mysql-schema/tables/short_link.sql b/doc/mysql-schema/tables/short_link.sql new file mode 100644 index 00000000..40e57527 --- /dev/null +++ b/doc/mysql-schema/tables/short_link.sql @@ -0,0 +1,10 @@ +DROP TABLE IF EXISTS short_link; +CREATE TABLE IF NOT EXISTS short_link +( + id BIGINT AUTO_INCREMENT PRIMARY KEY COMMENT '自增主键', + long_link VARCHAR(1000) NOT NULL COMMENT '监控数据类型。(http: http监控;其他值: 关联data_name表)', + create_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间' +) + ENGINE = InnoDB + DEFAULT CHARSET = utf8mb4 + COMMENT = '短链接表'; diff --git a/doc/wiki/template.md b/doc/wiki/template.md index d3d32809..df47ee90 100644 --- a/doc/wiki/template.md +++ b/doc/wiki/template.md @@ -3,9 +3,9 @@ 消息模板使用的语法是freemarker,具体用法参考freemarker官方文档。可用的变量分两部分。一部分是报警规则设置,一部分 是查询出来的数据。不同规则可使用的变量如下表格。 - 字段名 | 类型 | 说明 | 适用的判断类型 + 字段名 | 类型 | 说明 | 适用的判断类型 -------- |----------| ------- | ----- -TIME_WINDOW | int | 查询时间范围窗口大小(单位: 分钟) | 数值 +TIME_WINDOW | int | 查询时间范围窗口大小(单位: 分钟) | 数值 NUMBER | double | 数值类型值 | 数值 THRESHOLD | double | 判断阈值 | 数值 COUNT | long | 查询记录数量 | 数值 @@ -14,12 +14,12 @@ COUNT | long | 查询记录数量 | 数值 ### HTTP数据内置变量 - 字段名 | 类型 | 说明 | 适用的数据源 + 字段名 | 类型 | 说明 | 适用的数据源 -------- |----------| ------- | ----- -HTTP_STATUS | int | HTTP状态码 | HTTP +HTTP_STATUS | int | HTTP状态码 | HTTP HTTP_COST | long | 请求耗时 | HTTP -查询的数据可用变量取决于你的数据格式。以我们部门程序日志数值监控为例,可用变量和我们日志格式是一致的。如下表格: +查询的数据可用变量取决于你的数据格式。以我们部门程序日志数值监控为例,可用变量和我们日志格式是一致的。如下表格: 序号 | 字段名 | 类型 | 说明 | Elasticsearch存储 ----|-------- |----------| ------- | ----- @@ -46,9 +46,9 @@ HTTP_COST | long | 请求耗时 | HTTP 21 | ExceptionMessage | string | 异常信息 | 分词 22 | CustomMessage | string | 自定义信息 | 分词 23 | StackTrace | string | 堆栈信息 | 分词 -24 | HawkKey | string | Key | 不分词 +24 | HawkKey | string | Key | 不分词 -这样我们一般为程序日志报警定制的消息模板为: +这样我们一般为程序日志报警定制的消息模板为: ``` ${Project}最近${TIME_WINDOW}分钟内有异常日志${NUMBER}条。最近一条异常信息: @@ -79,4 +79,27 @@ HttpCode: ${code} ``` 这里用我们内部使用的例子供大家参考使用,具体模板内容,你需要自己根据数据格式定制。如果你想使用我们的日志格式,请参考 -另外一个开源项目: autolog4j[https://github.com/AutohomeCorp/autolog4j] \ No newline at end of file +另外一个开源项目: autolog4j[https://github.com/AutohomeCorp/autolog4j] + +## Q: 报警字段值太长,如何处理? + +freemarker提供了字符串截取的操作,例如: + +``` +${userName?truncate(16)} +``` + +如果userName长度超过16,将被截取。更多使用方法请参考[freemarker文档](https://freemarker.apache.org/docs/ref_builtins_string.html#ref_builtin_truncate); + +## Q: 如何设置报警消息头? + +默认报警消息title是: 霜之哀伤监控平台。可以配置config_map表config_key为AlertTitle的行的config_value值来设置自定义报警消息头。例如: + +```sql +INSERT INTO config_map(config_key, config_value, creator, create_at, modifier, modify_at) +VALUES('AlertTitle', '霜之哀伤监控平台', 'admin', now(), 'admin', now()); +``` + +同一个config_key禁止配置多条,对config_key建了唯一索引。 + +注意如果你的报警机器人依赖报警消息头作为关键词,请记得同时改机器人配置,否则会导致机器人消息无法发送。 diff --git a/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/controller/DataQueryController.java b/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/controller/DataQueryController.java index ab584c82..fd6a69e7 100644 --- a/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/controller/DataQueryController.java +++ b/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/controller/DataQueryController.java @@ -13,6 +13,7 @@ import com.autohome.frostmourne.core.contract.Protocol; import com.autohome.frostmourne.monitor.contract.ElasticsearchDataResult; import com.autohome.frostmourne.monitor.service.core.query.IQueryService; +import com.autohome.frostmourne.monitor.service.core.service.IShortLinkService; import com.autohome.frostmourne.spi.starter.api.IFrostmourneSpiApi; import org.elasticsearch.common.Strings; import org.joda.time.DateTime; @@ -36,6 +37,9 @@ public class DataQueryController { @Resource private IFrostmourneSpiApi frostmourneSpiApi; + @Resource + private IShortLinkService shortLinkService; + @ResponseBody @RequestMapping(value = "/elasticsearchData") public Protocol elasticsearchData(@RequestParam(value = "_appId", required = true) String _appId, @@ -70,7 +74,8 @@ public Protocol> elasticsearchFields(@RequestParam(value = "_appId" @RequestMapping(value = "/shortenLink", method = RequestMethod.GET) public Protocol shortenLink(@RequestParam(value = "_appId", required = true) String _appId, @RequestParam(value = "longUrl", required = true) String longUrl) { - return frostmourneSpiApi.shortenLink("frostmourne-monitor", longUrl); + String shortLink = shortLinkService.shorten(longUrl); + return new Protocol<>(shortLink); } @RequestMapping(value = "/downloadData") diff --git a/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/controller/IndexController.java b/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/controller/IndexController.java new file mode 100644 index 00000000..38c93efa --- /dev/null +++ b/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/controller/IndexController.java @@ -0,0 +1,39 @@ +package com.autohome.frostmourne.monitor.controller; + +import java.util.Optional; +import javax.annotation.Resource; + +import com.autohome.frostmourne.monitor.controller.annotation.PermissionLimit; +import com.autohome.frostmourne.monitor.dao.mybatis.frostmourne.domain.ShortLink; +import com.autohome.frostmourne.monitor.dao.mybatis.frostmourne.repository.IShortLinkRepository; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +@Controller +public class IndexController { + + private final static Logger LOGGER = LoggerFactory.getLogger(IndexController.class); + + @Resource + private IShortLinkRepository shortLinkRepository; + + @PermissionLimit(limit = false) + @RequestMapping(value = "/goto/{id}", method = RequestMethod.GET) + public String jump(@PathVariable(value = "id") Long id) { + if (id == null || id <= 0) { + LOGGER.error("invalid short link id: {}", id); + return "redirect:/dashboard.view"; + } + Optional shortLinkOptional = shortLinkRepository.selectByPrimaryKey(id); + if (shortLinkOptional.isPresent()) { + return String.format("redirect:%s", shortLinkOptional.get().getLongLink()); + } else { + LOGGER.error("invalid short link id: {}", id); + return "redirect:/dashboard.view"; + } + } +} diff --git a/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/domain/ConfigMap.java b/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/domain/ConfigMap.java new file mode 100644 index 00000000..134652f6 --- /dev/null +++ b/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/domain/ConfigMap.java @@ -0,0 +1,97 @@ +package com.autohome.frostmourne.monitor.dao.mybatis.frostmourne.domain; + +import java.util.Date; +import javax.annotation.Generated; + +public class ConfigMap { + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.84+08:00", comments="Source field: config_map.id") + private Long id; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.844+08:00", comments="Source field: config_map.config_key") + private String configKey; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.844+08:00", comments="Source field: config_map.config_value") + private String configValue; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.844+08:00", comments="Source field: config_map.creator") + private String creator; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.844+08:00", comments="Source field: config_map.create_at") + private Date createAt; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.844+08:00", comments="Source field: config_map.modify_at") + private Date modifyAt; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.844+08:00", comments="Source field: config_map.modifier") + private String modifier; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.842+08:00", comments="Source field: config_map.id") + public Long getId() { + return id; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.844+08:00", comments="Source field: config_map.id") + public void setId(Long id) { + this.id = id; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.844+08:00", comments="Source field: config_map.config_key") + public String getConfigKey() { + return configKey; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.844+08:00", comments="Source field: config_map.config_key") + public void setConfigKey(String configKey) { + this.configKey = configKey; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.844+08:00", comments="Source field: config_map.config_value") + public String getConfigValue() { + return configValue; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.844+08:00", comments="Source field: config_map.config_value") + public void setConfigValue(String configValue) { + this.configValue = configValue; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.844+08:00", comments="Source field: config_map.creator") + public String getCreator() { + return creator; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.844+08:00", comments="Source field: config_map.creator") + public void setCreator(String creator) { + this.creator = creator; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.844+08:00", comments="Source field: config_map.create_at") + public Date getCreateAt() { + return createAt; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.844+08:00", comments="Source field: config_map.create_at") + public void setCreateAt(Date createAt) { + this.createAt = createAt; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.844+08:00", comments="Source field: config_map.modify_at") + public Date getModifyAt() { + return modifyAt; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.844+08:00", comments="Source field: config_map.modify_at") + public void setModifyAt(Date modifyAt) { + this.modifyAt = modifyAt; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.844+08:00", comments="Source field: config_map.modifier") + public String getModifier() { + return modifier; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.844+08:00", comments="Source field: config_map.modifier") + public void setModifier(String modifier) { + this.modifier = modifier; + } +} \ No newline at end of file diff --git a/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/domain/ShortLink.java b/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/domain/ShortLink.java new file mode 100644 index 00000000..ff4ec352 --- /dev/null +++ b/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/domain/ShortLink.java @@ -0,0 +1,45 @@ +package com.autohome.frostmourne.monitor.dao.mybatis.frostmourne.domain; + +import java.util.Date; +import javax.annotation.Generated; + +public class ShortLink { + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-09T18:30:03.198+08:00", comments="Source field: short_link.id") + private Long id; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-09T18:30:03.201+08:00", comments="Source field: short_link.long_link") + private String longLink; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-09T18:30:03.201+08:00", comments="Source field: short_link.create_at") + private Date createAt; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-09T18:30:03.2+08:00", comments="Source field: short_link.id") + public Long getId() { + return id; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-09T18:30:03.201+08:00", comments="Source field: short_link.id") + public void setId(Long id) { + this.id = id; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-09T18:30:03.201+08:00", comments="Source field: short_link.long_link") + public String getLongLink() { + return longLink; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-09T18:30:03.201+08:00", comments="Source field: short_link.long_link") + public void setLongLink(String longLink) { + this.longLink = longLink; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-09T18:30:03.201+08:00", comments="Source field: short_link.create_at") + public Date getCreateAt() { + return createAt; + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-09T18:30:03.201+08:00", comments="Source field: short_link.create_at") + public void setCreateAt(Date createAt) { + this.createAt = createAt; + } +} \ No newline at end of file diff --git a/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/mapper/dynamic/ConfigMapDynamicMapper.java b/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/mapper/dynamic/ConfigMapDynamicMapper.java new file mode 100644 index 00000000..bfe25cea --- /dev/null +++ b/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/mapper/dynamic/ConfigMapDynamicMapper.java @@ -0,0 +1,187 @@ +package com.autohome.frostmourne.monitor.dao.mybatis.frostmourne.mapper.dynamic; + +import static com.autohome.frostmourne.monitor.dao.mybatis.frostmourne.mapper.dynamic.ConfigMapDynamicSqlSupport.*; +import static org.mybatis.dynamic.sql.SqlBuilder.*; + +import com.autohome.frostmourne.monitor.dao.mybatis.frostmourne.domain.ConfigMap; +import java.util.List; +import java.util.Optional; +import javax.annotation.Generated; +import org.apache.ibatis.annotations.DeleteProvider; +import org.apache.ibatis.annotations.InsertProvider; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Result; +import org.apache.ibatis.annotations.ResultMap; +import org.apache.ibatis.annotations.Results; +import org.apache.ibatis.annotations.SelectKey; +import org.apache.ibatis.annotations.SelectProvider; +import org.apache.ibatis.annotations.UpdateProvider; +import org.apache.ibatis.type.JdbcType; +import org.mybatis.dynamic.sql.BasicColumn; +import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter; +import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider; +import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider; +import org.mybatis.dynamic.sql.select.CountDSLCompleter; +import org.mybatis.dynamic.sql.select.SelectDSLCompleter; +import org.mybatis.dynamic.sql.select.render.SelectStatementProvider; +import org.mybatis.dynamic.sql.update.UpdateDSL; +import org.mybatis.dynamic.sql.update.UpdateDSLCompleter; +import org.mybatis.dynamic.sql.update.UpdateModel; +import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider; +import org.mybatis.dynamic.sql.util.SqlProviderAdapter; +import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils; + +@Mapper +public interface ConfigMapDynamicMapper { + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.857+08:00", comments="Source Table: config_map") + BasicColumn[] selectList = BasicColumn.columnList(id, configKey, configValue, creator, createAt, modifyAt, modifier); + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.849+08:00", comments="Source Table: config_map") + @SelectProvider(type=SqlProviderAdapter.class, method="select") + long count(SelectStatementProvider selectStatement); + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.85+08:00", comments="Source Table: config_map") + @DeleteProvider(type=SqlProviderAdapter.class, method="delete") + int delete(DeleteStatementProvider deleteStatement); + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.851+08:00", comments="Source Table: config_map") + @InsertProvider(type=SqlProviderAdapter.class, method="insert") + @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="record.id", before=false, resultType=Long.class) + int insert(InsertStatementProvider insertStatement); + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.853+08:00", comments="Source Table: config_map") + @SelectProvider(type=SqlProviderAdapter.class, method="select") + @ResultMap("ConfigMapResult") + Optional selectOne(SelectStatementProvider selectStatement); + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.853+08:00", comments="Source Table: config_map") + @SelectProvider(type=SqlProviderAdapter.class, method="select") + @Results(id="ConfigMapResult", value = { + @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), + @Result(column="config_key", property="configKey", jdbcType=JdbcType.VARCHAR), + @Result(column="config_value", property="configValue", jdbcType=JdbcType.VARCHAR), + @Result(column="creator", property="creator", jdbcType=JdbcType.VARCHAR), + @Result(column="create_at", property="createAt", jdbcType=JdbcType.TIMESTAMP), + @Result(column="modify_at", property="modifyAt", jdbcType=JdbcType.TIMESTAMP), + @Result(column="modifier", property="modifier", jdbcType=JdbcType.VARCHAR) + }) + List selectMany(SelectStatementProvider selectStatement); + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.853+08:00", comments="Source Table: config_map") + @UpdateProvider(type=SqlProviderAdapter.class, method="update") + int update(UpdateStatementProvider updateStatement); + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.854+08:00", comments="Source Table: config_map") + default long count(CountDSLCompleter completer) { + return MyBatis3Utils.countFrom(this::count, configMap, completer); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.854+08:00", comments="Source Table: config_map") + default int delete(DeleteDSLCompleter completer) { + return MyBatis3Utils.deleteFrom(this::delete, configMap, completer); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.854+08:00", comments="Source Table: config_map") + default int deleteByPrimaryKey(Long id_) { + return delete(c -> + c.where(id, isEqualTo(id_)) + ); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.854+08:00", comments="Source Table: config_map") + default int insert(ConfigMap record) { + return MyBatis3Utils.insert(this::insert, record, configMap, c -> + c.map(configKey).toProperty("configKey") + .map(configValue).toProperty("configValue") + .map(creator).toProperty("creator") + .map(createAt).toProperty("createAt") + .map(modifyAt).toProperty("modifyAt") + .map(modifier).toProperty("modifier") + ); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.856+08:00", comments="Source Table: config_map") + default int insertSelective(ConfigMap record) { + return MyBatis3Utils.insert(this::insert, record, configMap, c -> + c.map(configKey).toPropertyWhenPresent("configKey", record::getConfigKey) + .map(configValue).toPropertyWhenPresent("configValue", record::getConfigValue) + .map(creator).toPropertyWhenPresent("creator", record::getCreator) + .map(createAt).toPropertyWhenPresent("createAt", record::getCreateAt) + .map(modifyAt).toPropertyWhenPresent("modifyAt", record::getModifyAt) + .map(modifier).toPropertyWhenPresent("modifier", record::getModifier) + ); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.858+08:00", comments="Source Table: config_map") + default Optional selectOne(SelectDSLCompleter completer) { + return MyBatis3Utils.selectOne(this::selectOne, selectList, configMap, completer); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.859+08:00", comments="Source Table: config_map") + default List select(SelectDSLCompleter completer) { + return MyBatis3Utils.selectList(this::selectMany, selectList, configMap, completer); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.859+08:00", comments="Source Table: config_map") + default List selectDistinct(SelectDSLCompleter completer) { + return MyBatis3Utils.selectDistinct(this::selectMany, selectList, configMap, completer); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.859+08:00", comments="Source Table: config_map") + default Optional selectByPrimaryKey(Long id_) { + return selectOne(c -> + c.where(id, isEqualTo(id_)) + ); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.86+08:00", comments="Source Table: config_map") + default int update(UpdateDSLCompleter completer) { + return MyBatis3Utils.update(this::update, configMap, completer); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.86+08:00", comments="Source Table: config_map") + static UpdateDSL updateAllColumns(ConfigMap record, UpdateDSL dsl) { + return dsl.set(configKey).equalTo(record::getConfigKey) + .set(configValue).equalTo(record::getConfigValue) + .set(creator).equalTo(record::getCreator) + .set(createAt).equalTo(record::getCreateAt) + .set(modifyAt).equalTo(record::getModifyAt) + .set(modifier).equalTo(record::getModifier); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.86+08:00", comments="Source Table: config_map") + static UpdateDSL updateSelectiveColumns(ConfigMap record, UpdateDSL dsl) { + return dsl.set(configKey).equalToWhenPresent(record::getConfigKey) + .set(configValue).equalToWhenPresent(record::getConfigValue) + .set(creator).equalToWhenPresent(record::getCreator) + .set(createAt).equalToWhenPresent(record::getCreateAt) + .set(modifyAt).equalToWhenPresent(record::getModifyAt) + .set(modifier).equalToWhenPresent(record::getModifier); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.861+08:00", comments="Source Table: config_map") + default int updateByPrimaryKey(ConfigMap record) { + return update(c -> + c.set(configKey).equalTo(record::getConfigKey) + .set(configValue).equalTo(record::getConfigValue) + .set(creator).equalTo(record::getCreator) + .set(createAt).equalTo(record::getCreateAt) + .set(modifyAt).equalTo(record::getModifyAt) + .set(modifier).equalTo(record::getModifier) + .where(id, isEqualTo(record::getId)) + ); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.862+08:00", comments="Source Table: config_map") + default int updateByPrimaryKeySelective(ConfigMap record) { + return update(c -> + c.set(configKey).equalToWhenPresent(record::getConfigKey) + .set(configValue).equalToWhenPresent(record::getConfigValue) + .set(creator).equalToWhenPresent(record::getCreator) + .set(createAt).equalToWhenPresent(record::getCreateAt) + .set(modifyAt).equalToWhenPresent(record::getModifyAt) + .set(modifier).equalToWhenPresent(record::getModifier) + .where(id, isEqualTo(record::getId)) + ); + } +} \ No newline at end of file diff --git a/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/mapper/dynamic/ConfigMapDynamicSqlSupport.java b/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/mapper/dynamic/ConfigMapDynamicSqlSupport.java new file mode 100644 index 00000000..6d8b6065 --- /dev/null +++ b/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/mapper/dynamic/ConfigMapDynamicSqlSupport.java @@ -0,0 +1,54 @@ +package com.autohome.frostmourne.monitor.dao.mybatis.frostmourne.mapper.dynamic; + +import java.sql.JDBCType; +import java.util.Date; +import javax.annotation.Generated; +import org.mybatis.dynamic.sql.SqlColumn; +import org.mybatis.dynamic.sql.SqlTable; + +public final class ConfigMapDynamicSqlSupport { + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.847+08:00", comments="Source Table: config_map") + public static final ConfigMap configMap = new ConfigMap(); + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.848+08:00", comments="Source field: config_map.id") + public static final SqlColumn id = configMap.id; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.848+08:00", comments="Source field: config_map.config_key") + public static final SqlColumn configKey = configMap.configKey; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.848+08:00", comments="Source field: config_map.config_value") + public static final SqlColumn configValue = configMap.configValue; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.848+08:00", comments="Source field: config_map.creator") + public static final SqlColumn creator = configMap.creator; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.848+08:00", comments="Source field: config_map.create_at") + public static final SqlColumn createAt = configMap.createAt; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.848+08:00", comments="Source field: config_map.modify_at") + public static final SqlColumn modifyAt = configMap.modifyAt; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.848+08:00", comments="Source field: config_map.modifier") + public static final SqlColumn modifier = configMap.modifier; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-10T11:15:14.847+08:00", comments="Source Table: config_map") + public static final class ConfigMap extends SqlTable { + public final SqlColumn id = column("id", JDBCType.BIGINT); + + public final SqlColumn configKey = column("config_key", JDBCType.VARCHAR); + + public final SqlColumn configValue = column("config_value", JDBCType.VARCHAR); + + public final SqlColumn creator = column("creator", JDBCType.VARCHAR); + + public final SqlColumn createAt = column("create_at", JDBCType.TIMESTAMP); + + public final SqlColumn modifyAt = column("modify_at", JDBCType.TIMESTAMP); + + public final SqlColumn modifier = column("modifier", JDBCType.VARCHAR); + + public ConfigMap() { + super("config_map"); + } + } +} \ No newline at end of file diff --git a/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/mapper/dynamic/ShortLinkDynamicMapper.java b/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/mapper/dynamic/ShortLinkDynamicMapper.java new file mode 100644 index 00000000..0cc21f4a --- /dev/null +++ b/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/mapper/dynamic/ShortLinkDynamicMapper.java @@ -0,0 +1,159 @@ +package com.autohome.frostmourne.monitor.dao.mybatis.frostmourne.mapper.dynamic; + +import static com.autohome.frostmourne.monitor.dao.mybatis.frostmourne.mapper.dynamic.ShortLinkDynamicSqlSupport.*; +import static org.mybatis.dynamic.sql.SqlBuilder.*; + +import com.autohome.frostmourne.monitor.dao.mybatis.frostmourne.domain.ShortLink; +import java.util.List; +import java.util.Optional; +import javax.annotation.Generated; +import org.apache.ibatis.annotations.DeleteProvider; +import org.apache.ibatis.annotations.InsertProvider; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Result; +import org.apache.ibatis.annotations.ResultMap; +import org.apache.ibatis.annotations.Results; +import org.apache.ibatis.annotations.SelectKey; +import org.apache.ibatis.annotations.SelectProvider; +import org.apache.ibatis.annotations.UpdateProvider; +import org.apache.ibatis.type.JdbcType; +import org.mybatis.dynamic.sql.BasicColumn; +import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter; +import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider; +import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider; +import org.mybatis.dynamic.sql.select.CountDSLCompleter; +import org.mybatis.dynamic.sql.select.SelectDSLCompleter; +import org.mybatis.dynamic.sql.select.render.SelectStatementProvider; +import org.mybatis.dynamic.sql.update.UpdateDSL; +import org.mybatis.dynamic.sql.update.UpdateDSLCompleter; +import org.mybatis.dynamic.sql.update.UpdateModel; +import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider; +import org.mybatis.dynamic.sql.util.SqlProviderAdapter; +import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils; + +@Mapper +public interface ShortLinkDynamicMapper { + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-09T18:30:03.214+08:00", comments="Source Table: short_link") + BasicColumn[] selectList = BasicColumn.columnList(id, longLink, createAt); + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-09T18:30:03.205+08:00", comments="Source Table: short_link") + @SelectProvider(type=SqlProviderAdapter.class, method="select") + long count(SelectStatementProvider selectStatement); + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-09T18:30:03.206+08:00", comments="Source Table: short_link") + @DeleteProvider(type=SqlProviderAdapter.class, method="delete") + int delete(DeleteStatementProvider deleteStatement); + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-09T18:30:03.207+08:00", comments="Source Table: short_link") + @InsertProvider(type=SqlProviderAdapter.class, method="insert") + @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="record.id", before=false, resultType=Long.class) + int insert(InsertStatementProvider insertStatement); + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-09T18:30:03.21+08:00", comments="Source Table: short_link") + @SelectProvider(type=SqlProviderAdapter.class, method="select") + @ResultMap("ShortLinkResult") + Optional selectOne(SelectStatementProvider selectStatement); + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-09T18:30:03.21+08:00", comments="Source Table: short_link") + @SelectProvider(type=SqlProviderAdapter.class, method="select") + @Results(id="ShortLinkResult", value = { + @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), + @Result(column="long_link", property="longLink", jdbcType=JdbcType.VARCHAR), + @Result(column="create_at", property="createAt", jdbcType=JdbcType.TIMESTAMP) + }) + List selectMany(SelectStatementProvider selectStatement); + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-09T18:30:03.211+08:00", comments="Source Table: short_link") + @UpdateProvider(type=SqlProviderAdapter.class, method="update") + int update(UpdateStatementProvider updateStatement); + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-09T18:30:03.211+08:00", comments="Source Table: short_link") + default long count(CountDSLCompleter completer) { + return MyBatis3Utils.countFrom(this::count, shortLink, completer); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-09T18:30:03.211+08:00", comments="Source Table: short_link") + default int delete(DeleteDSLCompleter completer) { + return MyBatis3Utils.deleteFrom(this::delete, shortLink, completer); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-09T18:30:03.212+08:00", comments="Source Table: short_link") + default int deleteByPrimaryKey(Long id_) { + return delete(c -> + c.where(id, isEqualTo(id_)) + ); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-09T18:30:03.212+08:00", comments="Source Table: short_link") + default int insert(ShortLink record) { + return MyBatis3Utils.insert(this::insert, record, shortLink, c -> + c.map(longLink).toProperty("longLink") + .map(createAt).toProperty("createAt") + ); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-09T18:30:03.213+08:00", comments="Source Table: short_link") + default int insertSelective(ShortLink record) { + return MyBatis3Utils.insert(this::insert, record, shortLink, c -> + c.map(longLink).toPropertyWhenPresent("longLink", record::getLongLink) + .map(createAt).toPropertyWhenPresent("createAt", record::getCreateAt) + ); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-09T18:30:03.215+08:00", comments="Source Table: short_link") + default Optional selectOne(SelectDSLCompleter completer) { + return MyBatis3Utils.selectOne(this::selectOne, selectList, shortLink, completer); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-09T18:30:03.215+08:00", comments="Source Table: short_link") + default List select(SelectDSLCompleter completer) { + return MyBatis3Utils.selectList(this::selectMany, selectList, shortLink, completer); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-09T18:30:03.216+08:00", comments="Source Table: short_link") + default List selectDistinct(SelectDSLCompleter completer) { + return MyBatis3Utils.selectDistinct(this::selectMany, selectList, shortLink, completer); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-09T18:30:03.216+08:00", comments="Source Table: short_link") + default Optional selectByPrimaryKey(Long id_) { + return selectOne(c -> + c.where(id, isEqualTo(id_)) + ); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-09T18:30:03.216+08:00", comments="Source Table: short_link") + default int update(UpdateDSLCompleter completer) { + return MyBatis3Utils.update(this::update, shortLink, completer); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-09T18:30:03.217+08:00", comments="Source Table: short_link") + static UpdateDSL updateAllColumns(ShortLink record, UpdateDSL dsl) { + return dsl.set(longLink).equalTo(record::getLongLink) + .set(createAt).equalTo(record::getCreateAt); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-09T18:30:03.217+08:00", comments="Source Table: short_link") + static UpdateDSL updateSelectiveColumns(ShortLink record, UpdateDSL dsl) { + return dsl.set(longLink).equalToWhenPresent(record::getLongLink) + .set(createAt).equalToWhenPresent(record::getCreateAt); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-09T18:30:03.218+08:00", comments="Source Table: short_link") + default int updateByPrimaryKey(ShortLink record) { + return update(c -> + c.set(longLink).equalTo(record::getLongLink) + .set(createAt).equalTo(record::getCreateAt) + .where(id, isEqualTo(record::getId)) + ); + } + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-09T18:30:03.219+08:00", comments="Source Table: short_link") + default int updateByPrimaryKeySelective(ShortLink record) { + return update(c -> + c.set(longLink).equalToWhenPresent(record::getLongLink) + .set(createAt).equalToWhenPresent(record::getCreateAt) + .where(id, isEqualTo(record::getId)) + ); + } +} \ No newline at end of file diff --git a/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/mapper/dynamic/ShortLinkDynamicSqlSupport.java b/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/mapper/dynamic/ShortLinkDynamicSqlSupport.java new file mode 100644 index 00000000..81c2dcd7 --- /dev/null +++ b/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/mapper/dynamic/ShortLinkDynamicSqlSupport.java @@ -0,0 +1,34 @@ +package com.autohome.frostmourne.monitor.dao.mybatis.frostmourne.mapper.dynamic; + +import java.sql.JDBCType; +import java.util.Date; +import javax.annotation.Generated; +import org.mybatis.dynamic.sql.SqlColumn; +import org.mybatis.dynamic.sql.SqlTable; + +public final class ShortLinkDynamicSqlSupport { + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-09T18:30:03.204+08:00", comments="Source Table: short_link") + public static final ShortLink shortLink = new ShortLink(); + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-09T18:30:03.204+08:00", comments="Source field: short_link.id") + public static final SqlColumn id = shortLink.id; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-09T18:30:03.205+08:00", comments="Source field: short_link.long_link") + public static final SqlColumn longLink = shortLink.longLink; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-09T18:30:03.205+08:00", comments="Source field: short_link.create_at") + public static final SqlColumn createAt = shortLink.createAt; + + @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2022-03-09T18:30:03.204+08:00", comments="Source Table: short_link") + public static final class ShortLink extends SqlTable { + public final SqlColumn id = column("id", JDBCType.BIGINT); + + public final SqlColumn longLink = column("long_link", JDBCType.VARCHAR); + + public final SqlColumn createAt = column("create_at", JDBCType.TIMESTAMP); + + public ShortLink() { + super("short_link"); + } + } +} \ No newline at end of file diff --git a/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/repository/IConfigMapRepository.java b/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/repository/IConfigMapRepository.java new file mode 100644 index 00000000..2de51d58 --- /dev/null +++ b/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/repository/IConfigMapRepository.java @@ -0,0 +1,10 @@ +package com.autohome.frostmourne.monitor.dao.mybatis.frostmourne.repository; + +import java.util.Optional; + +import com.autohome.frostmourne.monitor.dao.mybatis.frostmourne.domain.ConfigMap; + +public interface IConfigMapRepository { + + Optional find(String configKey); +} diff --git a/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/repository/IShortLinkRepository.java b/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/repository/IShortLinkRepository.java new file mode 100644 index 00000000..1e6b6ad7 --- /dev/null +++ b/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/repository/IShortLinkRepository.java @@ -0,0 +1,12 @@ +package com.autohome.frostmourne.monitor.dao.mybatis.frostmourne.repository; + +import java.util.Optional; + +import com.autohome.frostmourne.monitor.dao.mybatis.frostmourne.domain.ShortLink; + +public interface IShortLinkRepository { + + Optional selectByPrimaryKey(Long id); + + Long save(ShortLink shortLink); +} diff --git a/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/repository/impl/ConfigMapRepository.java b/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/repository/impl/ConfigMapRepository.java new file mode 100644 index 00000000..b46c40e1 --- /dev/null +++ b/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/repository/impl/ConfigMapRepository.java @@ -0,0 +1,25 @@ +package com.autohome.frostmourne.monitor.dao.mybatis.frostmourne.repository.impl; + +import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo; + +import java.util.Optional; +import javax.annotation.Resource; + +import com.autohome.frostmourne.monitor.dao.mybatis.frostmourne.domain.ConfigMap; +import com.autohome.frostmourne.monitor.dao.mybatis.frostmourne.mapper.dynamic.ConfigMapDynamicMapper; +import com.autohome.frostmourne.monitor.dao.mybatis.frostmourne.mapper.dynamic.ConfigMapDynamicSqlSupport; +import com.autohome.frostmourne.monitor.dao.mybatis.frostmourne.repository.IConfigMapRepository; +import org.springframework.stereotype.Repository; + +@Repository +public class ConfigMapRepository implements IConfigMapRepository { + + @Resource + private ConfigMapDynamicMapper configMapDynamicMapper; + + @Override + public Optional find(String configKey) { + Optional configMapOptional = configMapDynamicMapper.selectOne(query -> query.where().and(ConfigMapDynamicSqlSupport.configKey, isEqualTo(configKey))); + return configMapOptional; + } +} diff --git a/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/repository/impl/ShortLinkRepository.java b/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/repository/impl/ShortLinkRepository.java new file mode 100644 index 00000000..56199949 --- /dev/null +++ b/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/dao/mybatis/frostmourne/repository/impl/ShortLinkRepository.java @@ -0,0 +1,27 @@ +package com.autohome.frostmourne.monitor.dao.mybatis.frostmourne.repository.impl; + +import java.util.Optional; +import javax.annotation.Resource; + +import com.autohome.frostmourne.monitor.dao.mybatis.frostmourne.domain.ShortLink; +import com.autohome.frostmourne.monitor.dao.mybatis.frostmourne.mapper.dynamic.ShortLinkDynamicMapper; +import com.autohome.frostmourne.monitor.dao.mybatis.frostmourne.repository.IShortLinkRepository; +import org.springframework.stereotype.Repository; + +@Repository +public class ShortLinkRepository implements IShortLinkRepository { + + @Resource + private ShortLinkDynamicMapper shortLinkDynamicMapper; + + @Override + public Optional selectByPrimaryKey(Long id) { + return shortLinkDynamicMapper.selectByPrimaryKey(id); + } + + @Override + public Long save(ShortLink shortLink) { + shortLinkDynamicMapper.insert(shortLink); + return shortLink.getId(); + } +} diff --git a/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/service/core/alert/AlertService.java b/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/service/core/alert/AlertService.java index 06d65155..7f6b8883 100644 --- a/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/service/core/alert/AlertService.java +++ b/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/service/core/alert/AlertService.java @@ -17,9 +17,12 @@ import com.autohome.frostmourne.monitor.contract.enums.VerifyResult; import com.autohome.frostmourne.monitor.dao.mybatis.frostmourne.domain.AlarmLog; import com.autohome.frostmourne.monitor.dao.mybatis.frostmourne.domain.AlertLog; +import com.autohome.frostmourne.monitor.dao.mybatis.frostmourne.domain.ConfigMap; import com.autohome.frostmourne.monitor.dao.mybatis.frostmourne.repository.IAlarmLogRepository; import com.autohome.frostmourne.monitor.dao.mybatis.frostmourne.repository.IAlertLogRepository; +import com.autohome.frostmourne.monitor.dao.mybatis.frostmourne.repository.IConfigMapRepository; import com.autohome.frostmourne.monitor.service.account.IAccountService; +import com.autohome.frostmourne.monitor.service.core.domain.ConfigMapKeys; import com.autohome.frostmourne.monitor.service.core.execute.AlarmProcessLogger; import com.autohome.frostmourne.spi.starter.api.IFrostmourneSpiApi; import com.autohome.frostmourne.spi.starter.model.AccountInfo; @@ -51,6 +54,9 @@ public class AlertService implements IAlertService { @Resource private IAlarmLogRepository alarmLogRepository; + @Resource + private IConfigMapRepository configMapRepository; + public void alert(AlarmProcessLogger alarmProcessLogger) { AlertContract alertContract = alarmProcessLogger.getAlarmContract().getAlertContract(); List recipients = recipients(alertContract.getRecipients(), alarmProcessLogger.getAlarmContract().getServiceInfo()); @@ -74,7 +80,7 @@ private void sendAlert(AlarmProcessLogger alarmProcessLogger, List AlarmMessage alarmMessage = new AlarmMessage(); String alertContent = null; if (alertType.equalsIgnoreCase(AlertType.PROBLEM)) { - alarmMessage.setContent(String.format("消息类型: [问题] %s分钟内持续报警将不重复发送\n%s", + alarmMessage.setContent(String.format("消息类型: [问题] %s分钟内连续报警将不重复发送\n%s", alertContract.getSilence(), alarmProcessLogger.getAlertMessage())); alertContent = alarmProcessLogger.getAlertMessage(); } else if (alertType.equalsIgnoreCase(AlertType.RECOVER)) { @@ -82,7 +88,7 @@ private void sendAlert(AlarmProcessLogger alarmProcessLogger, List alertContent = "消息类型: [恢复] 请自己检查问题是否解决,上次报警内容如下\n" + alertLog.getContent(); alarmMessage.setContent(alertContent); } - alarmMessage.setTitle(String.format("[%s][id:%s]%s", Strings.isNullOrEmpty(messageTitle) ? "霜之哀伤监控平台" : messageTitle, alarmProcessLogger.getAlarmContract().getId(), alarmProcessLogger.getAlarmContract().getAlarmName())); + alarmMessage.setTitle(String.format("[%s][id:%s]%s", Strings.isNullOrEmpty(messageTitle) ? alertTitle() : messageTitle, alarmProcessLogger.getAlarmContract().getId(), alarmProcessLogger.getAlarmContract().getAlarmName())); alarmMessage.setRecipients(recipients); alarmMessage.setWays(alertContract.getWays()); alarmMessage.setDingHook(alertContract.getDingRobotHook()); @@ -216,4 +222,12 @@ public void alarmLog(AlarmProcessLogger alarmProcessLogger) { alarmLogRepository.insert(alarmLog); alarmProcessLogger.setAlarmLog(alarmLog); } + + private String alertTitle() { + Optional configMapOptional = configMapRepository.find(ConfigMapKeys.ALERT_TITLE); + if (configMapOptional.isPresent()) { + return configMapOptional.get().getConfigValue(); + } + return "霜之哀伤监控平台"; + } } diff --git a/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/service/core/domain/ConfigMapKeys.java b/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/service/core/domain/ConfigMapKeys.java new file mode 100644 index 00000000..8ec199b1 --- /dev/null +++ b/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/service/core/domain/ConfigMapKeys.java @@ -0,0 +1,6 @@ +package com.autohome.frostmourne.monitor.service.core.domain; + +public class ConfigMapKeys { + + public final static String ALERT_TITLE = "AlertTitle"; +} diff --git a/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/service/core/execute/AlarmService.java b/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/service/core/execute/AlarmService.java index c0c75e22..144c5cf3 100644 --- a/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/service/core/execute/AlarmService.java +++ b/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/service/core/execute/AlarmService.java @@ -60,7 +60,7 @@ public AlarmProcessLogger run(AlarmContract alarmContract, boolean test) { alertService.alert(alarmProcessLogger); } } else { - if(alarmProcessLogger.getAlert()) { + if(alarmProcessLogger.getAlert() != null && alarmProcessLogger.getAlert()) { alarmProcessLogger.trace("test alarm, not send"); } } diff --git a/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/service/core/execute/GenerateShortLinkService.java b/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/service/core/execute/GenerateShortLinkService.java index 7e05dd12..9e1eb5d6 100644 --- a/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/service/core/execute/GenerateShortLinkService.java +++ b/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/service/core/execute/GenerateShortLinkService.java @@ -3,13 +3,12 @@ import java.net.URLEncoder; import java.util.ArrayList; import java.util.List; +import java.util.Map; import javax.annotation.Resource; -import com.autohome.frostmourne.core.contract.Protocol; -import com.autohome.frostmourne.core.jackson.JacksonUtil; import com.autohome.frostmourne.monitor.contract.AlarmContract; import com.autohome.frostmourne.monitor.contract.enums.DataSourceType; -import com.autohome.frostmourne.spi.starter.api.IFrostmourneSpiApi; +import com.autohome.frostmourne.monitor.service.core.service.IShortLinkService; import com.google.common.base.Strings; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -22,7 +21,7 @@ public class GenerateShortLinkService implements IGenerateShortLinkService { private static final Logger LOGGER = LoggerFactory.getLogger(GenerateShortLinkService.class); @Resource - private IFrostmourneSpiApi frostmourneSpiApi; + private IShortLinkService shortLinkService; @Value("${frostmourne.monitor.address}") private String frostmourneMonitorAddress; @@ -37,6 +36,15 @@ public String generate(AlarmProcessLogger alarmProcessLogger) { if (datasourceType.equalsIgnoreCase("influxdb")) { return null; } + + if (datasourceType.equalsIgnoreCase("elasticsearch")) { + Map metricProperties = alarmContract.getMetricContract().getProperties(); + if (metricProperties != null && metricProperties.containsKey("dataLink") && metricProperties.get("dataLink") != null + && !Strings.isNullOrEmpty(metricProperties.get("dataLink").toString())) { + return metricProperties.get("dataLink").toString(); + } + } + String url = null; List queryParameters = new ArrayList<>(); try { @@ -48,14 +56,7 @@ public String generate(AlarmProcessLogger alarmProcessLogger) { queryParameters.add("dataName=" + URLEncoder.encode(alarmContract.getMetricContract().getDataNameContract().getDataName(), "utf8")); } String longUrl = url + "?" + String.join("&", queryParameters); - Protocol protocol = frostmourneSpiApi.shortenLink("frostmourne-monitor", URLEncoder.encode(longUrl, "utf8")); - if (protocol.getReturncode() == 0 && !Strings.isNullOrEmpty(protocol.getResult())) { - return protocol.getResult(); - } - if (protocol.getReturncode() != 0) { - LOGGER.warn("error when generate short link. response: " + JacksonUtil.serialize(protocol)); - } - return longUrl; + return shortLinkService.shorten(longUrl); } catch (Exception ex) { LOGGER.error("error when generate short link", ex); return null; diff --git a/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/service/core/service/IShortLinkService.java b/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/service/core/service/IShortLinkService.java new file mode 100644 index 00000000..8c958077 --- /dev/null +++ b/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/service/core/service/IShortLinkService.java @@ -0,0 +1,6 @@ +package com.autohome.frostmourne.monitor.service.core.service; + +public interface IShortLinkService { + + String shorten(String longUrl); +} diff --git a/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/service/core/service/ServiceInfoService.java b/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/service/core/service/impl/ServiceInfoService.java similarity index 95% rename from frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/service/core/service/ServiceInfoService.java rename to frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/service/core/service/impl/ServiceInfoService.java index 85a88e1e..35500a47 100644 --- a/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/service/core/service/ServiceInfoService.java +++ b/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/service/core/service/impl/ServiceInfoService.java @@ -1,4 +1,4 @@ -package com.autohome.frostmourne.monitor.service.core.service; +package com.autohome.frostmourne.monitor.service.core.service.impl; import java.util.Collections; import java.util.List; @@ -14,6 +14,7 @@ import com.autohome.frostmourne.monitor.contract.ServiceInfoSimpleContract; import com.autohome.frostmourne.monitor.dao.mybatis.frostmourne.domain.ServiceInfo; import com.autohome.frostmourne.monitor.dao.mybatis.frostmourne.repository.IServiceInfoRepository; +import com.autohome.frostmourne.monitor.service.core.service.IServiceInfoService; import com.autohome.frostmourne.monitor.transform.ServiceInfoTransformer; import com.github.pagehelper.PageInfo; import org.springframework.stereotype.Service; diff --git a/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/service/core/service/impl/ShortLinkService.java b/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/service/core/service/impl/ShortLinkService.java new file mode 100644 index 00000000..2eda2803 --- /dev/null +++ b/frostmourne-monitor/src/main/java/com/autohome/frostmourne/monitor/service/core/service/impl/ShortLinkService.java @@ -0,0 +1,29 @@ +package com.autohome.frostmourne.monitor.service.core.service.impl; + +import java.util.Date; +import javax.annotation.Resource; + +import com.autohome.frostmourne.monitor.dao.mybatis.frostmourne.domain.ShortLink; +import com.autohome.frostmourne.monitor.dao.mybatis.frostmourne.repository.IShortLinkRepository; +import com.autohome.frostmourne.monitor.service.core.service.IShortLinkService; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +@Service +public class ShortLinkService implements IShortLinkService { + + @Resource + private IShortLinkRepository shortLinkRepository; + + @Value("${frostmourne.monitor.address}") + private String frostmourneMonitorAddress; + + @Override + public String shorten(String longUrl) { + ShortLink shortLink = new ShortLink(); + shortLink.setLongLink(longUrl); + shortLink.setCreateAt(new Date()); + Long linkId = shortLinkRepository.save(shortLink); + return String.format("%s/goto/%s", frostmourneMonitorAddress, linkId); + } +} diff --git a/frostmourne-monitor/src/main/resources/generatorConfig.xml b/frostmourne-monitor/src/main/resources/generatorConfig.xml index 1cb08413..ead37a36 100644 --- a/frostmourne-monitor/src/main/resources/generatorConfig.xml +++ b/frostmourne-monitor/src/main/resources/generatorConfig.xml @@ -77,8 +77,17 @@ -
--> - +
+ + + +
+ + + +
+ --> +
diff --git a/frostmourne-spi-starter/src/main/java/com/autohome/frostmourne/spi/starter/api/IFrostmourneSpiApi.java b/frostmourne-spi-starter/src/main/java/com/autohome/frostmourne/spi/starter/api/IFrostmourneSpiApi.java index 2c74c496..6e57ef8c 100644 --- a/frostmourne-spi-starter/src/main/java/com/autohome/frostmourne/spi/starter/api/IFrostmourneSpiApi.java +++ b/frostmourne-spi-starter/src/main/java/com/autohome/frostmourne/spi/starter/api/IFrostmourneSpiApi.java @@ -16,8 +16,4 @@ public interface IFrostmourneSpiApi { @RequestLine("POST /message/send?_appId={_appId}") @Headers("Content-Type: application/json") Protocol> send(AlarmMessage alarmMessage, @Param("_appId") String _appId); - - @RequestLine("GET /shorten/link?_appId={_appId}&longUrl={longUrl}") - @Headers("Content-Type: application/json") - Protocol shortenLink(@Param("_appId") String _appId, @Param("longUrl") String longUrl); } diff --git a/frostmourne-spi-starter/src/main/java/com/autohome/frostmourne/spi/starter/mock/MockFrostmourneSpi.java b/frostmourne-spi-starter/src/main/java/com/autohome/frostmourne/spi/starter/mock/MockFrostmourneSpi.java index 143bccd8..ff718ab0 100644 --- a/frostmourne-spi-starter/src/main/java/com/autohome/frostmourne/spi/starter/mock/MockFrostmourneSpi.java +++ b/frostmourne-spi-starter/src/main/java/com/autohome/frostmourne/spi/starter/mock/MockFrostmourneSpi.java @@ -21,9 +21,4 @@ public Protocol> send(AlarmMessage alarmMessage, String _app } return new Protocol<>(messageResults); } - - @Override - public Protocol shortenLink(String _appId, String longUrl) { - return new Protocol<>(""); - } } diff --git a/frostmourne-vue/src/views/alarm/edit.vue b/frostmourne-vue/src/views/alarm/edit.vue index 23defcaa..91fd4111 100644 --- a/frostmourne-vue/src/views/alarm/edit.vue +++ b/frostmourne-vue/src/views/alarm/edit.vue @@ -192,6 +192,9 @@ + + + 预览数据 diff --git a/pom.xml b/pom.xml index 20572aae..957d5f87 100644 --- a/pom.xml +++ b/pom.xml @@ -95,4 +95,18 @@ + + + + spring + https://maven.aliyun.com/repository/spring + + true + + + true + + + +