kongdeqiang
2025-12-02 7a2e82325091a39c32cf9940d0016178a3655dc9
大屏接口修改
7个文件已修改
113 ■■■■■ 已修改文件
pom.xml 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/wgcloud/service/OspfInfoService.java 57 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/wgcloud/service/RouterConnectionService.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/wgcloud/task/DataScheduledTask.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/wgcloud/task/ScheduledTask.java 19 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/application.yml 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
wgcloud-server.iml 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pom.xml
@@ -78,6 +78,11 @@
            <artifactId>lombok</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.83</version>
        </dependency>
        <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-all</artifactId>
            <version>5.6.5</version>
@@ -229,4 +234,4 @@
    </build>
</project>
</project>
src/main/java/com/wgcloud/service/OspfInfoService.java
@@ -1,5 +1,7 @@
package com.wgcloud.service;
import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.TypeReference;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wgcloud.entity.OspfErrorLog;
@@ -15,7 +17,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSON;
import java.util.HashMap;
import java.util.List;
@@ -38,6 +42,11 @@
    private OspfNeighborUtil ospfNeighborUtil;
    @Autowired
    private OspfErrorLogMapper errorLogMapper;
    @Value("${osfService.host}")
    private String remoteHost;
    @Value("${osfService.port}")
    private String remotePort;
    private static final Logger logger = LoggerFactory.getLogger(OspfInfoService.class);
@@ -78,27 +87,6 @@
        OspfInfoMapper.updateById(ospfInfo);
    }
//    public boolean checkOspfStatus() {
//        String command = "display ospf brief";
//        String output = routerConnectionService.executeCommand(command);
//
//        if (output == null) {
//            return false;
//        }
//
//        // 检查输出中是否包含OSPF相关信息
//        boolean containsRouterId = StringUtils.containsIgnoreCase(output, "Router ID");
//        boolean containsArea = StringUtils.containsIgnoreCase(output, "Area");
//        boolean containsProcessId = StringUtils.containsIgnoreCase(output, "Process ID");
//
//        // 检查是否有错误信息
//        boolean containsError = StringUtils.containsIgnoreCase(output, "Error") ||
//                StringUtils.containsIgnoreCase(output, "Fail") ||
//                StringUtils.containsIgnoreCase(output, "Invalid");
//
//        return (containsRouterId && containsArea && containsProcessId) && !containsError;
//    }
    /**
     * 获取详细的OSPF邻居信息
     */
