diff --git a/src/main/java/com/dispose/ability/DisposeAbility.java b/src/main/java/com/dispose/ability/DisposeAbility.java index 373e855d..a9092342 100644 --- a/src/main/java/com/dispose/ability/DisposeAbility.java +++ b/src/main/java/com/dispose/ability/DisposeAbility.java @@ -5,6 +5,7 @@ import com.dispose.common.DisposeCapacityType; import com.dispose.common.ErrorCode; import com.dispose.common.NetflowDirection; import com.dispose.pojo.po.MulReturnType; +import com.dispose.pojo.vo.DeviceFirewareInfo; import javax.annotation.Nullable; @@ -54,6 +55,13 @@ public interface DisposeAbility { @Nullable DDoSAttackType[] attackType, @Nullable Long taskId); + /** + * Gets ability device fireware. + * + * @return the ability device fireware + */ + MulReturnType getAbilityDeviceFireware(); + /** * Gets device link status. diff --git a/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java b/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java index 42e00f13..9af92c86 100644 --- a/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/DpTechAbilityImpl.java @@ -8,6 +8,7 @@ import com.dispose.common.DpTechConfigValue; import com.dispose.common.ErrorCode; import com.dispose.common.NetflowDirection; import com.dispose.pojo.po.MulReturnType; +import com.dispose.pojo.vo.DeviceFirewareInfo; import com.dptech.dispose.AbnormalFlowCleaningServicePortType; import lombok.extern.slf4j.Slf4j; import org.apache.cxf.endpoint.Client; @@ -210,4 +211,26 @@ public class DpTechAbilityImpl implements DisposeAbility { return false; } + + /** + * Gets ability device fireware. + * + * @return the ability device fireware + */ + @Override + public MulReturnType getAbilityDeviceFireware() { + return new MulReturnType<>(ErrorCode.ERR_OK, + DeviceFirewareInfo.builder() + .vendor("DpTech") + .model("UMC") + .firmware("Unknown") + .os("Windows Server") + .kernel("Windows") + .arch("x86_64") + .version("5.7.31") + .memory(-1) + .freeMemory(-1) + .cpuUsed(-1) + .build()); + } } diff --git a/src/main/java/com/dispose/ability/impl/HaoHanAbilityImpl.java b/src/main/java/com/dispose/ability/impl/HaoHanAbilityImpl.java index 95a4602c..8ae0f4d1 100644 --- a/src/main/java/com/dispose/ability/impl/HaoHanAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/HaoHanAbilityImpl.java @@ -6,6 +6,7 @@ import com.dispose.common.DisposeCapacityType; import com.dispose.common.ErrorCode; import com.dispose.common.NetflowDirection; import com.dispose.pojo.po.MulReturnType; +import com.dispose.pojo.vo.DeviceFirewareInfo; import com.haohan.dispose.common.HaoHanStartCleanResp; import com.haohan.dispose.common.HaoHanStopCleanResp; import com.haohan.dispose.protocol.RestfulInterface; @@ -130,4 +131,26 @@ public class HaoHanAbilityImpl implements DisposeAbility { // 获取任务信息接口调用成功认为设备心跳正常 return (restfulInterface.getCleanTaskStatus(this.urlRootPath, -1) != null); } + + /** + * Gets ability device fireware. + * + * @return the ability device fireware + */ + @Override + public MulReturnType getAbilityDeviceFireware() { + return new MulReturnType<>(ErrorCode.ERR_OK, + DeviceFirewareInfo.builder() + .vendor("HaoHan") + .model("Unknown") + .firmware("Unknown") + .os("Linux Server") + .kernel("Linux") + .arch("x86_64") + .version("Unknown") + .memory(-1) + .freeMemory(-1) + .cpuUsed(-1) + .build()); + } } diff --git a/src/main/java/com/dispose/ability/impl/VirtualAbilityImpl.java b/src/main/java/com/dispose/ability/impl/VirtualAbilityImpl.java index 4c1dbcad..7500c00a 100644 --- a/src/main/java/com/dispose/ability/impl/VirtualAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/VirtualAbilityImpl.java @@ -6,6 +6,7 @@ import com.dispose.common.DisposeCapacityType; import com.dispose.common.ErrorCode; import com.dispose.common.NetflowDirection; import com.dispose.pojo.po.MulReturnType; +import com.dispose.pojo.vo.DeviceFirewareInfo; import javax.annotation.Nullable; @@ -63,6 +64,28 @@ public class VirtualAbilityImpl implements DisposeAbility { return new MulReturnType<>(ErrorCode.ERR_OK, null); } + /** + * Gets ability device fireware. + * + * @return the ability device fireware + */ + @Override + public MulReturnType getAbilityDeviceFireware() { + return new MulReturnType<>(ErrorCode.ERR_OK, + DeviceFirewareInfo.builder() + .vendor("Virtual") + .model("Dispose_1000") + .firmware("Unknown") + .os("Unknown") + .kernel("Linux") + .arch("x86_64") + .version("Virtual_Device_2.0") + .memory(-1) + .freeMemory(-1) + .cpuUsed(-1) + .build()); + } + /** * Gets device link status. * diff --git a/src/main/java/com/dispose/common/DDoSAttackType.java b/src/main/java/com/dispose/common/DDoSAttackType.java index 277a2a2b..24fe78d0 100644 --- a/src/main/java/com/dispose/common/DDoSAttackType.java +++ b/src/main/java/com/dispose/common/DDoSAttackType.java @@ -143,7 +143,7 @@ public enum DDoSAttackType implements BaseEnum { */ SENTINEL_AMPLIFICATION ( 33, "SENTINEL_AMPLIFICATION"), /** - * The Fraggle. + * The Fraggle flood. */ FRAGGLE_FLOOD ( 34, "FRAGGLE_FLOOD"), /** @@ -177,7 +177,13 @@ public enum DDoSAttackType implements BaseEnum { /** * The Igmp flood. */ - IGMP_FLOOD ( 42, "IGMP_FLOOD"); + IGMP_FLOOD ( 42, "IGMP_FLOOD"), + + /** + * All attacks d do s attack type. + */ + ALL_ATTACKS (-1, "ALL_ATTACKS"), + ; /** diff --git a/src/main/java/com/dispose/common/DpTechAttackType.java b/src/main/java/com/dispose/common/DpTechAttackType.java index 6c1c3794..2aa85d9f 100644 --- a/src/main/java/com/dispose/common/DpTechAttackType.java +++ b/src/main/java/com/dispose/common/DpTechAttackType.java @@ -1,6 +1,7 @@ package com.dispose.common; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.stream.Stream; @@ -163,8 +164,12 @@ public enum DpTechAttackType implements BaseEnum { attackList.add(ICMP_FLOOD); break; + case ALL_ATTACKS: + attackList.addAll(Arrays.asList(DpTechAttackType.values())); + break; + default: - return attackList.stream(); + break; } return attackList.stream(); diff --git a/src/main/java/com/dispose/manager/DisposeDeviceManager.java b/src/main/java/com/dispose/manager/DisposeDeviceManager.java index 108eb3a3..d985ee3e 100644 --- a/src/main/java/com/dispose/manager/DisposeDeviceManager.java +++ b/src/main/java/com/dispose/manager/DisposeDeviceManager.java @@ -54,5 +54,5 @@ public interface DisposeDeviceManager { * * @return the all dispose devices */ - List getAllDisposeDevices(); + List getAllNormalDisposeDevices(); } diff --git a/src/main/java/com/dispose/manager/impl/DisposeDeviceManagerImpl.java b/src/main/java/com/dispose/manager/impl/DisposeDeviceManagerImpl.java index c30eb69c..be427d36 100644 --- a/src/main/java/com/dispose/manager/impl/DisposeDeviceManagerImpl.java +++ b/src/main/java/com/dispose/manager/impl/DisposeDeviceManagerImpl.java @@ -19,6 +19,7 @@ import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; /** * The type Dispose device manager. @@ -240,13 +241,9 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager { * @return the all dispose devices */ @Override - public List getAllDisposeDevices() { - List devList = disposeDeviceMapper.selectAll(); - - if (devList == null) { - devList = new ArrayList<>(); - } - - return devList; + public List getAllNormalDisposeDevices() { + return disposeDeviceMapper.selectAll().stream() + .filter(v -> v.getStatus() == ObjectStatus.NORMAL) + .collect(Collectors.toList()); } } diff --git a/src/main/java/com/dispose/pojo/po/AbilityInfo.java b/src/main/java/com/dispose/pojo/po/AbilityInfo.java index 6f313672..0a6e9f3d 100644 --- a/src/main/java/com/dispose/pojo/po/AbilityInfo.java +++ b/src/main/java/com/dispose/pojo/po/AbilityInfo.java @@ -2,6 +2,7 @@ package com.dispose.pojo.po; import com.dispose.ability.DisposeAbility; import com.dispose.pojo.entity.DisposeDevice; +import com.dispose.pojo.vo.DeviceFirewareInfo; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -27,6 +28,11 @@ public class AbilityInfo { */ private DisposeDevice dev; + /** + * The Fireware info. + */ + private DeviceFirewareInfo firewareInfo; + /** * The Link status. */ diff --git a/src/main/java/com/dispose/pojo/vo/DeviceFirewareInfo.java b/src/main/java/com/dispose/pojo/vo/DeviceFirewareInfo.java new file mode 100644 index 00000000..a8c55af9 --- /dev/null +++ b/src/main/java/com/dispose/pojo/vo/DeviceFirewareInfo.java @@ -0,0 +1,58 @@ +package com.dispose.pojo.vo; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * The type Device fireware info. + * + * @author + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class DeviceFirewareInfo { + /** + * The Vendor. + */ + private String vendor; + /** + * The Model. + */ + private String model; + /** + * The Firmware. + */ + private String firmware; + /** + * The Os. + */ + private String os; + /** + * The Kernel. + */ + private String kernel; + /** + * The Arch. + */ + private String arch; + /** + * The Version. + */ + private String version; + /** + * The Memory. + */ + private int memory; + /** + * The Free memory. + */ + private int freeMemory; + /** + * The Cpu used. + */ + private int cpuUsed; +} diff --git a/src/main/java/com/dispose/service/impl/DisposeAbilityRouterServiceImpl.java b/src/main/java/com/dispose/service/impl/DisposeAbilityRouterServiceImpl.java index 18f5414d..1a352f14 100644 --- a/src/main/java/com/dispose/service/impl/DisposeAbilityRouterServiceImpl.java +++ b/src/main/java/com/dispose/service/impl/DisposeAbilityRouterServiceImpl.java @@ -43,7 +43,7 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ */ @PostConstruct private void initDisposeAbility() { - List devList = disposeDeviceManager.getAllDisposeDevices(); + List devList = disposeDeviceManager.getAllNormalDisposeDevices(); devList.forEach(this::addDisposeAbilityDevice); } @@ -56,7 +56,7 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ */ @Override public AbilityInfo getAbilityDevice(String ipAddr, String ipPort) { - return disposeAbilityMap.get(getAbilityMapKey(ipAddr, ipPort)); + return disposeAbilityMap.get(getAbilityDeviceHashKey(ipAddr, ipPort)); } /** @@ -80,7 +80,7 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ DisposeAbility db; String httpType = dev.getUrlType() == HttpType.HTTP ? "http://" : "https://"; - String addr = getAbilityMapKey(dev.getIpAddr(), dev.getIpPort()); + String addr = getAbilityDeviceHashKey(dev.getIpAddr(), dev.getIpPort()); String url = httpType + addr + "/" + dev.getUrlPath(); switch (dev.getDeviceType()) { @@ -112,13 +112,13 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ } /** - * Gets ability map key. + * Gets ability device hash key. * * @param ipAddr the ip addr * @param ipPort the ip port - * @return the ability map key + * @return the ability device hash key */ - private String getAbilityMapKey(String ipAddr, String ipPort) { + private String getAbilityDeviceHashKey(String ipAddr, String ipPort) { return (ipPort == null || ipPort.length() == 0) ? ipAddr : (ipAddr + ":" + ipPort); } } diff --git a/src/main/java/com/dispose/setup/SystemInitial.java b/src/main/java/com/dispose/setup/SystemInitial.java index 31c93be2..dfba827a 100644 --- a/src/main/java/com/dispose/setup/SystemInitial.java +++ b/src/main/java/com/dispose/setup/SystemInitial.java @@ -3,11 +3,16 @@ package com.dispose.setup; import com.dispose.common.AuthConfigValue; import com.dispose.common.DisposeConfigValue; import com.dispose.common.DpTechConfigValue; +import com.dispose.common.ErrorCode; import com.dispose.config.AuthConfigure; import com.dispose.config.DisposeConfigure; import com.dispose.config.DpTechConfigure; +import com.dispose.pojo.po.MulReturnType; +import com.dispose.pojo.vo.DeviceFirewareInfo; +import com.dispose.service.DisposeAbilityRouterService; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.CommandLineRunner; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import javax.annotation.Resource; @@ -38,6 +43,12 @@ public class SystemInitial implements CommandLineRunner { @Resource DpTechConfigure dpTechConfigure; + /** + * The Dispose ability router service. + */ + @Resource + private DisposeAbilityRouterService disposeAbilityRouterService; + /** * Load configure. */ @@ -83,6 +94,19 @@ public class SystemInitial implements CommandLineRunner { } } + @Async("bizExecutor") + public void setupAbilityDevice() { + disposeAbilityRouterService.getAllAbilityDevices().forEach(v -> { + v.setLinkStatus(v.getDb().getDeviceLinkStatus()); + MulReturnType ret = v.getDb().getAbilityDeviceFireware(); + + if (ret.getFirstParam() == ErrorCode.ERR_OK) { + v.setFirewareInfo(ret.getSecondParam()); + } + }); + } + + /** * Run. * @@ -92,5 +116,8 @@ public class SystemInitial implements CommandLineRunner { public void run(String... args) { // 系统初始化入口 loadConfigure(); + + // 初始化处置能力设备 + setupAbilityDevice(); } } diff --git a/src/main/java/com/dispose/task/DeviceManagerTask.java b/src/main/java/com/dispose/task/DeviceManagerTask.java index 84ce4f77..31cdb24a 100644 --- a/src/main/java/com/dispose/task/DeviceManagerTask.java +++ b/src/main/java/com/dispose/task/DeviceManagerTask.java @@ -1,5 +1,8 @@ package com.dispose.task; +import com.dispose.common.ErrorCode; +import com.dispose.pojo.po.MulReturnType; +import com.dispose.pojo.vo.DeviceFirewareInfo; import com.dispose.service.DisposeAbilityRouterService; import lombok.extern.slf4j.Slf4j; import org.springframework.scheduling.annotation.Async; @@ -23,15 +26,37 @@ public class DeviceManagerTask { private DisposeAbilityRouterService disposeAbilityRouterService; /** - * Thread pool task. + * Update device link status task. */ @Async("bizExecutor") - @Scheduled(cron = "0/5 * * * * ?") - public void threadPoolTask() { - disposeAbilityRouterService.getAllAbilityDevices().forEach(v -> log.info("{}{} get link status {}", - v.getDev().getIpAddr(), - ((v.getDev().getIpPort() == null || v.getDev().getIpPort().length() == 0) ? - "" : ":" + v.getDev().getIpPort()), - v.getDb().getDeviceLinkStatus())); + @Scheduled(cron = "0/30 * * * * ?") + public void updateDeviceLinkStatusTask() { + disposeAbilityRouterService.getAllAbilityDevices().forEach(v -> { + v.setLinkStatus(v.getDb().getDeviceLinkStatus()); + log.debug("{}{} get link status {}", v.getDev().getIpAddr(), + ((v.getDev().getIpPort() == null || v.getDev().getIpPort().length() == 0) ? "" : + ":" + v.getDev().getIpPort()), + v.isLinkStatus()); + }); + } + + /** + * Update device fireware task. + */ + @Async("bizExecutor") + @Scheduled(cron = "0 */1 * * * ?") + public void updateDeviceFirewareTask() { + disposeAbilityRouterService.getAllAbilityDevices().forEach(v -> { + MulReturnType ret = v.getDb().getAbilityDeviceFireware(); + + if (ret.getFirstParam() == ErrorCode.ERR_OK) { + v.setFirewareInfo(ret.getSecondParam()); + } + + log.debug("{}{} get fireware status {}", v.getDev().getIpAddr(), + ((v.getDev().getIpPort() == null || v.getDev().getIpPort().length() == 0) ? "" : + ":" + v.getDev().getIpPort()), + ret.getFirstParam()); + }); } }