提交 6c622901 authored 作者: wangqiang's avatar wangqiang

install service

上级 73d2dcb6
差异被折叠。
package com.priusis;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.scheduling.annotation.EnableScheduling;
@EnableScheduling
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, SecurityAutoConfiguration.class})
public class ApqClientApplication {
public static void main(String[] args) {
SpringApplication.run(ApqClientApplication.class, args);
}
}
package com.priusis;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.scheduling.annotation.EnableScheduling;
@EnableScheduling
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, SecurityAutoConfiguration.class})
public class ApqClientApplication {
public static void main(String[] args) {
SpringApplication.run(ApqClientApplication.class, args);
}
}
package com.priusis.vo;
import lombok.Data;
import java.io.Serializable;
@Data
public class ApqInfoDataVo implements Serializable {
private String code;
private String name;
private int frequency;
}
package com.priusis.vo;
import lombok.Data;
import java.io.Serializable;
@Data
public class MqttRpcDataMessage implements Serializable {
private static final long serialVersionUID = -3133461476074777891L;
private int requestId;
private String method;
private String params;
@Override
public String toString() {
return "{requestId=" + requestId +
", method=" + method +
", params=" + params +
'}';
}
}
@ECHO OFF
setlocal ENABLEEXTENSIONS
@ECHO Detecting Java version installed.
:CHECK_JAVA_64
@ECHO Detecting if it is 64 bit machine
set KEY_NAME="HKEY_LOCAL_MACHINE\Software\Wow6432Node\JavaSoft\Java Runtime Environment"
set VALUE_NAME=CurrentVersion
FOR /F "usebackq skip=2 tokens=1-3" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName=%%A
set ValueType=%%B
set ValueValue=%%C
)
@ECHO CurrentVersion %ValueValue%
SET KEY_NAME="%KEY_NAME:~1,-1%\%ValueValue%"
SET VALUE_NAME=JavaHome
if defined ValueName (
FOR /F "usebackq skip=2 tokens=1,2*" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName2=%%A
set ValueType2=%%B
set JRE_PATH2=%%C
if defined ValueName2 (
set ValueName = %ValueName2%
set ValueType = %ValueType2%
set ValueValue = %JRE_PATH2%
)
)
)
IF NOT "%JRE_PATH2%" == "" GOTO JAVA_INSTALLED
:CHECK_JAVA_32
@ECHO Detecting if it is 32 bit machine
set KEY_NAME="HKEY_LOCAL_MACHINE\Software\JavaSoft\Java Runtime Environment"
set VALUE_NAME=CurrentVersion
FOR /F "usebackq skip=2 tokens=1-3" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName=%%A
set ValueType=%%B
set ValueValue=%%C
)
@ECHO CurrentVersion %ValueValue%
SET KEY_NAME="%KEY_NAME:~1,-1%\%ValueValue%"
SET VALUE_NAME=JavaHome
if defined ValueName (
FOR /F "usebackq skip=2 tokens=1,2*" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName2=%%A
set ValueType2=%%B
set JRE_PATH2=%%C
if defined ValueName2 (
set ValueName = %ValueName2%
set ValueType = %ValueType2%
set ValueValue = %JRE_PATH2%
)
)
)
IF "%JRE_PATH2%" == "" GOTO JAVA_NOT_INSTALLED
:JAVA_INSTALLED
@ECHO Java 1.8 found!
@ECHO Installing apq-pc-client ...
%~dp0apq-pc-client.exe install
@ECHO runing apq-pc-client ...
%~dp0apq-pc-client.exe start
@ECHO DONE.
GOTO END
:JAVA_NOT_INSTALLED
@ECHO Java 1.8 or above is not installed
@ECHO Please go to https://java.com/ and install Java. Then retry installation.
PAUSE
GOTO END
:END
@ECHO OFF
setlocal ENABLEEXTENSIONS
@ECHO Detecting Java version installed.
:CHECK_JAVA_64
@ECHO Detecting if it is 64 bit machine
set KEY_NAME="HKEY_LOCAL_MACHINE\Software\Wow6432Node\JavaSoft\Java Runtime Environment"
set VALUE_NAME=CurrentVersion
FOR /F "usebackq skip=2 tokens=1-3" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName=%%A
set ValueType=%%B
set ValueValue=%%C
)
@ECHO CurrentVersion %ValueValue%
SET KEY_NAME="%KEY_NAME:~1,-1%\%ValueValue%"
SET VALUE_NAME=JavaHome
if defined ValueName (
FOR /F "usebackq skip=2 tokens=1,2*" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName2=%%A
set ValueType2=%%B
set JRE_PATH2=%%C
if defined ValueName2 (
set ValueName = %ValueName2%
set ValueType = %ValueType2%
set ValueValue = %JRE_PATH2%
)
)
)
IF NOT "%JRE_PATH2%" == "" GOTO JAVA_INSTALLED
:CHECK_JAVA_32
@ECHO Detecting if it is 32 bit machine
set KEY_NAME="HKEY_LOCAL_MACHINE\Software\JavaSoft\Java Runtime Environment"
set VALUE_NAME=CurrentVersion
FOR /F "usebackq skip=2 tokens=1-3" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName=%%A
set ValueType=%%B
set ValueValue=%%C
)
@ECHO CurrentVersion %ValueValue%
SET KEY_NAME="%KEY_NAME:~1,-1%\%ValueValue%"
SET VALUE_NAME=JavaHome
if defined ValueName (
FOR /F "usebackq skip=2 tokens=1,2*" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName2=%%A
set ValueType2=%%B
set JRE_PATH2=%%C
if defined ValueName2 (
set ValueName = %ValueName2%
set ValueType = %ValueType2%
set ValueValue = %JRE_PATH2%
)
)
)
IF "%JRE_PATH2%" == "" GOTO JAVA_NOT_INSTALLED
:JAVA_INSTALLED
@ECHO Java 1.8 found!
@ECHO Installing apq-pc-client ...
%~dp0apq-pc-client.exe install
@ECHO running apq-pc-client ...
%~dp0apq-pc-client.exe start
@ECHO DONE.
GOTO END
:JAVA_NOT_INSTALLED
@ECHO Java 1.8 or above is not installed
@ECHO Please go to https://java.com/ and install Java. Then retry installation.
PAUSE
GOTO END
:END
@ECHO OFF
setlocal ENABLEEXTENSIONS
@ECHO Detecting Java version installed.
:CHECK_JAVA_64
@ECHO Detecting if it is 64 bit machine
set KEY_NAME="HKEY_LOCAL_MACHINE\Software\Wow6432Node\JavaSoft\Java Runtime Environment"
set VALUE_NAME=CurrentVersion
FOR /F "usebackq skip=2 tokens=1-3" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName=%%A
set ValueType=%%B
set ValueValue=%%C
)
@ECHO CurrentVersion %ValueValue%
SET KEY_NAME="%KEY_NAME:~1,-1%\%ValueValue%"
SET VALUE_NAME=JavaHome
if defined ValueName (
FOR /F "usebackq skip=2 tokens=1,2*" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName2=%%A
set ValueType2=%%B
set JRE_PATH2=%%C
if defined ValueName2 (
set ValueName = %ValueName2%
set ValueType = %ValueType2%
set ValueValue = %JRE_PATH2%
)
)
)
IF NOT "%JRE_PATH2%" == "" GOTO JAVA_INSTALLED
:CHECK_JAVA_32
@ECHO Detecting if it is 32 bit machine
set KEY_NAME="HKEY_LOCAL_MACHINE\Software\JavaSoft\Java Runtime Environment"
set VALUE_NAME=CurrentVersion
FOR /F "usebackq skip=2 tokens=1-3" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName=%%A
set ValueType=%%B
set ValueValue=%%C
)
@ECHO CurrentVersion %ValueValue%
SET KEY_NAME="%KEY_NAME:~1,-1%\%ValueValue%"
SET VALUE_NAME=JavaHome
if defined ValueName (
FOR /F "usebackq skip=2 tokens=1,2*" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName2=%%A
set ValueType2=%%B
set JRE_PATH2=%%C
if defined ValueName2 (
set ValueName = %ValueName2%
set ValueType = %ValueType2%
set ValueValue = %JRE_PATH2%
)
)
)
IF "%JRE_PATH2%" == "" GOTO JAVA_NOT_INSTALLED
:JAVA_INSTALLED
@ECHO Java 1.8 found!
@ECHO Installing apq-pc-client ...
%~dp0apq-pc-client.exe install
@ECHO runing apq-pc-client ...
%~dp0apq-pc-client.exe start
@ECHO DONE.
GOTO END
:JAVA_NOT_INSTALLED
@ECHO Java 1.8 or above is not installed
@ECHO Please go to https://java.com/ and install Java. Then retry installation.
PAUSE
GOTO END
:END
@ECHO OFF
setlocal ENABLEEXTENSIONS
@ECHO Detecting Java version installed.
:CHECK_JAVA_64
@ECHO Detecting if it is 64 bit machine
set KEY_NAME="HKEY_LOCAL_MACHINE\Software\Wow6432Node\JavaSoft\Java Runtime Environment"
set VALUE_NAME=CurrentVersion
FOR /F "usebackq skip=2 tokens=1-3" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName=%%A
set ValueType=%%B
set ValueValue=%%C
)
@ECHO CurrentVersion %ValueValue%
SET KEY_NAME="%KEY_NAME:~1,-1%\%ValueValue%"
SET VALUE_NAME=JavaHome
if defined ValueName (
FOR /F "usebackq skip=2 tokens=1,2*" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName2=%%A
set ValueType2=%%B
set JRE_PATH2=%%C
if defined ValueName2 (
set ValueName = %ValueName2%
set ValueType = %ValueType2%
set ValueValue = %JRE_PATH2%
)
)
)
IF NOT "%JRE_PATH2%" == "" GOTO JAVA_INSTALLED
:CHECK_JAVA_32
@ECHO Detecting if it is 32 bit machine
set KEY_NAME="HKEY_LOCAL_MACHINE\Software\JavaSoft\Java Runtime Environment"
set VALUE_NAME=CurrentVersion
FOR /F "usebackq skip=2 tokens=1-3" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName=%%A
set ValueType=%%B
set ValueValue=%%C
)
@ECHO CurrentVersion %ValueValue%
SET KEY_NAME="%KEY_NAME:~1,-1%\%ValueValue%"
SET VALUE_NAME=JavaHome
if defined ValueName (
FOR /F "usebackq skip=2 tokens=1,2*" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
set ValueName2=%%A
set ValueType2=%%B
set JRE_PATH2=%%C
if defined ValueName2 (
set ValueName = %ValueName2%
set ValueType = %ValueType2%
set ValueValue = %JRE_PATH2%
)
)
)
IF "%JRE_PATH2%" == "" GOTO JAVA_NOT_INSTALLED
:JAVA_INSTALLED
@ECHO Java 1.8 found!
@ECHO Installing apq-pc-client ...
%~dp0apq-pc-client.exe install
@ECHO running apq-pc-client ...
%~dp0apq-pc-client.exe start
@ECHO DONE.
GOTO END
:JAVA_NOT_INSTALLED
@ECHO Java 1.8 or above is not installed
@ECHO Please go to https://java.com/ and install Java. Then retry installation.
PAUSE
GOTO END
:END
spring:
application:
name: apq-pc-control
server:
# Server bind address
address: "0.0.0.0"
port: ${random.int[10000,19999]}
spring:
application:
name: apq-pc-control
server:
# Server bind address
address: "0.0.0.0"
# port: ${random.int[10000,19999]}
port: 8762
\ No newline at end of file
package com.priusis.controller;
import cn.hutool.core.io.unit.DataSizeUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import cn.hutool.system.oshi.CpuInfo;
import cn.hutool.system.oshi.OshiUtil;
import com.priusis.lib.R;
import com.priusis.util.MacAddrUtil;
import com.priusis.vo.ApqInfoDataVo;
import com.priusis.vo.MqttRpcDataMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import oshi.hardware.HWDiskStore;
import oshi.hardware.HWPartition;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author yangli
* @since 2021/09/10
*/
@Slf4j
@Validated
@RestController
@RequestMapping(value = "info")
public class InfoController {
@Autowired
private RestTemplate restTemplate;
@GetMapping(value = "read_post")
public R<Map<String, Object>> getDownloadPath() throws IOException {
boolean isNoneEven = false;
// 获取采集配置,数据上报频率 params == data
ResponseEntity<MqttRpcDataMessage> forEntity = null;
Map<String, Integer> mapParams = null;
try {
forEntity = restTemplate.getForEntity("http://localhost:8765/rpc_cmd/info", MqttRpcDataMessage.class);
if (null != forEntity) {
MqttRpcDataMessage body = forEntity.getBody();
String params = body.getParams();
if (StrUtil.isNotBlank(params)) {
List<ApqInfoDataVo> apqInfoDataVos = JSONUtil.toList(params, ApqInfoDataVo.class);
mapParams = new HashMap<>();
for (ApqInfoDataVo apqInfoDataVo : apqInfoDataVos) {
mapParams.put(apqInfoDataVo.getCode(), apqInfoDataVo.getFrequency());
}
}
}
} catch (Exception e) {
log.error("采集数据异常", e);
}
String operatingSystem = "operatingSystem";
String mac = "mac";
String baseboard = "baseboard";
String ip = "ip";
String cpuModel = "cpuModel";
String cpuLoad = "cpuLoad";
String cpuTemp = "cpuTemp";
String memoryCap = "memoryCap";
String memoryAvailable = "memoryAvailable";
String diskModel = "diskModel";
String diskCap = "diskCap";
String diskFree = "diskFree";
Map<String, Object> data = null;
try {
// 上报PC实时信息
String collect = null;
String collect1 = null;
String collect2 = null;
try {
collect = Arrays.stream(OshiUtil.getHardware().getDiskStores())
.map(HWDiskStore::getPartitions)
.flatMap(Arrays::stream)
.filter(partition -> StrUtil.isNotBlank(partition.getMountPoint()))
.map(partition -> "\"" + StrUtil.removeSuffix(partition.getMountPoint(), ":\\") + "盘\":\"" +
DataSizeUtil.format(partition.getSize()) + "\"")
.collect(Collectors.joining(",", "{", "}"));
collect1 = Arrays.stream(OshiUtil.getHardware().getDiskStores())
.map(store -> Arrays.stream(store.getPartitions())
.map(HWPartition::getMountPoint)
.filter(StrUtil::isNotBlank)
.map(s -> "\"" + StrUtil.removeSuffix(s, ":\\") + "盘\":\"" +
StrUtil.removeSuffix(store.getModel(), " (标准磁盘驱动器)") + "\"")
.collect(Collectors.joining(",")))
.filter(StrUtil::isNotBlank)
.collect(Collectors.joining(",", "{", "}"));
collect2 = Arrays.stream(OshiUtil.getHardware().getDiskStores())
.map(HWDiskStore::getPartitions)
.flatMap(Arrays::stream)
.filter(partition -> StrUtil.isNotBlank(partition.getMountPoint()))
.map(partition -> "\"" + StrUtil.removeSuffix(partition.getMountPoint(), ":\\") + "盘\":\"" +
new DecimalFormat("#.00").format(100d * new File(partition.getMountPoint()).getFreeSpace() / partition.getSize()) + "%\"")
.collect(Collectors.joining(",", "{", "}"));
} catch (Exception e) {
log.error("硬盘数据获取失败", e);
}
data = MapUtil.<String, Object>builder()
.put(isNeedCollection(isNoneEven, operatingSystem, mapParams), operatingSystem, OshiUtil.getOs().toString())
.put(isNeedCollection(isNoneEven, mac, mapParams), mac, MacAddrUtil.get())
.put(isNeedCollection(isNoneEven, baseboard, mapParams), baseboard, OshiUtil.getSystem().getBaseboard().getManufacturer() + " " + OshiUtil.getSystem().getBaseboard().getVersion())
.put(isNeedCollection(isNoneEven, ip, mapParams), ip, InetAddress.getLocalHost().getHostAddress())
.put(isNeedCollection(isNoneEven, cpuModel, mapParams), cpuModel, OshiUtil.getCpuInfo(0).getCpuModel())
.put(isNeedCollection(isNoneEven, cpuTemp, mapParams), cpuTemp, Double.parseDouble(new DecimalFormat("#.00").format(OshiUtil.getSensors().getCpuTemperature())))
.put(isNeedCollection(isNoneEven, cpuLoad, mapParams), cpuLoad, getCpuUsed())
.put(isNeedCollection(isNoneEven, memoryCap, mapParams), memoryCap, DataSizeUtil.format(OshiUtil.getMemory().getTotal()))
.put(isNeedCollection(isNoneEven, memoryAvailable, mapParams), memoryAvailable, DataSizeUtil.format(OshiUtil.getMemory().getAvailable()))
.put(isNeedCollection(isNoneEven, diskModel, mapParams), diskModel, collect1)
.put(isNeedCollection(isNoneEven, diskCap, mapParams), diskCap, collect)
.put(isNeedCollection(isNoneEven, diskFree, mapParams), diskFree, collect2)
.build();
log.info("采集数据,上报属性: mapData:{}", data);
Map mapR = restTemplate.postForObject("http://localhost:8765/uplink/oc-client", data, Map.class);
log.info("采集数据,上报属性: ret:{}", mapR);
} catch (Exception e) {
log.error("采集数据异常", e);
data = MapUtil.<String, Object>builder().put("ERROR", e.getMessage()).build();
}
return R.success(data);
}
private boolean isNeedCollection(boolean isNoneEven, String key, Map<String, Integer> mapParams) {
if (null != mapParams && mapParams.containsKey(key)) {
return (!isNoneEven || mapParams.get(key) != 30);
} else {
return isNoneEven;
}
}
public static double getCpuUsed() {
CpuInfo cpuInfo = OshiUtil.getCpuInfo(100);
double used = Double.parseDouble(new DecimalFormat("#.00").format(100 - cpuInfo.getFree()));
return Math.min(Math.max(used, 0), 100);
}
}
package com.priusis.lib;
import lombok.Getter;
@Getter
public class R<T> {
private final int code;
private final String msg;
private final T data;
private R(int code, String msg, T data) {
this.code = code;
this.msg = msg;
this.data = data;
}
public static <T> R<T> success(T data) {
return new R<>(0, "SUCCESS", data);
}
public static <T> R<T> success() {
return success(null);
}
public static <T> R<T> error(int code, String msg, T data) {
return new R<>(code, msg, data);
}
public static <T> R<T> error(int code, String msg) {
return error(code, msg, null);
}
public static <T> R<T> error(String msg) {
return error(500, msg);
}
public static <T> R<T> error() {
return error("系统异常");
}
}
spring:
application:
name: apq-pc-info
server:
# Server bind address
address: "0.0.0.0"
port: ${random.int[10000,19999]}
spring:
application:
name: apq-pc-info
server:
# Server bind address
address: "0.0.0.0"
# port: ${random.int[10000,19999]}
port: 8764
package com.priusis;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.priusis.dto.RegisterParamDto;
import com.priusis.util.WinExecuteUtils;
import com.priusis.vo.MqttRpcDataMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@EnableScheduling
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, SecurityAutoConfiguration.class})
public class ApqRegisterApplication {
public static void main(String[] args) {
SpringApplication.run(ApqRegisterApplication.class, args);
}
// "params":
// {
// "type":1
// "programs": [
// {
// "name":"qq"
// }
// ]
// }
@Autowired
private RestTemplate restTemplate;
@Scheduled(fixedDelay = 30000L)
protected void registerProgramTask() {
log.info("软件检测上报=================");
/*
log.info("===================");
try {
WinExecuteUtils.killProc("Postman.exe");
} catch (Exception e) {
log.error("杀进程异常", e);
}*/
// 获取软件检测监控配置 params == data
ResponseEntity<MqttRpcDataMessage> forEntity = null;
try {
forEntity = restTemplate.getForEntity("http://localhost:8765/rpc_cmd/register", MqttRpcDataMessage.class);
} catch (RestClientException e) {
log.error("软件检测上报异常", e.getMessage());
}
if (null != forEntity) {
MqttRpcDataMessage body = forEntity.getBody();
String params = body.getParams();
if (StrUtil.isNotBlank(params)) {
Long sendTime = body.getSendTime();
//long current = System.currentTimeMillis();
RegisterParamDto registerParamDto = JSONUtil.toBean(params, RegisterParamDto.class);
// 收到软件检测下发请求
log.info("收到软件检测下发请求, sendTime:{}, params:{}", sendTime, params);
int type = registerParamDto.getType();
if (type == 1) {
List<RegisterParamDto.RegisterDetailParamDto> programs = registerParamDto.getPrograms();
// 上报软件检测监控数据
Map mapRequest = new HashMap();
for (RegisterParamDto.RegisterDetailParamDto program : programs) {
String name = program.getName().trim();
log.info("软件检测软件: {}", name);
boolean isE = WinExecuteUtils.findProcess(name);
if (isE) {
// 杀进程
log.info("存在黑名单软件, 进行进程查杀: {}", name);
try {
WinExecuteUtils.killProc(name);
} catch (Exception e) {
log.error("杀进程异常", e);
}
// 上报黑名单异常
mapRequest.put(name, "1");
}
}
// 上报黑名单异常
if (mapRequest.size() > 0) {
Map eventMapRequest = new HashMap();
eventMapRequest.put("requestId", 1);
eventMapRequest.put("methodName", "BlackList");
eventMapRequest.put("params", mapRequest);
Map map = restTemplate.postForObject("http://localhost:8765/uplink_event/oc-client", eventMapRequest, Map.class);
log.info("存在软件检测接口扫码告警,上报告警事件: mapData:{}, ret:{}", mapRequest, map);
}
// 上报黑名单属性 todo
}
} else {
log.info("未获取到获取软件检测监控配置");
}
} else {
log.info("未获取到获取软件检测监控配置");
}
}
}
package com.priusis;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.priusis.dto.RegisterParamDto;
import com.priusis.util.WinExecuteUtils;
import com.priusis.vo.MqttRpcDataMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@EnableScheduling
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, SecurityAutoConfiguration.class})
public class ApqRegisterApplication {
public static void main(String[] args) {
SpringApplication.run(ApqRegisterApplication.class, args);
}
// "params":
// {
// "type":1
// "programs": [
// {
// "name":"qq"
// }
// ]
// }
@Autowired
private RestTemplate restTemplate;
@Scheduled(fixedDelay = 30000L)
protected void registerProgramTask() {
log.info("软件检测上报=================");
/* try {
WinExecuteUtils.killProc("TIM.exe");
} catch (IOException e) {
log.error("杀进程异常", e);
}*/
// 获取软件检测监控配置 params == data
ResponseEntity<MqttRpcDataMessage> forEntity = null;
try {
forEntity = restTemplate.getForEntity("http://localhost:8765/rpc_cmd/register", MqttRpcDataMessage.class);
} catch (RestClientException e) {
log.error("软件检测上报异常", e.getMessage());
}
if (null != forEntity) {
MqttRpcDataMessage body = forEntity.getBody();
String params = body.getParams();
if (StrUtil.isNotBlank(params)) {
Long sendTime = body.getSendTime();
//long current = System.currentTimeMillis();
RegisterParamDto registerParamDto = JSONUtil.toBean(params, RegisterParamDto.class);
// 收到软件检测下发请求
log.info("收到软件检测下发请求, sendTime:{}, params:{}", sendTime, params);
int type = registerParamDto.getType();
if (type == 1) {
List<RegisterParamDto.RegisterDetailParamDto> programs = registerParamDto.getPrograms();
// 上报软件检测监控数据
Map mapRequest = new HashMap();
for (RegisterParamDto.RegisterDetailParamDto program : programs) {
String name = program.getName().trim();
log.info("软件检测软件: {}", name);
boolean isE = WinExecuteUtils.findProcess(name);
if (isE) {
// 杀进程
log.info("存在黑名单软件, 进行进程查杀: {}", name);
try {
WinExecuteUtils.killProc(name);
} catch (Exception e) {
log.error("杀进程异常", e);
}
// 上报黑名单异常
mapRequest.put(name, "1");
}
}
// 上报黑名单异常
if (mapRequest.size() > 0) {
Map eventMapRequest = new HashMap();
eventMapRequest.put("requestId", 1);
eventMapRequest.put("methodName", "BlackList");
eventMapRequest.put("params", mapRequest);
Map map = restTemplate.postForObject("http://localhost:8765/uplink_event/oc-client", eventMapRequest, Map.class);
log.info("存在软件检测接口扫码告警,上报告警事件: mapData:{}, ret:{}", mapRequest, map);
}
// 上报黑名单属性 todo
}
} else {
log.info("未获取到获取软件检测监控配置");
}
} else {
log.info("未获取到获取软件检测监控配置");
}
}
}
spring:
application:
name: apq-pc-register
server:
# Server bind address
address: "0.0.0.0"
port: ${random.int[30000,39999]}
spring:
application:
name: apq-pc-register
server:
# Server bind address
address: "0.0.0.0"
# port: ${random.int[30000,39999]}
port: 8763
\ No newline at end of file
@ECHO OFF
setlocal ENABLEEXTENSIONS
@ECHO Installing apq-client ...
"%~dp0apq-client-service.exe" install
@ECHO runing apq-client ...
"%~dp0apq-client-service.exe" start
@ECHO DONE.
@ECHO OFF
setlocal ENABLEEXTENSIONS
@ECHO Installing apq-client ...
"%~dp0apq-client-service.exe" install
@ECHO running apq-client ...
"%~dp0apq-client-service.exe" start
@ECHO DONE.
:END
\ No newline at end of file
No preview for this file type
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论