REM:
1.增加华为设备能力接口
2.增加华为处置设备类型
This commit is contained in:
chenlinghy 2020-11-16 17:35:17 +08:00
parent 80a0e5c0db
commit 6781d98a6d
2 changed files with 218 additions and 2 deletions

View File

@ -0,0 +1,214 @@
package com.dispose.ability.impl;
import com.dispose.ability.DisposeAbility;
import cn.hutool.http.HttpResponse;
import com.dispose.common.DisposeCapacityType;
import com.dispose.common.DisposeObjectType;
import com.dispose.common.ErrorCode;
import com.dispose.common.NetflowDirection;
import com.dispose.pojo.po.MulReturnType;
import com.dispose.pojo.vo.DeviceFirewareInfo;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.huawei.dispose.common.HuaWeiLoginResp;
import com.huawei.dispose.protocol.HuaWeiInterface;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.annotation.Nullable;
import javax.servlet.http.HttpServletResponse;
@Component
@Slf4j
public class HuaWeiAbilityImpl implements DisposeAbility {
/**
* The Restful interface.
*/
private final HuaWeiInterface restfulInterface = new HuaWeiInterface();
/**
* The constant OBJECT_MAPPER.
*/
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
/**
* The Url root path.
*/
@Getter
@Setter
private String urlRootPath;
/**
* The Username.
*/
@Getter
@Setter
private String username;
/**
* The Password.
*/
@Getter
@Setter
private String password;
/**
* The Token.
*/
private String token;
/**
* Init device env.
*
* @param urlPath the url path
* @param username the username
* @param password the password
*/
@Override
public void initDeviceEnv(String urlPath, String username, String password) {
this.urlRootPath = urlPath;
this.username = username;
this.password = password;
upgradeToken();
}
/**
* Run dispose mul return type.
*
* @param disposeObject the dispose object
* @param objectType the object type
* @param capType the cap type
* @param nfDirection the nf direction
* @param attackType the attack type
* @param duration the duration
* @return the mul return type
*/
@Override
public MulReturnType<ErrorCode, String> runDispose(String disposeObject, DisposeObjectType objectType,
DisposeCapacityType capType,
@Nullable NetflowDirection nfDirection,
@Nullable Integer attackType,
@Nullable Long duration) {
return null;
}
/**
* Stop dispose mul return type.
*
* @param disposeObject the dispose object
* @param capType the cap type
* @param nfDirection the nf direction
* @param attackType the attack type
* @param taskId the task id
* @return the mul return type
*/
@Override
public MulReturnType<ErrorCode, Long> stopDispose(String disposeObject, DisposeCapacityType capType,
@Nullable NetflowDirection nfDirection,
@Nullable Integer attackType,
@Nullable String taskId) {
return null;
}
/**
* Task status mul return type.
*
* @param taskId the task id
* @return the mul return type
*/
@Override
public MulReturnType<ErrorCode, Long> taskStatus(String taskId) {
return null;
}
/**
* Gets ability device fireware.
*
* @return the ability device fireware
*/
@Override
public MulReturnType<ErrorCode, DeviceFirewareInfo> getAbilityDeviceFireware() {
return new MulReturnType<>(ErrorCode.ERR_OK,
DeviceFirewareInfo.builder()
.vendor("HuaWei")
.model("Unknown")
.firmware("Unknown")
.os("Linux Server")
.kernel("Linux")
.arch("x86_64")
.version("Unknown")
.memory(-1)
.freeMemory(-1)
.cpuUsed(-1)
.build());
}
/**
* To device attack type long.
*
* @param ddosAttackTypeMask the ddos attack type mask
* @return the long
*/
@Override
public Long toDeviceAttackType(Long ddosAttackTypeMask) {
return ddosAttackTypeMask;
}
/**
* Gets device link status.
*
* @return the device link status
*/
@Override
public boolean getDeviceLinkStatus() {
try {
//查询所有的zone接口调用成功认为设备心跳正常
//return (restfulInterface.queryAllZones(this.urlRootPath, token) != null);
return true;
} catch (Exception ex) {
log.error(ex.getMessage());
}
return false;
}
/**
* Gets dispose device protect object.
*/
@Override
public void getDisposeDeviceProtectObject() {
}
/**
* Is carry protect ip boolean.
*
* @param ipAddr the ip addr
* @return the boolean
*/
@Override
public boolean isCarryProtectIp(String ipAddr) {
return true;
}
/**
* Upgrade token.
*/
private void upgradeToken() {
try {
HttpResponse resp = restfulInterface.auth(this.urlRootPath, username, password);
if (resp != null) {
if (resp.getStatus() == HttpServletResponse.SC_OK && resp.body() != null) {
HuaWeiLoginResp logInfo = OBJECT_MAPPER.readValue(resp.body(), HuaWeiLoginResp.class);
this.token = logInfo.getToken();
}
}
} catch (Exception ignored) {
}
}
}

View File

@ -14,12 +14,14 @@ public enum DisposeDeviceType implements BaseEnum {
* The Haohan platform. * The Haohan platform.
*/ */
HAOHAN_PLATFORM(1, "浩瀚处置设备"), HAOHAN_PLATFORM(1, "浩瀚处置设备"),
/** /**
* The Pengxin platform. * The Pengxin platform.
*/ */
PENGXIN_PLATFORM(2, "鹏信处置设备"), PENGXIN_PLATFORM(2, "鹏信处置设备"),
/**
* The HuaWei platform.
*/
HUAWEI_PLATFORM(3, "华为处置设备"),
/** /**
* The Virtual dispose. * The Virtual dispose.
*/ */