Commit 87a136de authored by zengtianlai3's avatar zengtianlai3

添加告警

parent 9819106c
......@@ -5,6 +5,7 @@ import iot.sixiang.license.device.DeviceProtocol;
import iot.sixiang.license.model.SamInfo;
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.context.event.EventListener;
......@@ -22,6 +23,9 @@ public class OperateSAMStatusResponseEventHandler {
@Autowired
public OperateManager operateManager;
@Autowired
private AlarmService alarmService;
public OperateSAMStatusResponseEventHandler() {
}
......@@ -36,6 +40,12 @@ public class OperateSAMStatusResponseEventHandler {
for (SamInfo samInfo : samInfoList) {
if (samInfo.getStatus() == 0 || samInfo.getStatus() == 1 || samInfo.getStatus() == 2 || samInfo.getStatus() == 4) {
onlineCount++;
} else {
int index = samInfo.getIndex();
int typeId = 2;
String title = "SAM故障";
String content = "index为" + index + "的SAM发生故障";
alarmService.addAlarm(typeId,title,content);
}
}
SamMonitor samMonitor = new SamMonitor();
......@@ -43,5 +53,11 @@ public class OperateSAMStatusResponseEventHandler {
samMonitor.setOnlineCount(onlineCount);
samMonitor.setSamCount(samCount);
operateManager.putSamMonitorMap(serverIp, samMonitor);
if (onlineCount / samCount > 0.7) {
int typeId = 3;
String title = "SAM不足";
String content = "当前在线客户端已超过70%";
alarmService.addAlarm(typeId,title,content);
}
}
}
package iot.sixiang.license.forward;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoop;
import io.netty.channel.socket.SocketChannel;
import iot.sixiang.license.device.DeviceProtocol;
import iot.sixiang.license.event.DeviceClientBeForcedOfflineEvent;
......@@ -9,32 +8,31 @@ import iot.sixiang.license.event.DeviceClientLicenseEvent;
import iot.sixiang.license.event.EventPublisher;
import iot.sixiang.license.event.ForwardClientConnectEvent;
import iot.sixiang.license.net.BaseConnectionListener;
import iot.sixiang.license.service.AlarmService;
import iot.sixiang.license.util.SpringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.concurrent.TimeUnit;
import java.net.InetSocketAddress;
@Slf4j
public class ForwardConnectionListener extends BaseConnectionListener {
@Autowired
private AlarmService alarmService;
@Override
public void operationComplete(ChannelFuture channelFuture) throws Exception {
if (!channelFuture.isSuccess()) {
// final EventLoop loop = channelFuture.channel().eventLoop();
// loop.schedule(new Runnable() {
// @Override
// public void run() {
// log.debug("ForwardConnectionListener ...operationComplete");
// log.info("forward client connect fail ..." + appId);
//// ForwardManager forwardManager = SpringUtil.getBean(ForwardManager.class);
//// log.debug("channelActive.forwardManager:" + forwardManager);
//
//// log.warn("The client is not connected and starts to reconnect..." + forwardManager);
//// forwardManager.startTcpClient(appId);
// }
// }, 10L, TimeUnit.SECONDS);
//TODO 中转失败进行告警
InetSocketAddress socketAddress = (InetSocketAddress)channelFuture.channel().remoteAddress();
String remoteIp = socketAddress.getHostString();
String remotePort = String.valueOf(socketAddress.getPort());
int typeId = 1;
String title = "中转失败";
String content = "中转到服务器:" + remoteIp + ":"+ remotePort +"失败";
alarmService.addAlarm(typeId,title,content);
//TODO forward client连接失败,则强制踢掉设备客户端
DeviceClientBeForcedOfflineEvent deviceClientBeForcedOfflineEvent = new DeviceClientBeForcedOfflineEvent();
......
......@@ -3,27 +3,36 @@ package iot.sixiang.license.operate;
import io.netty.channel.ChannelFuture;
import io.netty.channel.socket.SocketChannel;
import iot.sixiang.license.device.DeviceProtocol;
import iot.sixiang.license.event.*;
import iot.sixiang.license.event.EventPublisher;
import iot.sixiang.license.event.OperateSAMStatusRequestEvent;
import iot.sixiang.license.net.BaseConnectionListener;
import iot.sixiang.license.service.AlarmService;
import iot.sixiang.license.util.SpringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import java.net.InetSocketAddress;
@Slf4j
public class OperateConnectionListener extends BaseConnectionListener {
@Autowired
private AlarmService alarmService;
@Override
public void operationComplete(ChannelFuture channelFuture) throws Exception {
if (!channelFuture.isSuccess()) {
//TODO 失败进行告警
InetSocketAddress socketAddress = (InetSocketAddress)channelFuture.channel().remoteAddress();
String remoteIp = socketAddress.getHostString();
String remotePort = String.valueOf(socketAddress.getPort());
int typeId = 1;
String title = "连接服器失败";
String content = "连接服务器:" + remoteIp + ":"+ remotePort +"失败";
alarmService.addAlarm(typeId,title,content);
} else {
//TODO 查询SAM状态
OperateSAMStatusRequestEvent operateSAMStatusQueryEvent = new OperateSAMStatusRequestEvent();
short stx = 21930;
int len = 2;
byte cmd = 0x5f;
......
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