交换机管理图形监控只展示端口为up的。

优化frp信息上报
This commit is contained in:
gaoyutao
2025-12-24 19:55:47 +08:00
parent 5eda46802e
commit 30373bbb1e
13 changed files with 120 additions and 44 deletions
@@ -83,5 +83,7 @@ public class AllInterfaceName extends BaseEntity
private boolean expand;
/** 是否业务网卡 */
private boolean businessFlag;
/** 端口状态 1up 2down */
private String portStatus;
}
@@ -56,6 +56,10 @@ public class AllInterfaceNameServiceImpl implements IAllInterfaceNameService
@Override
public List<AllInterfaceName> selectAllInterfaceNameList(AllInterfaceName allInterfaceName)
{
if ("2".equals(allInterfaceName.getResourceType())) {
// 交换机类型,只返回端口为up的
allInterfaceName.setPortStatus("1");
}
List<AllInterfaceName> allInterfaceNameList = allInterfaceNameMapper.selectAllInterfaceNameList(allInterfaceName);
if (allInterfaceNameList == null || allInterfaceNameList.isEmpty()) {
return allInterfaceNameList;
@@ -150,7 +154,6 @@ public class AllInterfaceNameServiceImpl implements IAllInterfaceNameService
interfaceName.getInterfaceName() != null && topologyManagement.getInterfaceName() != null &&
interfaceName.getInterfaceName().equalsIgnoreCase(topologyManagement.getInterfaceName())
);
// 如果匹配成功,设置 expand 属性为 true
if (isMatched) {
interfaceName.setExpand(true);
@@ -405,6 +405,7 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe
record.setSwitchName(data.getSwitchName());
record.setSwitchSn(data.getSwitchSn());
record.setSwitchIp(data.getSwitchIp());
record.setPortStatus(data.getStatus());
return record;
}
private void fillBusinessInfo(AllInterfaceName record, String serverSn) {
@@ -1,7 +1,7 @@
<?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">
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tongran.system.mapper.AllInterfaceNameMapper">
<resultMap type="AllInterfaceName" id="AllInterfaceNameResult">
@@ -23,10 +23,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="switchSn" column="switch_sn" />
<result property="switchIp" column="switch_ip" />
<result property="serverIp" column="server_ip" />
<result property="portStatus" column="port_status" />
</resultMap>
<sql id="selectAllInterfaceNameVo">
select id, client_id, interface_name, device_sn, node_name, business_code, business_name, resource_type, create_time, update_time, create_by, update_by, switch_name, interface_device_type, server_port, switch_sn, switch_ip, server_ip from all_interface_name
select id, client_id, interface_name, device_sn, node_name, business_code, business_name, resource_type, create_time, update_time, create_by, update_by, switch_name, interface_device_type, server_port, switch_sn, switch_ip, server_ip, port_status from all_interface_name
</sql>
<select id="selectAllInterfaceNameList" parameterType="AllInterfaceName" resultMap="AllInterfaceNameResult">
@@ -45,6 +46,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="switchSn != null and switchSn != ''"> and switch_sn = #{switchSn}</if>
<if test="switchIp != null and switchIp != ''"> and switch_ip = #{switchIp}</if>
<if test="serverIp != null and serverIp != ''"> and server_ip = #{serverIp}</if>
<if test="portStatus != null and portStatus != ''"> and port_status = #{portStatus}</if>
</where>
</select>
@@ -73,6 +75,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="switchSn != null">switch_sn,</if>
<if test="switchIp != null">switch_ip,</if>
<if test="serverIp != null">server_ip,</if>
<if test="portStatus != null">port_status,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="clientId != null and clientId != ''">#{clientId},</if>
@@ -92,6 +95,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="switchSn != null">#{switchSn},</if>
<if test="switchIp != null">#{switchIp},</if>
<if test="serverIp != null">#{serverIp},</if>
<if test="portStatus != null">#{portStatus},</if>
</trim>
</insert>
@@ -115,6 +119,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="switchSn != null">switch_sn = #{switchSn},</if>
<if test="switchIp != null">switch_ip = #{switchIp},</if>
<if test="serverIp != null">server_ip = #{serverIp},</if>
<if test="portStatus != null">port_status = #{portStatus},</if>
</trim>
where id = #{id}
</update>
@@ -145,7 +150,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
server_port AS serverPort,
switch_sn AS switchSn,
switch_ip AS switchIp,
server_ip AS serverIp
server_ip AS serverIp,
port_status AS portStatus
FROM
all_interface_name
<where>
@@ -175,7 +181,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
node_name,
business_code,
business_name,
switch_name, interface_device_type, server_port, switch_sn, switch_ip, server_ip,
switch_name, interface_device_type, server_port, switch_sn, switch_ip, server_ip, port_status,
create_time,
update_time
)
@@ -189,7 +195,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{item.nodeName},
#{item.businessCode},
#{item.businessName},
#{item.switchName}, #{item.interfaceDeviceType}, #{item.serverPort}, #{item.switchSn}, #{item.switchIp}, #{item.serverIp},
#{item.switchName}, #{item.interfaceDeviceType}, #{item.serverPort}, #{item.switchSn}, #{item.switchIp}, #{item.serverIp}, #{item.portStatus},
NOW(),
NOW()
)
@@ -240,6 +246,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
THEN VALUES(switch_ip)
ELSE switch_ip
END,
server_ip = CASE
WHEN server_ip != VALUES(server_ip) OR (server_ip IS NULL AND VALUES(server_ip) IS NOT NULL)
THEN VALUES(server_ip)
ELSE server_ip
END,
port_status = CASE
WHEN port_status != VALUES(port_status) OR (port_status IS NULL AND VALUES(port_status) IS NOT NULL)
THEN VALUES(port_status)
ELSE port_status
END,
update_time = CASE
WHEN device_sn != VALUES(device_sn) OR (device_sn IS NULL AND VALUES(device_sn) IS NOT NULL)
OR node_name != VALUES(node_name) OR (node_name IS NULL AND VALUES(node_name) IS NOT NULL)
@@ -250,6 +266,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
OR server_port != VALUES(server_port) OR (server_port IS NULL AND VALUES(server_port) IS NOT NULL)
OR switch_sn != VALUES(switch_sn) OR (switch_sn IS NULL AND VALUES(switch_sn) IS NOT NULL)
OR switch_ip != VALUES(switch_ip) OR (switch_ip IS NULL AND VALUES(switch_ip) IS NOT NULL)
OR server_ip != VALUES(server_ip) OR (server_ip IS NULL AND VALUES(server_ip) IS NOT NULL)
OR port_status != VALUES(port_status) OR (port_status IS NULL AND VALUES(port_status) IS NOT NULL)
THEN NOW()
ELSE update_time
END
@@ -257,13 +275,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="getAllDeviceSn" parameterType="AllInterfaceName" resultType="AllInterfaceName">
SELECT
client_id AS clientId
client_id AS clientId
FROM
all_interface_name
all_interface_name
<where>
and resource_type = '1' and client_id != ''
</where>
group by client_id
group by client_id
</select>
<select id="getAllSwitchSn" parameterType="AllInterfaceName" resultType="AllInterfaceName">
SELECT
@@ -290,7 +308,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
switch_name = #{item.switchName},
switch_sn = #{item.switchSn},
switch_ip = #{item.switchIp},
server_ip = #{item.serverIp}
server_ip = #{item.serverIp},
port_status = #{item.portStatus}
WHERE id = #{item.id}
</foreach>
</update>
@@ -36,6 +36,9 @@ public class RmFrpcConfigManage extends BaseEntity
/** FRPC远程端口 */
@Excel(name = "FRPC远程端口")
private String frpcRemotePort;
/** FRPC远程端口 */
@Excel(name = "FRPC远程端口")
private String frpcType;
/** FRPC本地端口 */
@Excel(name = "FRPC本地端口")
@@ -143,8 +143,10 @@ public class MessageHandler {
frpcData.setFrpcLocalPort(rsp.getLocalPort());
frpcData.setFrpcLocalIp(rsp.getLocalIP());
frpcData.setFrpcCreateTime(createTime);
frpcData.setCreateTime(DateUtils.getNowDate());
frpcData.setFrpcConnectionStatus(2L);
frpcData.setFrpcRemotePort(rsp.getRemotePort());
frpcData.setFrpcType(rsp.getType());
frpcData.setFrpcServerAddr(rsp.getServerAddr());
frpcData.setFrpcServerPort(rsp.getServerPort());
rmFrpcConfigManageService.insertRmFrpcConfigManage(frpcData);
@@ -157,13 +159,14 @@ public class MessageHandler {
RmFrpcConfigManage frpcData = new RmFrpcConfigManage();
frpcData.setClientId(message.getClientId());
frpcData.setFrpcName(rsp.getName());
frpcData.setFrpcType(rsp.getType());
frpcData.setFrpcStatus(rsp.getIsRunning());
frpcData.setFrpcLocalPort(rsp.getLocalPort());
frpcData.setFrpcLocalIp(rsp.getLocalIP());
frpcData.setFrpcCreateTime(createTime);
frpcData.setFrpcRemotePort(rsp.getRemotePort());
frpcData.setFrpcServerAddr(rsp.getServerAddr());
frpcData.setFrpcServerPort(rsp.getServerPort());
frpcData.setUpdateTime(DateUtils.getNowDate());
rmFrpcConfigManageService.insertRmFrpcConfigManage(frpcData);
} else{
if(rsp.getRemotePort() != null){
@@ -67,4 +67,6 @@ public interface InitialSwitchOtherCollectDataMapper
* @return
*/
Map getSwitchMonitorMsg(InitialSwitchOtherCollectData initialSwitchOtherCollectData);
void deleteInitialSwitchOtherCollectData(InitialSwitchOtherCollectData deleteData);
}
@@ -88,4 +88,6 @@ public interface IInitialSwitchOtherCollectDataService
* @return
*/
Map<String, Object> getSwitchMemUseMsg(InitialSwitchOtherCollectData initialSwitchOtherCollectData);
void deleteInitialSwitchOtherCollectData(InitialSwitchOtherCollectData deleteData);
}
@@ -196,4 +196,9 @@ public class InitialSwitchOtherCollectDataServiceImpl implements IInitialSwitchO
return EchartsDataUtils.buildEchartsData(list,InitialSwitchOtherCollectData::getCreateTime, extractors);
}
@Override
public void deleteInitialSwitchOtherCollectData(InitialSwitchOtherCollectData deleteData) {
initialSwitchOtherCollectDataMapper.deleteInitialSwitchOtherCollectData(deleteData);
}
}
@@ -115,7 +115,6 @@ public class RmFrpcConfigManageServiceImpl implements IRmFrpcConfigManageService
@Override
public int insertRmFrpcConfigManage(RmFrpcConfigManage rmFrpcConfigManage)
{
rmFrpcConfigManage.setCreateTime(DateUtils.getNowDate());
int rows = rmFrpcConfigManageMapper.insertRmFrpcConfigManage(rmFrpcConfigManage);
return 1;
}
@@ -18,10 +18,7 @@ import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -93,7 +90,7 @@ public class ProcessSwitchCollectDataService {
// 设置基本信息
long timestamp = switchDataVo.getTimestamp();
Date createTime = new Date(timestamp * 1000 / 1000 * 1000);
Date createTime = new Date(timestamp * 1000);
insertData.setClientId(clientId);
insertData.setCreateTime(createTime);
@@ -104,6 +101,9 @@ public class ProcessSwitchCollectDataService {
if (jsonNode.isArray() && jsonNode.size() > 0) {
JsonNode firstElement = jsonNode.get(0);
String collectType = null;
String collectValue = null;
if (firstElement.isTextual()) {
// 二次解析JSON字符串
JsonNode innerJsonNode = objectMapper.readTree(firstElement.asText());
@@ -112,32 +112,51 @@ public class ProcessSwitchCollectDataService {
Iterator<Map.Entry<String, JsonNode>> fields = innerJsonNode.fields();
if (fields.hasNext()) {
Map.Entry<String, JsonNode> entry = fields.next();
String fieldName = entry.getKey();
String fieldValue = entry.getValue().asText();
insertData.setCollectType(fieldName);
if (!"null".equals(fieldValue)) {
insertData.setCollectValue(fieldValue);
insertInitialSwitchOtherInfo.insertInitialSwitchOtherCollectData(insertData);
}
collectType = entry.getKey();
collectValue = entry.getValue().asText();
}
}
}else{
if (firstElement.isObject()) {
Iterator<Map.Entry<String, JsonNode>> fields = firstElement.fields();
if (fields.hasNext()) {
Map.Entry<String, JsonNode> entry = fields.next();
String fieldName = entry.getKey();
String fieldValue = entry.getValue().asText();
insertData.setCollectType(fieldName);
if (!"null".equals(fieldValue)) {
insertData.setCollectValue(fieldValue);
insertInitialSwitchOtherInfo.insertInitialSwitchOtherCollectData(insertData);
}
}
} else if (firstElement.isObject()) {
Iterator<Map.Entry<String, JsonNode>> fields = firstElement.fields();
if (fields.hasNext()) {
Map.Entry<String, JsonNode> entry = fields.next();
collectType = entry.getKey();
collectValue = entry.getValue().asText();
}
}
if (collectType != null && !"null".equals(collectValue)) {
// 定义需要先删后插的collectType列表
List<String> specialCollectTypes = Arrays.asList(
"sysDescr",
"sysObjectID",
"sysUpTime",
"sysContact",
"sysName",
"sysLocation",
"hwStackSystemMac",
"entIndex",
"entPhysicalName",
"entPhysicalSoftwareRev"
);
// 如果collectType在特殊列表中,先删除相同clientId和时间范围内的记录
if (specialCollectTypes.contains(collectType)) {
// 创建删除条件对象
InitialSwitchOtherCollectData deleteData = new InitialSwitchOtherCollectData();
deleteData.setClientId(clientId);
deleteData.setCollectType(collectType);
deleteData.setCreateTime(createTime);
// 调用删除方法
insertInitialSwitchOtherInfo.deleteInitialSwitchOtherCollectData(deleteData);
}
// 插入新数据
insertData.setCollectType(collectType);
insertData.setCollectValue(collectValue);
insertInitialSwitchOtherInfo.insertInitialSwitchOtherCollectData(insertData);
}
}
} catch (Exception e) {
@@ -102,4 +102,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
) latest ON t.collect_type = latest.collect_type AND t.create_time = latest.max_time
WHERE t.client_id = #{clientId}
</select>
<delete id="deleteInitialSwitchOtherCollectData" parameterType="Long">
delete from initial_switch_other_collect_data
<where>
<choose>
<when test="clientId != null and collectType != null and createTime != null">
AND client_id = #{clientId}
AND collect_type = #{collectType}
AND create_time &lt; #{createTime}
</when>
<otherwise>
and 1=0
</otherwise>
</choose>
</where>
</delete>
</mapper>
@@ -11,6 +11,7 @@
<result property="frpcServerPort" column="frpc_server_port" />
<result property="frpcRemotePort" column="frpc_remote_port" />
<result property="frpcLocalPort" column="frpc_local_port" />
<result property="frpcType" column="frpc_type" />
<result property="frpcName" column="frpc_name" />
<result property="frpcConnectionStatus" column="frpc_connection_status" />
<result property="frpcCreateTime" column="frpc_create_time" />
@@ -23,7 +24,7 @@
</resultMap>
<sql id="selectRmFrpcConfigManageVo">
select id, client_id, frpc_server_addr, frpc_server_port, frpc_remote_port, frpc_local_port, frpc_name, frpc_connection_status, frpc_create_time, create_time, update_time, create_by, update_by, frpc_local_ip, frpc_status from rm_frpc_config_manage
select id, client_id, frpc_server_addr, frpc_server_port, frpc_remote_port, frpc_local_port, frpc_type, frpc_name, frpc_connection_status, frpc_create_time, create_time, update_time, create_by, update_by, frpc_local_ip, frpc_status from rm_frpc_config_manage
</sql>
<select id="selectRmFrpcConfigManageList" parameterType="RmFrpcConfigManage" resultMap="RmFrpcConfigManageResult">
@@ -64,6 +65,7 @@
<if test="updateBy != null">update_by,</if>
<if test="frpcLocalIp != null">frpc_local_ip,</if>
<if test="frpcStatus != null">frpc_status,</if>
<if test="frpcType != null">frpc_type,</if>
</trim>
<trim prefix="VALUES (" suffix=")" suffixOverrides=",">
<if test="clientId != null">#{clientId},</if>
@@ -80,10 +82,10 @@
<if test="updateBy != null">#{updateBy},</if>
<if test="frpcLocalIp != null">#{frpcLocalIp},</if>
<if test="frpcStatus != null">#{frpcStatus},</if>
<if test="frpcType != null">#{frpcType},</if>
</trim>
ON DUPLICATE KEY UPDATE
<trim suffixOverrides=",">
<if test="clientId != null">client_id = VALUES(client_id),</if>
<if test="frpcServerAddr != null">frpc_server_addr = VALUES(frpc_server_addr),</if>
<if test="frpcServerPort != null">frpc_server_port = VALUES(frpc_server_port),</if>
<if test="frpcRemotePort != null">frpc_remote_port = VALUES(frpc_remote_port),</if>
@@ -91,11 +93,11 @@
<if test="frpcName != null">frpc_name = VALUES(frpc_name),</if>
<if test="frpcConnectionStatus != null">frpc_connection_status = VALUES(frpc_connection_status),</if>
<if test="frpcCreateTime != null">frpc_create_time = VALUES(frpc_create_time),</if>
<!-- 通常更新时间字段在更新时会设置为当前时间 -->
update_time = NOW(),
<if test="updateTime != null">update_time = VALUES(update_time),</if>
<if test="updateBy != null">update_by = VALUES(update_by),</if>
<if test="frpcLocalIp != null">frpc_local_ip = VALUES(frpc_local_ip),</if>
<if test="frpcStatus != null">frpc_status = VALUES(frpc_status),</if>
<if test="frpcType != null">frpc_type = VALUES(frpc_type),</if>
</trim>
</insert>
@@ -116,6 +118,7 @@
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="frpcLocalIp != null">frpc_local_ip = #{frpcLocalIp},</if>
<if test="frpcStatus != null">frpc_status = #{frpcStatus},</if>
<if test="frpcType != null">frpc_type = #{frpcType},</if>
</trim>
where id = #{id}
</update>