@@ -107,6 +95,7 @@
        for (OspfInfo ospfInfo : ospfInfos) {
            String command = "display ospf peer "+ospfInfo.getHostname();
            String result =  routerConnectionService.executeCommand(command,ospfInfo.getMonitorUsername(),ospfInfo.getMonitorPassword(),ospfInfo.getMonitorIp());
            System.out.println("获取到的邻居信息为:"+result);
            if(StringUtils.isNotBlank(result)){
                List<OspfNeighbor> neighbors = ospfNeighborUtil.analysisStr(result);
                if(neighbors != null || neighbors.size()>0){
@@ -144,6 +133,32 @@
        }
    }
    public void getRouterStatus() {
        List<OspfInfo> ospfInfos = OspfInfoMapper.selectAllByParams(null);
        for (OspfInfo ospfInfo : ospfInfos) {
            String command = "display ospf peer "+ospfInfo.getHostname();
            Map<String,String> map = new HashMap<>();
            map.put("command",command);
            map.put("username",ospfInfo.getMonitorUsername());
            map.put("password",ospfInfo.getMonitorPassword());
            map.put("monitorIp",ospfInfo.getMonitorIp());
            String str = JSON.toJSONString(map);
            System.out.println(str);
            try {
                String url = "http://"+remoteHost+":"+remotePort+"/api/connect/getResult";
                String responseBody = HttpRequest.post(url)
                        .timeout(5000)
                        .body(str)
                        .execute()
                        .body();
                System.out.println(responseBody);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    /**
     * 获取OSPF接口状态
     */
src/main/java/com/wgcloud/service/RouterConnectionService.java
@@ -82,10 +82,13 @@
     * 执行路由器命令
     */
    public String executeCommand(String command,String username,String password,String hostname) {
        if (!isConnected()) {
            if (!connect(username,hostname,password)) {
                return null;
            }
//        if (!isConnected()) {
//            if (!connect(username,hostname,password)) {
//                return null;
//            }
//        }
        if (!connect(username,hostname,password)) {
            return null;
        }
        try {
@@ -101,6 +104,7 @@
            reader.close();
            channel.disconnect();
            disconnect();
            return output.toString();
        } catch (Exception e) {
            System.err.println("执行命令失败: " + e.getMessage());
src/main/java/com/wgcloud/task/DataScheduledTask.java
@@ -97,7 +97,7 @@
     * 29秒后执行,之后每隔29秒执行, 单位:ms。
     * 批量提交数据
     */
    @Scheduled(initialDelay = 29000L, fixedRate = 29 * 1000)
    //@Scheduled(initialDelay = 29000L, fixedRate = 29 * 1000)
    public synchronized void commitTask() {
        if (DateUtil.isClearTime()) {
            logger.info("正在清空历史趋势图数据,不执行提交监控数据----------" + DateUtil.getCurrentDateTime());
@@ -470,7 +470,7 @@
     * 每天凌晨8:24:30执行
     * 清理历史数据过程即将结束时,将主机、端口、进程、docker的更新时间刷新为当前时间
     */
    @Scheduled(cron = "30 24 8 * * ?")
    //@Scheduled(cron = "30 24 8 * * ?")
    public void refreshCommitDate() {
        try {
            taskUtilService.refreshCommitDate();
@@ -483,7 +483,7 @@
     * 每天凌晨8:10执行
     * 删除历史趋势图数据,默认15天
     */
    @Scheduled(cron = "0 10 8 * * ?")
    //@Scheduled(cron = "0 10 8 * * ?")
    public void clearHisdataTask() {
        if (!StaticKeys.NODE_MASTER.equals(commonConfig.getNodeType())) {
            logger.info("slave节点不执行清空历史趋势图数据任务");
src/main/java/com/wgcloud/task/ScheduledTask.java
@@ -78,13 +78,14 @@
    private ServletContext servletContext;
    /**
     * 30秒后执行,每2分钟检测一次
     * 30秒后执行,每1分钟检测一次
     * 检测ospf状态
     */
    @Scheduled(initialDelay = 30000L, fixedRate = 2 * 60 * 1000)
    public void ospfDownCheckTask() {
        logger.info("ospfDownCheckTask------------" + DateUtil.getDateTimeString(new Date()));
        logger.info("ospf链路检测任务开始------------" + DateUtil.getDateTimeString(new Date()));
        ospfInfoService.getDetailedOspfNeighborInfo();
        logger.info("ospf链路检测任务结束------------" + DateUtil.getDateTimeString(new Date()));
    }
    /**
@@ -124,7 +125,7 @@
     * 20秒后执行,之后每6分钟刷新一次
     * 初始化一些任务
     */
    @Scheduled(initialDelay = 20000L, fixedRate = 6 * 60 * 1000)
    //@Scheduled(initialDelay = 20000L, fixedRate = 6 * 60 * 1000)
    public void initTask() {
        logger.info("initTask------------" + DateUtil.getDateTimeString(new Date()));
        try {
@@ -160,7 +161,7 @@
     * 15秒后执行,之后每小时刷新一次
     * 获取所有磁盘总容量之和,缓存起来
     */
    @Scheduled(initialDelay = 15000L, fixedRate = 60 * 60 * 1000)
    //@Scheduled(initialDelay = 15000L, fixedRate = 60 * 60 * 1000)
    public void sumDiskSizeCacheTask() {
        logger.info("sumDiskSizeCacheTask------------" + DateUtil.getDateTimeString(new Date()));
        try {
@@ -174,7 +175,7 @@
     * 150秒后执行,之后每隔15分钟执行, 单位:ms。
     * snmp设备监测
     */
    @Scheduled(initialDelay = 150000L, fixedRateString = "${base.snmpTimes}" + "000")
    //@Scheduled(initialDelay = 150000L, fixedRateString = "${base.snmpTimes}" + "000")
    public void snmpInfoTask() {
        if (!StaticKeys.NODE_MASTER.equals(commonConfig.getNodeType())) {
            logger.info("slave节点不执行snmp设备监测任务");
@@ -211,7 +212,7 @@
     * 60秒后执行,之后每隔10分钟执行, 单位:ms。
     * 检测服务接口
     */
    @Scheduled(initialDelay = 60000L, fixedRateString = "${base.heathTimes}" + "000")
    //@Scheduled(initialDelay = 60000L, fixedRateString = "${base.heathTimes}" + "000")
    public void heathMonitorTask() {
        if (!StaticKeys.NODE_MASTER.equals(commonConfig.getNodeType())) {
            logger.info("slave节点不执行检测服务接口任务");
@@ -247,7 +248,7 @@
     * 90秒后执行,之后每隔15分钟执行, 单位:ms。
     * 检测数通PING设备
     */
    @Scheduled(initialDelay = 90000L, fixedRateString = "${base.dceTimes}" + "000")
    //@Scheduled(initialDelay = 90000L, fixedRateString = "${base.dceTimes}" + "000")
    public void dceInfoTask() {
        if (!StaticKeys.NODE_MASTER.equals(commonConfig.getNodeType())) {
            logger.info("slave节点不执行检测数通设备PING任务");
@@ -283,7 +284,7 @@
     * 120秒后执行,之后每隔120分钟执行, 单位:ms。
     * 数据表监控
     */
    @Scheduled(initialDelay = 120000L, fixedRateString = "${base.dbTableTimes}" + "000")
    //@Scheduled(initialDelay = 120000L, fixedRateString = "${base.dbTableTimes}" + "000")
    public void tableCountTask() {
        if (!StaticKeys.NODE_MASTER.equals(commonConfig.getNodeType())) {
            logger.info("slave节点不执行数据表监控任务");
@@ -302,7 +303,7 @@
     * 300秒后执行,每6分钟检测一次
     * 检测主机是否已经下线,检测进程、端口、docker、文件防篡改是否恢复
     */
    @Scheduled(initialDelay = 300000L, fixedRate = 5 * 60 * 1000)
    //@Scheduled(initialDelay = 300000L, fixedRate = 5 * 60 * 1000)
    public void hostDownCheckTask() {
        if (!StaticKeys.NODE_MASTER.equals(commonConfig.getNodeType())) {
            logger.info("slave节点不执行检测主机/进程/docker/端口是否恢复任务");
src/main/resources/application.yml
@@ -1,5 +1,5 @@
server:
  port: 10001
  port: 8889
  servlet:
    session:
      timeout: 120m
@@ -14,7 +14,7 @@
    name: wgcloud-server
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/wgcloud?characterEncoding=utf-8&characterSetResults=utf8&autoReconnect=true&useSSL=false&allowMultiQueries=true&allowPublicKeyRetrieval=true
    url: jdbc:mysql://120.1.33.103:10001/wgcloud?characterEncoding=utf-8&characterSetResults=utf8&autoReconnect=true&useSSL=false&allowMultiQueries=true&allowPublicKeyRetrieval=true
    username: root
    password: rootroot
    # hikari连接池的参数 相关设置
@@ -209,9 +209,8 @@
  varDatas: /collect/api/realData/varDatas
  alarm: /collect/api/alarm/findByPage
router:
  host: 192.168.1.1
  username: xxxxx
  password: xxxxx
osfService:
  host: 127.0.0.1
  port: 8081
wgcloud-server.iml
@@ -56,6 +56,7 @@
    <orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.14.0-rc3" level="project" />
    <orderEntry type="library" name="Maven: com.fasterxml.jackson.module:jackson-module-parameter-names:2.14.0-rc3" level="project" />
    <orderEntry type="library" name="Maven: org.projectlombok:lombok:1.18.22" level="project" />
    <orderEntry type="library" name="Maven: com.alibaba:fastjson:1.2.83" level="project" />
    <orderEntry type="library" name="Maven: cn.hutool:hutool-all:5.6.5" level="project" />
    <orderEntry type="library" name="Maven: mysql:mysql-connector-java:8.0.28" level="project" />
    <orderEntry type="library" name="Maven: org.mariadb.jdbc:mariadb-java-client:2.7.3" level="project" />