日志容量达到上限的90%进行告警
This commit is contained in:
parent
1c3012232d
commit
75936f519c
|
|
@ -5,8 +5,8 @@ import com.bonus.common.core.constant.TokenConstants;
|
|||
import com.bonus.common.core.context.SecurityContextHolder;
|
||||
import com.bonus.common.core.utils.ServletUtils;
|
||||
import com.bonus.common.core.utils.StringUtils;
|
||||
import com.bonus.common.core.utils.encryption.Sm4Utils;
|
||||
import com.bonus.system.api.model.LoginUser;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
|
|
@ -99,8 +99,8 @@ public class SecurityUtils
|
|||
*/
|
||||
public static String encryptPassword(String password)
|
||||
{
|
||||
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
||||
return passwordEncoder.encode(password);
|
||||
return Sm4Utils.encrypt(password);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -112,17 +112,18 @@ public class SecurityUtils
|
|||
*/
|
||||
public static boolean matchesPassword(String rawPassword, String encodedPassword)
|
||||
{
|
||||
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
||||
return passwordEncoder.matches(rawPassword, encodedPassword);
|
||||
return encodedPassword.equals(Sm4Utils.encrypt(rawPassword));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
//$2a$10$7JB720yubVSZvUI0rEqK/.VqGOZTH.ulu33dHOiBE8ByOhJIrdAu2
|
||||
//$2a$10$zvlw3Mu8M.j.MhAChrYwluj88ziX6lVD3AoRrBQpwKMcdIZvKMoR2
|
||||
// String msg= encryptPassword("Admin@1234");
|
||||
String msg= encryptPassword("Bonus$2024");
|
||||
boolean rest = matchesPassword("Bonus$2024","$2a$10$8JaKSUAU.K.mceU1.YQbd.wP4EJzbrsIscjAwPlfDR7wAWV6s/BGa");
|
||||
// String msg= encryptPassword("Bonus$2024");
|
||||
// boolean rest = matchesPassword("Bonus$2024","$2a$10$8JaKSUAU.K.mceU1.YQbd.wP4EJzbrsIscjAwPlfDR7wAWV6s/BGa");
|
||||
String msg = Sm4Utils.encrypt("Bonus$2026");
|
||||
// boolean rest = Sm4Utils.decrypt("$2a$10$8JaKSUAU.K.mceU1.YQbd.wP4EJzbrsIscjAwPlfDR7wAWV6s/BGa").equals("Bonus$2026");
|
||||
System.err.println(msg);
|
||||
System.err.println(rest);
|
||||
// System.err.println(rest);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -184,11 +184,12 @@ public class SysLogController extends BaseController {
|
|||
return service.getLogStatistics(dto);
|
||||
}
|
||||
|
||||
// @ApiOperation(value = "查询日志告警")
|
||||
// @PostMapping("logWarn")
|
||||
// public R<Map<String,Object>> logWarn() {
|
||||
// return service.logWarn();
|
||||
// }
|
||||
@ApiOperation(value = "查询日志告警")
|
||||
@GetMapping("logWarn")
|
||||
public AjaxResult logWarn() {
|
||||
service.handleWarningLog();
|
||||
return success();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -229,10 +229,6 @@ public class SysUserController extends BaseController {
|
|||
ajax.put("user", user);
|
||||
ajax.put("roles", roles);
|
||||
ajax.put("permissions", permissions);
|
||||
//在系统管理员和审计管理员登录时处理警告日志
|
||||
if(roles.contains("admin") || roles.contains("audit") || roles.contains("systemAdmin")){
|
||||
sysLogService.handleWarningLog();
|
||||
}
|
||||
return ajax;
|
||||
} catch (Exception e) {
|
||||
logger.error(e.toString(), e);
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ public class SysLogServiceImpl implements ISysLogService {
|
|||
}
|
||||
mapper.saveLogs(sysLog);
|
||||
if (sysLog.getLogType() == 2) {
|
||||
eventPublisher.publishEvent(new WaringLogEvent(new SysWarning(sysLog.getLogId(),sysLog.getErrType() ,sysLog.getIp(),sysLog.getOperaUserName(),sysLog.getOperTime())));
|
||||
eventPublisher.publishEvent(new WaringLogEvent(new SysWarning(sysLog.getLogId(),sysLog.getErrType() ,sysLog.getIp(),sysLog.getOperaUserName(),sysLog.getOperTime(),"0")));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("保存系统日志");
|
||||
|
|
@ -110,7 +110,7 @@ public class SysLogServiceImpl implements ISysLogService {
|
|||
}
|
||||
mapper.saveLogs(sysLog);
|
||||
if (sysLog.getLogType() == 2) {
|
||||
eventPublisher.publishEvent(new WaringLogEvent(new SysWarning(loginUuid, "越权访问", ip, user.getUsername(), DateUtils.getTime())));
|
||||
eventPublisher.publishEvent(new WaringLogEvent(new SysWarning(loginUuid, "越权访问", ip, user.getUsername(), DateUtils.getTime(),"0")));
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.error(e.toString(),e);
|
||||
|
|
@ -273,7 +273,7 @@ public class SysLogServiceImpl implements ISysLogService {
|
|||
Double max=Double.parseDouble(city)*bfb;
|
||||
if(d>=max){
|
||||
String warningEvent = "日志容量告警,当日日志内存为" +d+ "MB,日志内存超过总内存的90%,请及时处理!";
|
||||
eventPublisher.publishEvent(new WaringLogEvent(new SysWarning("0",warningEvent,"",null,null)));
|
||||
eventPublisher.publishEvent(new WaringLogEvent(new SysWarning("0",warningEvent,"",null,null, "1")));
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.error(e.toString(),e);
|
||||
|
|
@ -286,7 +286,7 @@ public class SysLogServiceImpl implements ISysLogService {
|
|||
List<SysLogsVo> list = mapper.getNotHandleWarningLog();
|
||||
// 使用for-each循环遍历List
|
||||
for (SysLogsVo item : list) {
|
||||
eventPublisher.publishEvent(new WaringLogEvent(new SysWarning(item.getLogId(),item.getErrType(), item.getIp(),item.getOperaUserName(),item.getOperTime())));
|
||||
eventPublisher.publishEvent(new WaringLogEvent(new SysWarning(item.getLogId(),item.getErrType(), item.getIp(),item.getOperaUserName(),item.getOperTime(),"0")));
|
||||
log.info("*****系统管理员和审计管理员处理异常日志*******");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ public class SysOperLogServiceImpl implements ISysOperLogService
|
|||
public int addLogs(SysLogsVo sysLogsVo) {
|
||||
if (sysLogsVo.getLogType() == 2) {
|
||||
sysLogsVo.setWarningStatus("0");
|
||||
eventPublisher.publishEvent(new WaringLogEvent(new SysWarning(sysLogsVo.getLogId(), sysLogsVo.getErrType(), sysLogsVo.getIp(), sysLogsVo.getOperaUserName(), sysLogsVo.getOperTime())));
|
||||
eventPublisher.publishEvent(new WaringLogEvent(new SysWarning(sysLogsVo.getLogId(), sysLogsVo.getErrType(), sysLogsVo.getIp(), sysLogsVo.getOperaUserName(), sysLogsVo.getOperTime(), "0")));
|
||||
}
|
||||
return operLogMapper.addLogs(sysLogsVo);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,12 +7,13 @@ import java.util.Date;
|
|||
@Data
|
||||
public class SysWarning {
|
||||
|
||||
public SysWarning(String warningId,String warningEvent,String warningIp,String operaUserName,String operaTime ){
|
||||
public SysWarning(String warningId,String warningEvent,String warningIp,String operaUserName,String operaTime, String warningStatus){
|
||||
this.warningId = warningId;
|
||||
this.warningEvent = warningEvent;
|
||||
this.warningIp = warningIp;
|
||||
this.operaUserName = operaUserName;
|
||||
this.operaTime = operaTime;
|
||||
this.warningStatus = warningStatus;
|
||||
}
|
||||
private String warningId;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.bonus.system.warning;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.bonus.common.core.utils.SpringUtils;
|
||||
import com.bonus.system.service.ISysLogService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.event.EventListener;
|
||||
|
|
@ -24,9 +25,6 @@ public class WebSocketHandler extends TextWebSocketHandler {
|
|||
private static final Logger logger = LoggerFactory.getLogger(WebSocketHandler.class);
|
||||
private static final CopyOnWriteArrayList<WebSocketSession> sessions = new CopyOnWriteArrayList<>();
|
||||
|
||||
@Resource(name = "ISysLogService")
|
||||
private ISysLogService logService;
|
||||
|
||||
public static void closeSession(WebSocketSession session) throws IOException {
|
||||
session.close();
|
||||
}
|
||||
|
|
@ -42,7 +40,7 @@ public class WebSocketHandler extends TextWebSocketHandler {
|
|||
String jsonStr = JSON.toJSONString(warning);
|
||||
sendMessageToAll(jsonStr);
|
||||
} catch (Exception e) {
|
||||
System.out.print("处理日志告警失败");
|
||||
logger.error("处理日志告警失败" + event);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -53,7 +51,7 @@ public class WebSocketHandler extends TextWebSocketHandler {
|
|||
@EventListener
|
||||
public void handleWebSocketConnectListener(SessionConnectedEvent event) {
|
||||
StompHeaderAccessor headerAccessor = StompHeaderAccessor.wrap(event.getMessage());
|
||||
System.out.println("WebSocket 连接建立,Session ID: " + headerAccessor.getSessionId());
|
||||
logger.debug("WebSocket 连接建立,Session ID: " + headerAccessor.getSessionId());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -63,35 +61,36 @@ public class WebSocketHandler extends TextWebSocketHandler {
|
|||
@EventListener
|
||||
public void handleWebSocketDisconnectListener(SessionDisconnectEvent event) {
|
||||
StompHeaderAccessor headerAccessor = StompHeaderAccessor.wrap(event.getMessage());
|
||||
System.out.println("WebSocket 连接断开,Session ID: " + headerAccessor.getSessionId());
|
||||
logger.debug("WebSocket 连接断开,Session ID: " + headerAccessor.getSessionId());
|
||||
}
|
||||
|
||||
// 处理用户确认消息
|
||||
@MessageMapping("/alert-handled")
|
||||
public void handleAlert(String alertId) {
|
||||
// 在这里处理告警确认逻辑
|
||||
System.out.println("Alert " + alertId + " has been handled");
|
||||
logger.debug("Alert " + alertId + " has been handled");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
|
||||
sessions.add(session);
|
||||
logger.info("WebSocket 连接成功: " + session.getId());
|
||||
logger.debug("WebSocket 连接成功: " + session.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
|
||||
String payload = message.getPayload();
|
||||
logger.info("接收到消息: " + payload);
|
||||
logger.debug("接收到消息: " + payload);
|
||||
|
||||
ISysLogService logService = SpringUtils.getBean(ISysLogService.class);
|
||||
logService.updateLogsWithHandledStatus(payload);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
|
||||
sessions.remove(session);
|
||||
logger.info("WebSocket 连接关闭: " + session.getId());
|
||||
logger.debug("WebSocket 连接关闭: " + session.getId());
|
||||
}
|
||||
|
||||
public void sendMessageToAll(String message) throws Exception {
|
||||
|
|
|
|||
|
|
@ -270,7 +270,7 @@
|
|||
SELECT
|
||||
log_id logId, opera_user_name operaUserName,ip,
|
||||
user_id userId, oper_time operTime,
|
||||
oper_type operType
|
||||
oper_type operType, err_type errType
|
||||
FROM sys_logs
|
||||
where warning_status=0
|
||||
</select>
|
||||
|
|
|
|||
Loading…
Reference in New Issue