Commit 4a671a1b authored by zengtianlai3's avatar zengtianlai3

运维模块-告警

parent 2f5f9c7f
......@@ -2,7 +2,11 @@ package iot.sixiang.license.controller;
import com.alibaba.fastjson.JSONObject;
import iot.sixiang.license.model.ResResult;
import iot.sixiang.license.model.SamMonitor;
import iot.sixiang.license.operate.OperateManager;
import iot.sixiang.license.service.AlarmService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......@@ -15,20 +19,34 @@ import java.util.List;
@RequestMapping("/iot_license/operate")
public class OperateController {
@Autowired
private OperateManager operateManager;
@Autowired
private AlarmService alarmService;
@GetMapping("monitor/server")
public ResResult getDeviceTypes() {
List<JSONObject> list = new ArrayList<>();
JSONObject obj = new JSONObject();
obj.put("serverIp", "192.168.1.11");
obj.put("serverSam", 100);
obj.put("onlineCount",55);
list.add(obj);
JSONObject obj2 = new JSONObject();
obj2.put("serverIp", "192.168.1.12");
obj2.put("serverSam", 100);
obj2.put("onlineCount",55);
list.add(obj2);
return ResResult.success().record(list);
// List<JSONObject> list = new ArrayList<>();
// JSONObject obj = new JSONObject();
// obj.put("serverIp", "192.168.1.11");
// obj.put("samCount", 100);
// obj.put("onlineCount",55);
// list.add(obj);
// JSONObject obj2 = new JSONObject();
// obj2.put("serverIp", "192.168.1.12");
// obj2.put("samCount", 100);
// obj2.put("onlineCount",55);
// list.add(obj2);
List<SamMonitor> records = operateManager.getSamMonitorList();
return ResResult.success().record(records);
}
@GetMapping("alarm/add")
public void addlog(){
alarmService.addAlarm("test");
}
}
package iot.sixiang.license.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class Alarm {
private static final long serialVersionUID = 1L;
@TableId(type = IdType.AUTO)
private Integer id;
private String content;
}
......@@ -7,13 +7,14 @@ import iot.sixiang.license.model.ResResult;
import lombok.extern.slf4j.Slf4j;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;
@Slf4j
//@WebFilter(filterName = "jwtFilter", urlPatterns = "/iot_license/*")
@WebFilter(filterName = "jwtFilter", urlPatterns = "/iot_license/*")
public class JwtFilter implements Filter {
......
package iot.sixiang.license.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import iot.sixiang.license.entity.Alarm;
import iot.sixiang.license.entity.Apply;
import iot.sixiang.license.model.vo.AppVo;
import java.util.List;
/**
* Title: AlarmMapper
* Description: TODO
*
* @author m33
* @version V1.0
* @date 2022-06-09
*/
public interface AlarmMapper extends BaseMapper<Alarm> {
boolean addAlarm(String content);
// List<Alarm> getAlarmList(String id);
//
// Apply getApplyByAppName(String id);
}
......@@ -34,7 +34,9 @@ public class OperateClientHandler extends SimpleChannelInboundHandler<Object> {
SocketChannel channel = (SocketChannel) ctx.channel();
InetSocketAddress socketAddr = (InetSocketAddress) ctx.channel().remoteAddress();
String remoteIp = socketAddr.getHostString();
DeviceProtocol protocol = (DeviceProtocol) msg;
OperateSAMStatusEvent event = new OperateSAMStatusEvent();
event.setProtocol(protocol);
event.setIp(remoteIp);
......
......@@ -26,11 +26,11 @@ public class OperateConnectionListener extends BaseConnectionListener {
short stx = 21930;
int len = 2;
// byte cmd = 0x5f;
byte cmd = 0x5b;
byte cmd = 0x5f;
// byte cmd = 0x5b;
byte ack = 0x00;
// byte end = 0x5f;
byte end = 0x5b;
byte end = 0x5f;
// byte end = 0x5b;
SocketChannel channel = (SocketChannel) channelFuture.channel();
DeviceProtocol protocol = new DeviceProtocol(stx, len, cmd, ack, null, end);
......
......@@ -31,15 +31,15 @@ public class OperateDecoder extends ByteToMessageDecoder {
short stx = buffer.readShort();//55AA->21930
short len = buffer.readShortLE();
log.debug("msg rece len:"+packet.length+",decode len:"+len);
len = 2677;
byte cmd = buffer.readByte();
byte ack = buffer.readByte();////stx:21930,len:52,cmd:-112,ack:0
log.debug("stx:" + stx + ",len:" + len);
int real_len = len;//注意,透传前已经去掉了END一个字符
int real_len = len;
int cmd_ack_len = 2;
if (buffer.readableBytes() < real_len - cmd_ack_len+1) {
......
......@@ -2,16 +2,14 @@ package iot.sixiang.license.operate;
import iot.sixiang.license.entity.Server;
import iot.sixiang.license.model.SamMonitor;
import iot.sixiang.license.model.vo.DeviceVo;
import iot.sixiang.license.service.ServerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.*;
@Component
@Slf4j
......@@ -33,6 +31,14 @@ public class OperateManager {
samMonitorMap.put(serverIp, samMonitor);
}
public List<SamMonitor> getSamMonitorList() {
List<SamMonitor> result = new ArrayList<>();
if (samMonitorMap.size() > 0) {
samMonitorMap.entrySet().stream().sorted(Map.Entry.<String, SamMonitor>comparingByKey()).forEachOrdered(x -> result.add(x.getValue()));
}
return result;
}
@PostConstruct
public void init() {
List<Server> servers = serverService.getServerList(0, 20);
......@@ -55,6 +61,7 @@ public class OperateManager {
// for(int i =0;i<5;i++){
String serverIp = server.getServerIp();
Integer port = server.getPort();
serverIp = "192.168.1.56";
// serverIp = "172.17.115.81";
// port = 777;
this.startTcpClient(serverIp, port);
......
package iot.sixiang.license.service;
import com.baomidou.mybatisplus.extension.service.IService;
import iot.sixiang.license.entity.Alarm;
import iot.sixiang.license.entity.Apply;
import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.vo.AppVo;
/**
* Title: AlarmService
* Description: TODO
*
* @author m33
* @version V1.0
* @date 2022-06-09
*/
public interface AlarmService extends IService<Alarm> {
boolean addAlarm(String content);
// PageInfoModel<AppVo> getAppList(int pageNo, int pageSize, String appName);
}
package iot.sixiang.license.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import iot.sixiang.license.entity.Alarm;
import iot.sixiang.license.entity.Apply;
import iot.sixiang.license.handler.IotLicenseException;
import iot.sixiang.license.mapper.AlarmMapper;
import iot.sixiang.license.mapper.ApplyMapper;
import iot.sixiang.license.service.AlarmService;
import iot.sixiang.license.service.ApplyService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
public class AlarmServiceImpl extends ServiceImpl<AlarmMapper, Alarm> implements AlarmService {
@Resource
AlarmMapper alarmMapper;
@Override
public boolean addAlarm(String content) {
return alarmMapper.addAlarm(content);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="iot.sixiang.license.mapper.AlarmMapper">
<insert id="addAlarm" parameterType="iot.sixiang.license.entity.Alarm">
insert into alarm(content) values (#{content})
</insert>
</mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment