提交 5e0442e2 authored 作者: 杨凯's avatar 杨凯

feat:新增告警接收接口

上级 cd2e7e7d
...@@ -16,4 +16,220 @@ ...@@ -16,4 +16,220 @@
<maven.compiler.target>8</maven.compiler.target> <maven.compiler.target>8</maven.compiler.target>
</properties> </properties>
<dependencies>
<!--easypoi -->
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-base</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-web</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-annotation</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.ebaiyihui</groupId>-->
<!-- <artifactId>byh-framework-service</artifactId>-->
<!-- <version>0.0.1-SNAPSHOT</version>-->
<!-- </dependency>-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<!--swagger接口文档-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.9.0</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>io.github.swagger2markup</groupId>-->
<!-- <artifactId>swagger2markup</artifactId>-->
<!-- <version>1.3.3</version>-->
<!-- </dependency>-->
<!--数据库连接-->
<!-- <dependency>-->
<!-- <groupId>com.alibaba</groupId>-->
<!-- <artifactId>druid-spring-boot-starter</artifactId>-->
<!-- <version>1.1.9</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>mysql</groupId>-->
<!-- <artifactId>mysql-connector-java</artifactId>-->
<!-- <version>5.1.30</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.mybatis.spring.boot</groupId>-->
<!-- <artifactId>mybatis-spring-boot-starter</artifactId>-->
<!-- <version>1.3.2</version>-->
<!-- </dependency>-->
<!--fastjson-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.24</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.github.pagehelper</groupId>-->
<!-- <artifactId>pagehelper-spring-boot-starter</artifactId>-->
<!-- <version>1.2.5</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.springframework.amqp</groupId>-->
<!-- <artifactId>spring-rabbit</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>com.ning</groupId>
<artifactId>async-http-client</artifactId>
<version>1.9.40</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.ihospital</groupId>-->
<!-- <artifactId>doctoruser-service-api</artifactId>-->
<!-- <version>${doctoruser-api.version}</version>-->
<!-- <exclusions>-->
<!-- <exclusion>-->
<!-- <groupId>com.github.xiaoymin</groupId>-->
<!-- <artifactId>swagger-bootstrap-ui</artifactId>-->
<!-- </exclusion>-->
<!-- <exclusion>-->
<!-- <groupId>com.hxgy.ehospital</groupId>-->
<!-- <artifactId>hxgy-commons-core</artifactId>-->
<!-- </exclusion>-->
<!-- <exclusion>-->
<!-- <groupId>com.ebaiyihui</groupId>-->
<!-- <artifactId>byh-framework-service</artifactId>-->
<!-- </exclusion>-->
<!-- </exclusions>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>com.ebaiyihui</groupId>-->
<!-- <artifactId>node-user-center-client</artifactId>-->
<!-- <version>${node-user-center.version}</version>-->
<!-- <exclusions>-->
<!-- <exclusion> &lt;!&ndash; declare the exclusion here &ndash;&gt;-->
<!-- <groupId>com.ebaiyihui</groupId>-->
<!-- <artifactId>byh-common-redis</artifactId>-->
<!-- </exclusion>-->
<!-- <exclusion> &lt;!&ndash; declare the exclusion here &ndash;&gt;-->
<!-- <groupId>com.hxgy.ehospital</groupId>-->
<!-- <artifactId>hxgy-ehospital-im</artifactId>-->
<!-- </exclusion>-->
<!-- </exclusions>-->
<!-- </dependency>-->
<!--redis-->
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-data-redis</artifactId>-->
<!-- </dependency>-->
<!--Excel文件导出-->
<!-- <dependency>-->
<!-- <groupId>com.alibaba</groupId>-->
<!-- <artifactId>easyexcel</artifactId>-->
<!-- <version>2.1.3</version>-->
<!-- <scope>compile</scope>-->
<!-- </dependency>-->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>${docker.plugin.version}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>build</goal>
<goal>push</goal>
</goals>
</execution>
</executions>
<configuration>
<imageName>${docker.image.prefix}/${project.artifactId}:${project.version}</imageName>
<dockerDirectory>${project.basedir}/src/main/${dockerfile.dic}</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
</project> </project>
\ No newline at end of file
FROM byh-registry-pro:5000/byh-base:s9.0.0
VOLUME /tmp
ADD byh-alarm-server-*.jar app.jar
ADD startup.sh startup.sh
RUN sh -c 'touch /app.jar'
RUN echo "Asia/Shanghai" > /etc/localtime > /etc/timezone \
&& chmod +x /startup.sh
ENTRYPOINT ["/startup.sh" ]
\ No newline at end of file
#!/bin/sh
java -Duser.timezone=GMT+08 -Dfile.encoding=UTF-8 \
-javaagent:/agent/skywalking-agent.jar \
-Dskywalking.agent.service_name=${sw_service_name} \
-Dskywalking.collector.backend_service=${sw_service_url} \
-Dskywalking.trace.ignore_path=/eureka/** \
-Djava.security.egd=file:/dev/./urandom \
-jar \
/app.jar
\ No newline at end of file
FROM byh-registry:5000/oraclejdk8:v1
VOLUME /tmp
ADD byh-alarm-server-*.jar app.jar
RUN sh -c 'touch /app.jar'
RUN echo "Asia/Shanghai" > /etc/timezone
ENV JAVA_OPTS="-Duser.timezone=GMT+08 -Dfile.encoding=UTF-8"
ENTRYPOINT ["sh","-c","java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]
\ No newline at end of file
package com.ebaiyihui;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
/**
* @description:
* @author: yk
* @create: 2023/08/09 09:15
**/
@SpringBootApplication
//@EnableDiscoveryClient
public class AlarmServerApplication {
public static void main(String[] args) {
SpringApplication.run(AlarmServerApplication.class, args);
}
}
package com.ebaiyihui.alarm.server.controller;
/**
* @description:
* @author: yk
* @create: 2023/08/09 09:29
**/
import com.ebaiyihui.alarm.server.entity.AlarmMessage;
import com.ebaiyihui.alarm.server.service.AlarmService;
import com.ebaiyihui.framework.page.PageResult;
import com.ebaiyihui.framework.response.BaseResponse;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@Slf4j
@RestController
@RequestMapping(value = "/alarm")
public class AlarmController {
@Autowired
private AlarmService alarmService;
// receive
@ApiOperation(value = "告警接收地址")
@RequestMapping(value = "/receive", method = RequestMethod.POST)
public String receive(@RequestBody @Validated List<AlarmMessage> alarmMessages) {
return alarmService.receive(alarmMessages);
}
}
package com.ebaiyihui.alarm.server.entity;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
/**
* @description:
* @author: yk
* @create: 2023/08/09 09:21
**/
@Setter
@Getter
public class AlarmMessage {
private int scopeId;
private String scope;
private String name;
private String id0;
private String id1;
private String ruleName;
private String alarmMessage;
private List<Tag> tags;
private long startTime;
}
package com.ebaiyihui.alarm.server.entity;
import lombok.*;
import org.springframework.util.CollectionUtils;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
/**
* @description:
* @author: yk
* @create: 2023/08/09 09:22
**/
@Getter
@Setter
@EqualsAndHashCode
@NoArgsConstructor
@AllArgsConstructor
public class Tag {
public static final int TAG_LENGTH = 256;
private String key;
private String value;
@Override
public String toString() {
return key + "=" + value;
}
public static class Util {
public static List<String> toStringList(List<Tag> list) {
if (CollectionUtils.isEmpty(list)) {
return Collections.emptyList();
}
return list.stream().map(Tag::toString).collect(Collectors.toList());
}
}
}
package com.ebaiyihui.alarm.server.service;
import com.ebaiyihui.alarm.server.entity.AlarmMessage;
import java.util.List;
/**
* @description:
* @author: yk
* @create: 2023/08/09 09:52
**/
public interface AlarmService {
String receive(List<AlarmMessage> alarmMessages);
}
package com.ebaiyihui.alarm.server.service.Impl;
import com.ebaiyihui.alarm.server.entity.AlarmMessage;
import com.ebaiyihui.alarm.server.service.AlarmService;
import com.ebaiyihui.alarm.server.util.HttpKit;
import com.ebaiyihui.framework.utils.StringUtil;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.netflix.client.http.HttpRequest;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.io.IOException;
import java.net.URI;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.time.Duration;
import java.util.*;
import java.util.stream.Collectors;
/**
* @description:
* @author: yk
* @create: 2023/08/09 09:52
**/
@Service
public class AlarmServiceImpl implements AlarmService {
@Value(value = "${webHookUrl}")
private String webHookUrl;
@Value(value = "${secret}")
private String secret;
@Override
public String receive(List<AlarmMessage> alarmMessages) {
for (AlarmMessage alarmMessage : alarmMessages) {
String name = alarmMessage.getName();
String message = alarmMessage.getAlarmMessage();
if (name.contains("byh-ehospital-im01_cloud-pro") ||
name.contains("byh-ehospital-im02_cloud-pro")) {
message += "<at user_id=\\\"ou_6cb2f35f9bf8e7d7e977483801ab13de\\\">杨凯</at>";
alarmMessage.setAlarmMessage(message);
}
String sendMessage = "{\"msg_type\":\"text\",\"content\":{\"text\":\"Apache SkyWalking Alarm: \\n %s.\"}}";
String requestBody = getRequestBody(sendMessage, alarmMessage);
try {
HttpKit.jsonPost(webHookUrl, requestBody);
} catch (Exception e) {
return "fail";
}
}
return "success";
}
/**
* deal requestBody,if it has sign set the sign
*/
private String getRequestBody(String sendMessage, AlarmMessage alarmMessage) {
String requestBody = String.format(sendMessage, alarmMessage.getAlarmMessage());
Gson gson = new Gson();
JsonObject jsonObject = gson.fromJson(requestBody, JsonObject.class);
Map<String, Object> content = buildContent(jsonObject);
if (!StringUtil.isBlank(secret)) {
Long timestamp = System.currentTimeMillis() / 1000;
content.put("timestamp", timestamp);
try {
content.put("sign", sign(timestamp, secret));
} catch (NoSuchAlgorithmException | InvalidKeyException e) {
throw new RuntimeException(e);
}
}
return gson.toJson(content);
}
/**
* build content,if it has ats someone set the ats
*/
private Map<String, Object> buildContent(JsonObject jsonObject) {
Map<String, Object> content = new HashMap<String, Object>();
content.put("msg_type", jsonObject.get("msg_type").getAsString());
if (jsonObject.get("ats") != null) {
String ats = jsonObject.get("ats").getAsString();
List<String> collect = Arrays.stream(ats.split(",")).map(String::trim).collect(Collectors.toList());
String text = jsonObject.get("content").getAsJsonObject().get("text").getAsString();
for (final String userId : collect) {
text += "<at user_id=\"" + userId + "\"></at>";
}
jsonObject.get("content").getAsJsonObject().addProperty("text", text);
}
content.put("content", jsonObject.get("content").getAsJsonObject());
return content;
}
/**
* Sign webhook url using HmacSHA256 algorithm
*/
private String sign(final Long timestamp, String secret) throws NoSuchAlgorithmException, InvalidKeyException {
String stringToSign = timestamp + "\n" + secret;
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(new SecretKeySpec(stringToSign.getBytes(), "HmacSHA256"));
byte[] signData = mac.doFinal();
return Base64.getEncoder().encodeToString(signData);
}
}
package com.ebaiyihui.alarm.server.util;
import com.ning.http.client.AsyncHttpClient;
import com.ning.http.client.AsyncHttpClientConfig;
import com.ning.http.client.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLConnection;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
/**
* https 请求 微信为https的请求
*
* @author zhanghaojie
* @date 2019年08月12日
*/
public final class HttpKit {
private static Logger log = LoggerFactory.getLogger(HttpKit.class);
private static final String DEFAULT_CHARSET = "UTF-8";
/**
* 请求超时时间 //45000
*/
private static final int SO_TIMEOUT = 45000;
/**
* 最大允许连接数
*/
private static final int MAX_TOTAL_CONNECTION = 200;
private static final int MAX_PER_HOST = 90;
/**
* 异步请求对象
*/
private static AsyncHttpClient asyncHttpClient;
/*
* 设置异步请求参数
*/
static {
AsyncHttpClientConfig.Builder builder = new AsyncHttpClientConfig.Builder();
builder.setMaxConnections(MAX_TOTAL_CONNECTION);
builder.setMaxConnectionsPerHost(MAX_PER_HOST);
builder.setRequestTimeout(SO_TIMEOUT);
asyncHttpClient = new AsyncHttpClient(builder.build());
}
/**
* @return 返回类型:
* @throws IOException
* @throws UnsupportedEncodingException
* @throws NoSuchProviderException
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
* @description 功能描述: get 请求
*/
public static String get(String url, Map<String, String> params, Map<String, String> headers) throws IOException, ExecutionException, InterruptedException {
AsyncHttpClient.BoundRequestBuilder builder = asyncHttpClient.prepareGet(url);
builder.setBodyEncoding(DEFAULT_CHARSET);
if (params != null && !params.isEmpty()) {
Set<String> keys = params.keySet();
for (String key : keys) {
builder.addQueryParam(key, params.get(key));
}
}
if (headers != null && !headers.isEmpty()) {
Set<String> keys = headers.keySet();
for (String key : keys) {
builder.addHeader(key, params.get(key));
}
}
Future<Response> f = builder.execute();
String body = f.get().getResponseBody(DEFAULT_CHARSET);
return body;
}
/**
* @return 返回类型:
* @throws IOException
* @throws UnsupportedEncodingException
* @throws NoSuchProviderException
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
* @description 功能描述: get 请求
*/
public static String get(String url) throws KeyManagementException, NoSuchAlgorithmException, NoSuchProviderException, UnsupportedEncodingException, IOException, ExecutionException, InterruptedException {
return get(url, null);
}
/**
* @return 返回类型:
* @throws IOException
* @throws NoSuchProviderException
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
* @throws UnsupportedEncodingException
* @description 功能描述: get 请求
*/
public static String get(String url, Map<String, String> params) throws KeyManagementException, NoSuchAlgorithmException, NoSuchProviderException, UnsupportedEncodingException, IOException, ExecutionException, InterruptedException {
return get(url, params, null);
}
/**
* @return 返回类型:
* @throws IOException
* @throws NoSuchProviderException
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
* @description 功能描述: POST 请求
*/
public static String post(String url, Map<String, String> params) throws IOException, ExecutionException, InterruptedException {
AsyncHttpClient.BoundRequestBuilder builder = asyncHttpClient.preparePost(url);
builder.setBodyEncoding(DEFAULT_CHARSET);
if (params != null && !params.isEmpty()) {
Set<String> keys = params.keySet();
for (String key : keys) {
builder.addQueryParam(key, params.get(key));
}
}
Future<Response> f = builder.execute();
return f.get().getResponseBody(DEFAULT_CHARSET);
}
public static String post(String url, String s) throws IOException, ExecutionException, InterruptedException {
AsyncHttpClient.BoundRequestBuilder builder = asyncHttpClient.preparePost(url);
builder.setBodyEncoding(DEFAULT_CHARSET);
builder.setBody(s);
Future<Response> f = builder.execute();
return f.get().getResponseBody(DEFAULT_CHARSET);
}
public static String jsonPost(String url, String s) throws IOException, ExecutionException, InterruptedException {
AsyncHttpClient.BoundRequestBuilder builder = asyncHttpClient.preparePost(url);
builder.setHeader("Content-Type", "application/json");
builder.setBodyEncoding(DEFAULT_CHARSET);
builder.setBody(s);
log.info("http请求 url->{}, param->:" + url, s);
Future<Response> f = builder.execute();
String body = f.get().getResponseBody(DEFAULT_CHARSET);
log.info("http响应:" + body);
return body;
}
/**
* 向指定URL发送GET方法的请求
*
* @param url 发送请求的URL
* @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
* @return URL 所代表远程资源的响应结果
*/
public static String sendGet(String url, String param) {
StringBuilder result = new StringBuilder();
BufferedReader in = null;
try {
String urlNameString = param == null ? url : (url + "?" + param);
URL realUrl = new URL(urlNameString);
// 打开和URL之间的连接
URLConnection connection = realUrl.openConnection();
// 设置通用的请求属性
connection.setRequestProperty("accept", "*/*");
connection.setRequestProperty("connection", "Keep-Alive");
connection.setRequestProperty("user-agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.56 Safari/537.17");
// 建立实际的连接
connection.connect();
// 定义 BufferedReader输入流来读取URL的响应
in = new BufferedReader(new InputStreamReader(
connection.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
result.append(line);
}
} catch (Exception e) {
e.printStackTrace();
log.error("发送GET请求出现异常:" + e.getMessage(), e);
}
// 使用finally块来关闭输入流
finally {
try {
if (in != null) {
in.close();
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
return result.toString();
}
public static String sendGet(String url) {
return sendGet(url, null);
}
}
\ No newline at end of file
#spring:
# redis:
# database: 0
# cluster:
# nodes: 39.105.23.253:6382,39.106.26.175:6381,101.200.127.120:6382
# timeout: 3600
# jedis:
# shutdown-timeout: 3600
# pool:
# max-wait: -1
# max-active: 300
# max-idle: 8
# min-idle: 2
# datasource:
# driver-class-name: com.mysql.jdbc.Driver
# username: root
# password: Bykf@2020@..
# url: jdbc:mysql://192.168.0.108:3311/byh-charitable-assistance?useUnicode=true&characterEncoding=utf8
# cache:
# cache-names: dataCache
# type: REDIS
# rabbitmq:
# host: 123.57.93.190
# port: 5672
# username: byh
# password: byh2019@ZW..
# jackson:
# serialization:
# WRITE_DATES_AS_TIMESTAMPS: true
#eureka:
# client:
# registerWithEureka: true
# fetchRegistry: true
# serviceUrl:
# defaultZone: http://discover:1111/eureka
#feign:
# hystrix:
# enabled: true # 开启Feign熔断
#
#hystrix:
# command:
# default:
# execution:
# isolation:
# thread:
# timeoutInMilliseconds: 50000
#ribbon:
# ReadTimeout: 50000
# ConnectTimeout: 50000
#mybatis:
# mapper-locations: classpath:mapper/*.xml
# configuration:
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
# map-underscore-to-camel-case: true
logging:
config: classpath:logback-spring.xml
path: data/log
#swagger:
# enabled: true
webHookUrl: https://open.feishu.cn/open-apis/bot/v2/hook/23a4631d-393e-46e8-9235-f321323b37d0
secret: OV5mmyDxX5Nx0caMYQp3Kg
server:
port: 9192
spring:
application:
name: byh-alarm-service
profiles:
active: pro
# cloud:
# config:
# name: byh-charitable-assistance
# profile: pro # 配置文件版本
# label: zryh # 配置文件分支
# discovery:
# enabled: true #是从配置中心读取文件
# service-id: byh-service-config
#eureka:
# client:
# serviceUrl:
# defaultZone: http://127.0.0.1:1111/eureka/
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<springProperty scope="context" name="springAppName" source="spring.application.name" />
<springProperty name="LOG_PATH" source="logging.path" defaultValue="data/log/${springAppName}"/>
<property name="CONSOLE_LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss:SSS} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr([${springAppName:-}]){yellow} %clr(${PID:- }){magenta} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr([%X{caller},%X{user},%X{method}]){green} : %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}" />
<springProperty scope="context" name="FILE_PATTERN" source="log=back.pattern.file" defaultValue="%d{yyyy-MM-dd HH:mm:ss:SSS} ${LOG_LEVEL_PATTERN:-%5p} [${springAppName:-}] ${PID:- } [%15.15t] %-40.40logger{39} [%X{caller},%X{user},%X{method}] : %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}"/>
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>INFO</level>
</filter>
<encoder>
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
<charset>UTF-8</charset>
</encoder>
</appender>
<appender name="flatfile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!--日志文件输出的文件名 -->
<fileNamePattern>${LOG_PATH}/${springAppName}-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>300MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<pattern>${FILE_PATTERN}</pattern>
<charset>UTF-8</charset>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="console" />
<appender-ref ref="flatfile" />
</root>
</configuration>
\ No newline at end of file
...@@ -3,20 +3,150 @@ ...@@ -3,20 +3,150 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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"> 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> <modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>org.example</groupId> <groupId>org.example</groupId>
<artifactId>byh-alarm-service</artifactId> <artifactId>byh-alarm-service</artifactId>
<packaging>pom</packaging> <packaging>pom</packaging>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<profiles>
<profile>
<id>dev</id>
<properties>
<environment>dev</environment><!-- 节点名字environment是自己随意取的 -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
<java.version>1.8</java.version>
<common.version>0.0.3-SNAPSHOT</common.version>
<docker.image.prefix> byh-registry:5000</docker.image.prefix>
<docker.plugin.version>0.4.13</docker.plugin.version>
<dockerfile.dic>docker</dockerfile.dic>
<node-user-center.version>0.0.3-SNAPSHOT</node-user-center.version>
<card.version>0.0.2-SNAPSHOT</card.version>
<doctoruser-api.version>0.0.3-SNAPSHOT</doctoruser-api.version>
</properties>
<activation>
<activeByDefault>true</activeByDefault><!-- 默认激活该profile节点-->
</activation>
</profile>
<profile>
<id>pro</id>
<properties>
<environment>pro</environment><!-- 节点名字environment是自己随意取的 -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
<java.version>1.8</java.version>
<common.version>1.0.0</common.version>
<docker.image.prefix> byh-registry-pro:5000</docker.image.prefix>
<docker.plugin.version>0.4.13</docker.plugin.version>
<dockerfile.dic>docker-pro</dockerfile.dic>
<node-user-center.version>1.0.0</node-user-center.version>
<card.version>1.0.0</card.version>
<doctoruser-api.version>1.0.0</doctoruser-api.version>
</properties>
</profile>
</profiles>
<modules> <modules>
<module>alarm-cllient</module> <module>alarm-cllient</module>
<module>alarm-common</module> <module>alarm-common</module>
<module>alarm-server</module> <module>alarm-server</module>
</modules> </modules>
<properties> <dependencies>
<maven.compiler.source>8</maven.compiler.source> <dependency>
<maven.compiler.target>8</maven.compiler.target> <groupId>org.springframework.boot</groupId>
</properties> <artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--swagger接口文档-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>com.ebaiyihui</groupId>
<artifactId>byh-framework-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<repositories>
<repository>
<id>public</id>
<name>byhgroup</name>
<url>http://39.106.16.160:9001/nexus/content/groups/public/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>releases</id>
<name>Releases</name>
<url>http://39.106.16.160:9001/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Snapshots</name>
<url>http://39.106.16.160:9001/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
</project> </project>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论