Skip to content

Commit

Permalink
[refactor] [alert] alter instance && support sms(web) (DataLinkDC#1999)
Browse files Browse the repository at this point in the history
* refactor alert instance && support sms(web)

* fix some bug

* format code

* fix some bug

* fix some bug

* fix some bug

* USE enum support switch

* added sms config

* added sms config
  • Loading branch information
Zzm0809 authored Jun 1, 2023
1 parent 4eec3d5 commit a473767
Show file tree
Hide file tree
Showing 41 changed files with 2,474 additions and 1,539 deletions.
1 change: 1 addition & 0 deletions dinky-admin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>${scope.runtime}</scope>
</dependency>
<!-- postgresql -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,14 @@ private static AlertMsg getAlertMsg(AlertInstance alertInstance) {
String exceptionUrl = "http://cdh1:8081/#/job/" + uuid + "/exceptions";

Map<String, String> map = JSONUtil.toMap(alertInstance.getParams());
if (map.get("msgtype").equals(ShowType.MARKDOWN.getValue())) {
alertMsgBuilder.linkUrl("[跳转至该任务的 FlinkWeb](" + linkUrl + ")");
alertMsgBuilder.exceptionUrl("[点击查看该任务的异常日志](" + exceptionUrl + ")");
if (!alertInstance.getType().equals("Sms")) {
if (map.get("msgtype").equals(ShowType.MARKDOWN.getValue())) {
alertMsgBuilder.linkUrl("[跳转至该任务的 FlinkWeb](" + linkUrl + ")");
alertMsgBuilder.exceptionUrl("[点击查看该任务的异常日志](" + exceptionUrl + ")");
} else {
alertMsgBuilder.linkUrl(linkUrl);
alertMsgBuilder.exceptionUrl(exceptionUrl);
}
} else {
alertMsgBuilder.linkUrl(linkUrl);
alertMsgBuilder.exceptionUrl(exceptionUrl);
Expand Down
188 changes: 120 additions & 68 deletions dinky-admin/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,120 +1,172 @@
#################################################################################################################
################################################# Common Config #################################################
#################################################################################################################
# Dinky application port
server:
port: 8888

spring:
datasource:
url: jdbc:mysql://${MYSQL_ADDR:127.0.0.1:3306}/${MYSQL_DATABASE:dinky}?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
username: ${MYSQL_USERNAME:dinky}
password: ${MYSQL_PASSWORD:dinky}
driver-class-name: com.mysql.cj.jdbc.Driver
# Dinky application name
application:
name: dinky
name: Dinky
profiles:
# The h2 database is used by default. If you need to use other databases, please set the configuration active to: mysql, currently supports [mysql, pgsql, h2]
# If you use mysql database, please configure mysql database connection information in application-mysql.yml
# If you use pgsql database, please configure pgsql database connection information in application-pgsql.yml
# If you use the h2 database, please configure the h2 database connection information in application-h2.yml,
# note: the h2 database is only for experience use, and the related data that has been created cannot be migrated, please use it with caution
active: h2 #[h2,mysql,pgsql]

# mvc config
mvc:
pathmatch:
# Path matching strategy, default ant_path_matcher, support ant_path_matcher and path_pattern_parser
matching-strategy: ant_path_matcher
format:
date: yyyy-MM-dd HH:mm:ss
#json格式化全局配置
date: yyyy-MM-dd HH:mm:ss # date format
time: HH:mm:ss # time format
date-time: yyyy-MM-dd HH:mm:ss # date-time format

# json format global configuration
jackson:
time-zone: GMT+8
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8 # Time zone, default is GMT+8
date-format: yyyy-MM-dd HH:mm:ss # Date format, the default is yyyy-MM-dd HH:mm:ss

# circular references allowed
main:
allow-circular-references: true

# 默认使用内存缓存元数据信息,
# dinky支持redis缓存,如有需要请把simple改为redis,并打开下面的redis连接配置
# 子配置项可以按需要打开或自定义配置
cache:
type: simple
## 如果type配置为redis,则该项可按需配置
# redis:
## 是否缓存空值,保存默认即可
# cache-null-values: false
## 缓存过期时间,24小时
# time-to-live: 86400


# flyway:
# enabled: false
# clean-disabled: true
## baseline-on-migrate: true
# table: dinky_schema_history
# Redis配置
#sa-token如需依赖redis,请打开redis配置和pom.xml、dinky-admin/pom.xml中依赖
# redis:
# host: localhost
# port: 6379
# password:
# database: 10
# jedis:
# pool:
# # 连接池最大连接数(使用负值表示没有限制)
# max-active: 50
# # 连接池最大阻塞等待时间(使用负值表示没有限制)
# max-wait: 3000
# # 连接池中的最大空闲连接数
# max-idle: 20
# # 连接池中的最小空闲连接数
# min-idle: 5
# # 连接超时时间(毫秒)
# timeout: 5000
# file upload config of servlet , the default is 500MB
servlet:
multipart:
enabled: true
max-file-size: 524288000
max-request-size: 524288000
enabled: true
profiles.active: h2 #[h2,mysql,pgsql]
server:
port: 8888


# By default, memory cache metadata information is used,
# dinky supports redis cache, if necessary, please change simple to redis, and open the following redis connection configuration
# Sub-configuration items can be opened or customized as needed
cache:
type: simple
# If type is configured as redis, this item can be configured as needed, note: Pay attention to the indentation of this configuration item
# redis:
# # Whether to cache empty values, save the default
# cache-null-values: false
# # Cache expiration time, default 24 hours
# time-to-live: 86400

########################################################## Redis配置 ##########################################################
# If sa-token needs to rely on redis, please open the redis configuration and depend on pom.xml and dinky-admin/pom.xml, and configure redis connection information in application.yml
# note: pay attention to the indentation of this configuration item
# redis:
# host: localhost
# port: 6379
# password:
# database: 10
# jedis:
# pool:
# # The maximum number of connections in the connection pool (use a negative value to indicate no limit)
# max-active: 50
# # The maximum blocking waiting time of the connection pool (use a negative value to indicate no limit)
# max-wait: 3000
# # The maximum number of idle connections in the connection pool
# max-idle: 20
# # The minimum number of idle connections in the connection pool
# min-idle: 5
# # Connection timeout (milliseconds)
# timeout: 5000

#################################################################################################################
################################################# Mybatis Config ################################################
######### Please note: that the following configurations are not recommended to be modified #####################
#################################################################################################################
mybatis-plus:
mapper-locations: classpath:/mapper/*Mapper.xml
#实体扫描,多个package用逗号或者分号分隔
# Entity scanning, multiple packages are separated by commas or semicolons
typeAliasesPackage: org.dinky.model
global-config:
db-config:
id-type: auto
#逻辑删除配置
# Logic delete configuration : 0: false(Not deleted), 1: true(deleted)
logic-delete-field: is_delete
logic-delete-value: 1
logic-not-delete-value: 0
banner: false
configuration:
##### mybatis-plus打印完整sql(只适用于开发环境)
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
##### mybatis-plus prints complete sql (only for development environment)
#log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
log-impl: org.apache.ibatis.logging.nologging.NoLoggingImpl

# Sa-Token 配置
#################################################################################################################
################################################# SMS Config ####################################################
#################################################################################################################
#sms:
# # Whether to enable SMS
# config-type: sql_config
# is-print: false
# sql:
# # The database connection information
# url: ${spring.datasource.url}
# username: ${spring.datasource.username}
# password: ${spring.datasource.password}
# driver-class-name: ${spring.datasource.driver-class-name}
# table-name: dinky_alert_instance
# supplier-field-name: manufacturers
# config-name: params
# start-name: enabled
# is-start: 1



#################################################################################################################
################################################# Sa-Token Config ###############################################
#################################################################################################################
# Sa-Token basic configuration
sa-token:
# token名称 (同时也是cookie名称)
# token name (also cookie name)
token-name: satoken
# token有效期,单位s 默认10小时, -1代表永不过期
# The validity period of the token, the unit is 10 hours by default, -1 means it will never expire
timeout: 36000
# token临时有效期 (指定时间内无操作就视为token过期) 单位: 秒
# The temporary validity period of the token (the token will be considered as expired if there is no operation within the specified time)
# unit: second
activity-timeout: -1
# 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录)
# Whether to allow the same account to log in concurrently (when true, allow login together, when false, new login squeezes out old login)
is-concurrent: false
# 在多人登录同一账号时,是否共用一个token (为true时所有登录共用一个token, 为false时每次登录新建一个token)
# When multiple people log in to the same account, whether to share a token (if true, all logins share a token, and if false, create a new token for each login)
is-share: true
# token风格
# token style
token-style: uuid
# 是否输出操作日志
# Whether to output the operation log
is-log: false
# Whether to print banner
is-print: false


#################################################################################################################
################################################# knife4j Config ################################################
#################################################################################################################
knife4j:
enable: true

#################################################################################################################
################################################# DolphinScheduler Config #######################################
#################################################################################################################
dinky:
dolphinscheduler:
# If you enable the integrated DolphinScheduler, you need to configure the following configuration items
enabled: false
# dolphinscheduler 地址
# DolphinScheduler Address
# Note: The address must be the same as the address configured in the DolphinScheduler background , eg: http://127.0.0.1:12345/dolphinscheduler
url: http://127.0.0.1:5173/dolphinscheduler
# dolphinscheduler 生成的token
# DolphinScheduler's Token , Please create a token in DolphinScheduler's Security Center -> Token Management, and modify the following configuration
token: ad54eb8f57fadea95f52763517978b26
# dolphinscheduler 中指定的项目名不区分大小写
# The project name specified in DolphinScheduler, case insensitive
project-name: Dinky
# Dolphinscheduler DinkyTask Address
# DolphinScheduler DinkyTask Address , eg: http://127.0.0.1:8888
# note: the address must be the same as the address configured in the Dinky Application background url
address: http://127.0.0.1:8888

# python udf 需要用到的 python 执行环境
# The python execution environment needed by python udf
python:
path: python
46 changes: 46 additions & 0 deletions dinky-alert/dinky-alert-sms/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.dinky</groupId>
<artifactId>dinky-alert</artifactId>
<version>0.8.0</version>
</parent>

<artifactId>dinky-alert-sms</artifactId>
<name>Dinky : Alter : SMS</name>

<dependencies>
<dependency>
<groupId>org.dinky</groupId>
<artifactId>dinky-alert-base</artifactId>
</dependency>
<dependency>
<groupId>org.dromara.sms4j</groupId>
<artifactId>sms4j-spring-boot-starter</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.dinky.alert.sms;

import org.dinky.alert.AbstractAlert;
import org.dinky.alert.AlertResult;

import cn.hutool.json.JSONUtil;

/** SmsAlert */
public class SmsAlert extends AbstractAlert {

@Override
public String getType() {
return SmsConstants.TYPE;
}

@Override
public AlertResult send(String title, String content) {
SmsSender sender = new SmsSender(JSONUtil.toJsonStr(getConfig().getParam()));
return sender.send(title, content);
}
}
Loading

0 comments on commit a473767

Please sign in to comment.