修复网卡信息有变动saas平台未及时更新、脚本策略下发未返回结果bug。

优化mtr探测策略
This commit is contained in:
gaoyutao
2025-11-26 18:13:26 +08:00
parent afbf1eead0
commit 31e1f7f8dc
13 changed files with 65 additions and 49 deletions
@@ -20,6 +20,6 @@ public class TongRanMtragentApplication
public static void main(String[] args)
{
SpringApplication.run(TongRanMtragentApplication.class, args);
System.out.println("(♥◠‿◠)ノ゙ RuoYiMtragent模块启动成功 ლ(´ڡ`ლ)゙");
System.out.println("(♥◠‿◠)ノ゙ TongRanMtragent模块启动成功 ლ(´ڡ`ლ)゙");
}
}
@@ -60,4 +60,6 @@ public class RmMtrPolicyConfig extends BaseEntity
private Long probeFrequency;
/** clientId和ip对应集合 */
private Map<String, List<String>> clientIdToIpsMap;
/** 查询条件 */
private String queryName;
}
@@ -230,27 +230,28 @@ public class MessageHandler {
RegisterMsgVo registerMsgVo = interfaces.get(0);
String mtrClientId = registerMsgVo.getClientId();
List<RmMtrPolicyConfig> mtrPolicyConfigList = rmMtrPolicyConfigService.getPoliciesForMtrClient(mtrClientId);
if(mtrPolicyConfigList != null && !mtrPolicyConfigList.isEmpty()){
// 构建mtrclient消息
String mtrPolicyListStr = JSONObject.toJSONString(mtrPolicyConfigList);
PolicyTypeVo policyTypeVo = new PolicyTypeVo();
policyTypeVo.setMtrPolicys(mtrPolicyListStr);
String configJson = JSONObject.toJSONString(policyTypeVo);
try {
DeviceMessage message = new DeviceMessage();
message.setClientId(mtrClientId);
message.setData(configJson);
message.setDataType(MsgEnum.获取最新策略应答.getValue());
if(mtrPolicyConfigList == null){
mtrPolicyConfigList = new ArrayList<>();
}
// 构建mtrclient消息
String mtrPolicyListStr = JSONObject.toJSONString(mtrPolicyConfigList);
PolicyTypeVo policyTypeVo = new PolicyTypeVo();
policyTypeVo.setMtrPolicys(mtrPolicyListStr);
String configJson = JSONObject.toJSONString(policyTypeVo);
try {
DeviceMessage message = new DeviceMessage();
message.setClientId(mtrClientId);
message.setData(configJson);
message.setDataType(MsgEnum.获取最新策略应答.getValue());
messageProducer.sendAsyncProducerMessage(
producerMode.getAgentTopic(),
"",
"",
JSONObject.toJSONString(message)
);
} catch (Exception e) {
log.error("发送mtr策略失败,mtrClientId: {}", mtrClientId, e);
}
messageProducer.sendAsyncProducerMessage(
producerMode.getAgentTopic(),
"",
"",
JSONObject.toJSONString(message)
);
} catch (Exception e) {
log.error("发送mtr策略失败,mtrClientId: {}", mtrClientId, e);
}
}
}
@@ -189,9 +189,8 @@ public class RmMtrPolicyConfigServiceImpl implements IRmMtrPolicyConfigService
return result;
}
// 查询所有有效的策略(探测标志为1
// 查询所有策略
RmMtrPolicyConfig query = new RmMtrPolicyConfig();
query.setProbeFlag(1L); // 只查询启用探测的策略
List<RmMtrPolicyConfig> allPolicies = rmMtrPolicyConfigMapper.selectRmMtrPolicyConfigList(query);
if (allPolicies == null || allPolicies.isEmpty()) {
@@ -14,8 +14,7 @@ spring:
nacos:
discovery:
# 服务注册地址
server-addr: 172.16.15.52:8848
# server-addr: 172.16.15.103:8848
server-addr: ${spring.cloud.nacos.config.server-addr}
namespace: ${spring.cloud.nacos.config.namespace}
username: ${spring.cloud.nacos.config.username}
password: ${spring.cloud.nacos.config.password}
@@ -37,6 +37,9 @@
<if test="startTime != null "> and start_time = #{startTime}</if>
<if test="endTime != null "> and end_time = #{endTime}</if>
<if test="probeFrequency != null "> and probe_frequency = #{probeFrequency}</if>
<if test="queryName != null "> and (policy_name like concat('%', #{queryName}, '%')
or mtr_client_id like concat('%', #{queryName}, '%') or server_group like concat('%', #{queryName}, '%')
)</if>
</where>
</select>
@@ -143,6 +143,6 @@
<if test="bindIp != null">bind_ip = #{bindIp},</if>
<if test="newFlag != null">new_flag = #{newFlag},</if>
</trim>
where mac_address = #{macAddress} and clientId = #{clientId}
where mac_address = #{macAddress} and client_id = #{clientId}
</update>
</mapper>
@@ -68,7 +68,7 @@ public class SysMenuClickServiceImpl implements ISysMenuClickService
* 获取当前用户有权限的菜单
*/
private List<SysMenu> getPermittedMenusForCurrentUser() {
// 使用Ruoyi的权限服务(推荐)
// 使用TongRan的权限服务(推荐)
if (SecurityUtils.getLoginUser() != null) {
Long userId = SecurityUtils.getUserId();
return sysMenuService.getMenuListByWelcome(userId);
@@ -18,11 +18,11 @@ spring:
username: ${spring.cloud.nacos.config.username}
password: ${spring.cloud.nacos.config.password}
config:
server-addr: 172.16.15.52:8848
# 配置中心地址
server-addr: 172.16.15.52:8848
# server-addr: 172.16.15.103:8848
# namespace: public
namespace: saas-local
# namespace: public
username: nacos
password: nacos
# 配置文件格式
@@ -41,4 +41,11 @@ public class RmAlarmLog extends BaseEntity
/** 告警内容 */
@Excel(name = "告警内容")
private String alarmContent;
/** 业务名称 */
@Excel(name = "业务名称")
private String businessName;
/** 推送标志(0失败,1成功,3未配置消息推送机制) */
@Excel(name = "推送标志", readConverterExp = "0=失败,1=成功,3=未配置消息推送机制")
private Long pushFlag;
}
@@ -1198,6 +1198,10 @@ public class MessageHandler {
rmAlarmLog.setMgmPublicIp(networkInterface.getPublicIp());
});
}
// 查询业务名称
RmResourceRegistrationRemote query = new RmResourceRegistrationRemote();
query.setClientId(clientId);
R<RmResourceRegistrationRemote> registrationR = remoteRevenueConfigService.getListByHardwareSn(query, SecurityConstants.INNER);
rmAlarmLog.setClientId(clientId);
rmAlarmLog.setAlarmType("1");
}
@@ -1283,7 +1287,7 @@ public class MessageHandler {
if(businessScriptMsgR != null && businessScriptMsgR.getData() != null){
EpsBusinessScriptRemote businessScriptMsg = businessScriptMsgR.getData();
String failedKeywords = businessScriptMsg.getFailedKeywords();
if(resOut.contains(failedKeywords)){
if(failedKeywords != null && resOut.contains(failedKeywords)){
insertData.setResultFlag(0);
}else {
insertData.setResultFlag(1);
@@ -3,7 +3,7 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tongran.rocketmq.mapper.RmAlarmLogMapper">
<resultMap type="RmAlarmLog" id="RmAlarmLogResult">
<result property="id" column="id" />
<result property="clientId" column="client_id" />
@@ -11,6 +11,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="mgmPublicIp" column="mgm_public_ip" />
<result property="alarmType" column="alarm_type" />
<result property="alarmContent" column="alarm_content" />
<result property="businessName" column="business_name" />
<result property="pushFlag" column="push_flag" />
<result property="createTime" column="create_time" />
<result property="updateTime" column="update_time" />
<result property="createBy" column="create_by" />
@@ -18,17 +20,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectRmAlarmLogVo">
select id, client_id, alarm_time, mgm_public_ip, alarm_type, alarm_content, create_time, update_time, create_by, update_by from rm_alarm_log
select id, client_id, alarm_time, mgm_public_ip, alarm_type, alarm_content, business_name, push_flag, create_time, update_time, create_by, update_by from rm_alarm_log
</sql>
<select id="selectRmAlarmLogList" parameterType="RmAlarmLog" resultMap="RmAlarmLogResult">
<include refid="selectRmAlarmLogVo"/>
<where>
<where>
<if test="clientId != null and clientId != ''"> and client_id = #{clientId}</if>
<if test="alarmTime != null "> and alarm_time = #{alarmTime}</if>
<if test="mgmPublicIp != null and mgmPublicIp != ''"> and mgm_public_ip = #{mgmPublicIp}</if>
<if test="alarmType != null and alarmType != ''"> and alarm_type = #{alarmType}</if>
<if test="alarmContent != null and alarmContent != ''"> and alarm_content = #{alarmContent}</if>
<if test="businessName != null and businessName != ''"> and business_name like concat('%', #{businessName}, '%')</if>
<if test="pushFlag != null "> and push_flag = #{pushFlag}</if>
</where>
order by alarm_time desc
</select>
@@ -46,47 +50,44 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="mgmPublicIp != null">mgm_public_ip,</if>
<if test="alarmType != null">alarm_type,</if>
<if test="alarmContent != null">alarm_content,</if>
<if test="businessName != null">business_name,</if>
<if test="pushFlag != null">push_flag,</if>
<if test="createTime != null">create_time,</if>
<if test="updateTime != null">update_time,</if>
<if test="createBy != null">create_by,</if>
<if test="updateBy != null">update_by,</if>
</trim>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="clientId != null and clientId != ''">#{clientId},</if>
<if test="alarmTime != null">#{alarmTime},</if>
<if test="mgmPublicIp != null">#{mgmPublicIp},</if>
<if test="alarmType != null">#{alarmType},</if>
<if test="alarmContent != null">#{alarmContent},</if>
<if test="businessName != null">#{businessName},</if>
<if test="pushFlag != null">#{pushFlag},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="createBy != null">#{createBy},</if>
<if test="updateBy != null">#{updateBy},</if>
</trim>
</trim>
</insert>
<update id="updateRmAlarmLog" parameterType="RmAlarmLog">
update rm_alarm_log
<trim prefix="SET" suffixOverrides=",">
<if test="clientId != null and clientId != ''">client_id = #{clientId},</if>
<if test="alarmTime != null">alarm_time = #{alarmTime},</if>
<if test="mgmPublicIp != null">mgm_public_ip = #{mgmPublicIp},</if>
<if test="alarmType != null">alarm_type = #{alarmType},</if>
<if test="alarmContent != null">alarm_content = #{alarmContent},</if>
<if test="businessName != null">business_name = #{businessName},</if>
<if test="pushFlag != null">push_flag = #{pushFlag},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
</trim>
<where>
<choose>
<when test="id != null">
and id = #[id]
</when>
<when test="clientId != null and alarmType != null">
and client_id = #{clientId} and alarm_type = #{alarmType}
</when>
<otherwise>
and 1=0
</otherwise>
</choose>
</where>
where id = #{id}
</update>
<delete id="deleteRmAlarmLogById" parameterType="Long">
@@ -150,6 +150,6 @@
<if test="bindIp != null">bind_ip = #{bindIp},</if>
<if test="newFlag != null">new_flag = #{newFlag},</if>
</trim>
where mac_address = #{macAddress} and clientId = #{clientId}
where mac_address = #{macAddress} and client_id = #{clientId}
</update>
</mapper>