syntax error fix
This commit is contained in:
parent
07ef365ad3
commit
b4eed25b5f
2
pom.xml
2
pom.xml
|
@ -49,7 +49,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.loafle.overflow</groupId>
|
<groupId>com.loafle.overflow</groupId>
|
||||||
<artifactId>commons-java</artifactId>
|
<artifactId>commons-java</artifactId>
|
||||||
<version>1.0.6-SNAPSHOT</version>
|
<version>1.0.8-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -9,6 +9,6 @@ import org.springframework.stereotype.Repository;
|
||||||
*/
|
*/
|
||||||
@Repository
|
@Repository
|
||||||
public interface InfraHostDAO extends JpaRepository<InfraHost, Long> {
|
public interface InfraHostDAO extends JpaRepository<InfraHost, Long> {
|
||||||
InfraHost findByIpv4(String ipv4);
|
InfraHost findByProbeIdAndIpv4(Long probeId, String ipv4);
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
package com.loafle.overflow.central.module.infra.service;
|
package com.loafle.overflow.central.module.infra.service;
|
||||||
|
|
||||||
|
|
||||||
import com.loafle.overflow.central.module.infra.dao.InfraHostDAO;
|
import com.loafle.overflow.central.module.infra.dao.InfraHostDAO;
|
||||||
import com.loafle.overflow.core.exception.OverflowException;
|
import com.loafle.overflow.core.exception.OverflowException;
|
||||||
import com.loafle.overflow.model.infra.InfraHost;
|
import com.loafle.overflow.model.infra.InfraHost;
|
||||||
|
@ -24,8 +25,8 @@ public class CentralInfraHostService implements InfraHostService {
|
||||||
return this.infraHostDAO.findOne(id);
|
return this.infraHostDAO.findOne(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public InfraHost readByIp(String ip) throws OverflowException {
|
public InfraHost readByProbeIdAndIpv4(Long probeId, String ip) throws OverflowException {
|
||||||
return this.infraHostDAO.findByIpv4(ip);
|
return this.infraHostDAO.findByProbeIdAndIpv4(probeId, ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,6 @@ public class CentralInfraService implements InfraService {
|
||||||
|
|
||||||
public Infra read(Long id) throws OverflowException {
|
public Infra read(Long id) throws OverflowException {
|
||||||
Infra infra = this.infraDAO.findOne(id);
|
Infra infra = this.infraDAO.findOne(id);
|
||||||
infra.getTarget().setSensors(this.sensorDAO.findAllByTargetId(infra.getTarget().getId()));
|
|
||||||
return infra;
|
return infra;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,9 +54,6 @@ public class CentralInfraService implements InfraService {
|
||||||
}
|
}
|
||||||
|
|
||||||
Page<Infra> infraList = this.infraDAO.findAllByProbeInAndTargetNotNull(probeList, PageUtil.getPageRequest(pageParams));
|
Page<Infra> infraList = this.infraDAO.findAllByProbeInAndTargetNotNull(probeList, PageUtil.getPageRequest(pageParams));
|
||||||
for (Infra infra : infraList) {
|
|
||||||
infra.getTarget().setSensors(this.sensorDAO.findAllByTargetId(infra.getTarget().getId()));
|
|
||||||
}
|
|
||||||
return infraList;
|
return infraList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,13 +73,12 @@ public class CentralSensorService implements SensorService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Page<Sensor> readAllByInfraID(Long infraID, PageParams pageParams) throws OverflowException {
|
public Page<Sensor> readAllByInfraID(Long infraID, PageParams pageParams) throws OverflowException {
|
||||||
Infra dbInfra = this.infraService.read(infraID);
|
// Infra dbInfra = this.infraService.read(infraID);
|
||||||
|
// if (dbInfra == null) {
|
||||||
if (dbInfra == null || dbInfra.getTarget() == null) {
|
// throw new OverflowException("", new Throwable());
|
||||||
throw new OverflowException("", new Throwable());
|
// }
|
||||||
}
|
// return this.sensorDAO.findAllByTargetId(dbInfra.getTarget().getId(), PageUtil.getPageRequest(pageParams));
|
||||||
|
return null;
|
||||||
return this.sensorDAO.findAllByTargetId(dbInfra.getTarget().getId(), PageUtil.getPageRequest(pageParams));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Page<Sensor> readAllByTargetID(Long targetID, PageParams pageParams) throws OverflowException {
|
public Page<Sensor> readAllByTargetID(Long targetID, PageParams pageParams) throws OverflowException {
|
||||||
|
|
|
@ -9,4 +9,5 @@ import org.springframework.stereotype.Repository;
|
||||||
*/
|
*/
|
||||||
@Repository
|
@Repository
|
||||||
public interface TargetDAO extends JpaRepository<Target, Long> {
|
public interface TargetDAO extends JpaRepository<Target, Long> {
|
||||||
|
Target findByInfraId(Long infraId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,226 +1,226 @@
|
||||||
package com.loafle.overflow.central.module.target.service;
|
// package com.loafle.overflow.central.module.target.service;
|
||||||
|
|
||||||
import com.loafle.overflow.central.module.infra.service.*;
|
// import com.loafle.overflow.central.module.infra.service.*;
|
||||||
import com.loafle.overflow.core.exception.OverflowException;
|
// import com.loafle.overflow.core.exception.OverflowException;
|
||||||
import com.loafle.overflow.core.type.PortType;
|
// import com.loafle.overflow.core.type.PortType;
|
||||||
import com.loafle.overflow.model.discovery.Host;
|
// import com.loafle.overflow.model.discovery.Host;
|
||||||
import com.loafle.overflow.model.discovery.Port;
|
// import com.loafle.overflow.model.discovery.Port;
|
||||||
|
|
||||||
import com.loafle.overflow.model.infra.*;
|
// import com.loafle.overflow.model.infra.*;
|
||||||
import com.loafle.overflow.model.meta.MetaInfraType;
|
// import com.loafle.overflow.model.meta.MetaInfraType;
|
||||||
import com.loafle.overflow.model.meta.MetaInfraVendor;
|
// import com.loafle.overflow.model.meta.MetaInfraVendor;
|
||||||
import com.loafle.overflow.model.probe.Probe;
|
// import com.loafle.overflow.model.probe.Probe;
|
||||||
import com.loafle.overflow.model.target.Target;
|
// import com.loafle.overflow.model.target.Target;
|
||||||
import com.loafle.overflow.service.central.target.*;
|
// import com.loafle.overflow.service.central.target.*;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
// import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
// import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.transaction.Transactional;
|
// import javax.transaction.Transactional;
|
||||||
import java.util.List;
|
// import java.util.List;
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* Created by snoop on 17. 6. 28.
|
// * Created by snoop on 17. 6. 28.
|
||||||
*/
|
// */
|
||||||
@Service("TargetDiscoveryService")
|
// @Service("TargetDiscoveryService")
|
||||||
public class CentralTargetDiscoveryService implements TargetDiscoveryService {
|
// public class CentralTargetDiscoveryService implements TargetDiscoveryService {
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private TargetService targetService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CentralInfraMachineService infraMachineService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CentralInfraOSService infraOSService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CentralInfraHostService infraHostService;
|
|
||||||
|
|
||||||
// @Autowired
|
// @Autowired
|
||||||
// private CentralInfraService infraService;
|
// private TargetService targetService;
|
||||||
|
|
||||||
@Autowired
|
// @Autowired
|
||||||
private CentralInfraOSPortService infraOSPortService;
|
// private CentralInfraMachineService infraMachineService;
|
||||||
|
|
||||||
@Autowired
|
// @Autowired
|
||||||
private CentralInfraServiceService infraServiceService;
|
// private CentralInfraOSService infraOSService;
|
||||||
|
|
||||||
@Transactional
|
// @Autowired
|
||||||
public boolean saveAllTarget(List<Host> hosts, Probe probe) throws OverflowException {
|
// private CentralInfraHostService infraHostService;
|
||||||
|
|
||||||
InfraHost infraHost = null;
|
// // @Autowired
|
||||||
|
// // private CentralInfraService infraService;
|
||||||
|
|
||||||
for (Host host : hosts) {
|
// @Autowired
|
||||||
|
// private CentralInfraOSPortService infraOSPortService;
|
||||||
|
|
||||||
infraHost = this.createAndReadHost(host, probe);
|
// @Autowired
|
||||||
|
// private CentralInfraServiceService infraServiceService;
|
||||||
|
|
||||||
this.createPort(infraHost, host, probe);
|
// @Transactional
|
||||||
|
// public boolean saveAllTarget(List<Host> hosts, Probe probe) throws OverflowException {
|
||||||
|
|
||||||
}
|
// InfraHost infraHost = null;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createService(InfraHost infraHost, Port port, Probe probe) throws OverflowException {
|
// for (Host host : hosts) {
|
||||||
|
|
||||||
MetaInfraType typeService = new MetaInfraType(7);
|
// infraHost = this.createAndReadHost(host, probe);
|
||||||
|
|
||||||
String portType = "UDP";
|
// this.createPort(infraHost, host, probe);
|
||||||
|
|
||||||
if (port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP || port.getPortType() == null) {
|
// }
|
||||||
portType = "TCP";
|
// return true;
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (port.getServiceList() == null) {
|
// private void createService(InfraHost infraHost, Port port, Probe probe) throws OverflowException {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// for(String key : port.getServices().keySet()) {
|
// MetaInfraType typeService = new MetaInfraType(7);
|
||||||
for (com.loafle.overflow.model.discovery.Service service : port.getServiceList()) {
|
|
||||||
|
|
||||||
// com.loafle.overflow.module.discovery.model.Service service =
|
// String portType = "UDP";
|
||||||
// port.getServices().get(key);
|
|
||||||
|
|
||||||
InfraService dbInfraService = this.infraServiceService
|
// if (port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP || port.getPortType() == null) {
|
||||||
.readByInfraHostIDAndPortAndPortType(infraHost.getId(), port.getPortNumber(), portType);
|
// portType = "TCP";
|
||||||
|
// }
|
||||||
|
|
||||||
if (dbInfraService != null) {
|
// if (port.getServiceList() == null) {
|
||||||
if (service.isTarget() && dbInfraService.getTarget() == null) {
|
|
||||||
Target targetService = new Target();
|
|
||||||
targetService.setDisplayName(service.getServiceName());
|
|
||||||
this.targetService.regist(targetService, probe);
|
|
||||||
dbInfraService.setTarget(targetService);
|
|
||||||
this.infraServiceService.regist(dbInfraService);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
InfraService infraService = new InfraService();
|
|
||||||
infraService.setInfraHost(infraHost);
|
|
||||||
infraService.setPort(port.getPortNumber());
|
|
||||||
infraService.setPortType(portType);
|
|
||||||
infraService.setMetaInfraType(typeService);
|
|
||||||
infraService.setProbe(probe);
|
|
||||||
|
|
||||||
if (port.getPortType() == PortType.TLS) {
|
|
||||||
infraService.setTlsType(true);
|
|
||||||
}
|
|
||||||
infraService.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByService(service.getServiceName()));
|
|
||||||
|
|
||||||
if (service.isTarget()) {
|
|
||||||
Target targetService = new Target();
|
|
||||||
targetService.setDisplayName(service.getServiceName());
|
|
||||||
this.targetService.regist(targetService, probe);
|
|
||||||
infraService.setTarget(targetService);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.infraServiceService.regist(infraService);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createPort(InfraHost infraHost, Host host, Probe probe) throws OverflowException {
|
|
||||||
|
|
||||||
// if(host.getPorts() == null) {
|
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
String portType = "UDP";
|
// // for(String key : port.getServices().keySet()) {
|
||||||
|
// for (com.loafle.overflow.model.discovery.Service service : port.getServiceList()) {
|
||||||
|
|
||||||
MetaInfraType typePort = new MetaInfraType(6);
|
// // com.loafle.overflow.module.discovery.model.Service service =
|
||||||
|
// // port.getServices().get(key);
|
||||||
|
|
||||||
InfraOS infraOS = infraHost.getInfraOS();
|
// InfraService dbInfraService = this.infraServiceService
|
||||||
|
// .readByInfraHostIDAndPortAndPortType(infraHost.getId(), port.getPortNumber(), portType);
|
||||||
|
|
||||||
// for( String key: host.getPorts().keySet()) {
|
// if (dbInfraService != null) {
|
||||||
|
// if (service.isTarget() && dbInfraService.getTarget() == null) {
|
||||||
|
// Target targetService = new Target();
|
||||||
|
// targetService.setDisplayName(service.getServiceName());
|
||||||
|
// this.targetService.regist(targetService, probe);
|
||||||
|
// dbInfraService.setTarget(targetService);
|
||||||
|
// this.infraServiceService.regist(dbInfraService);
|
||||||
|
// }
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
|
||||||
if (host.getPortList() == null) {
|
// InfraService infraService = new InfraService();
|
||||||
return;
|
// infraService.setInfraHost(infraHost);
|
||||||
}
|
// infraService.setPort(port.getPortNumber());
|
||||||
|
// infraService.setPortType(portType);
|
||||||
|
// infraService.setMetaInfraType(typeService);
|
||||||
|
// infraService.setProbe(probe);
|
||||||
|
|
||||||
for (Port port : host.getPortList()) {
|
// if (port.getPortType() == PortType.TLS) {
|
||||||
// Port port = host.getPorts().get(key);
|
// infraService.setTlsType(true);
|
||||||
|
// }
|
||||||
|
// infraService.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByService(service.getServiceName()));
|
||||||
|
|
||||||
if (port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP) {
|
// if (service.isTarget()) {
|
||||||
portType = "TCP";
|
// Target targetService = new Target();
|
||||||
}
|
// targetService.setDisplayName(service.getServiceName());
|
||||||
|
// this.targetService.regist(targetService, probe);
|
||||||
|
// infraService.setTarget(targetService);
|
||||||
|
// }
|
||||||
|
|
||||||
InfraOSPort dbInfraOSPort = this.infraOSPortService.readByInfraOSIDAndPortAndPortType(infraOS.getId(), port.getPortNumber(),
|
// this.infraServiceService.regist(infraService);
|
||||||
portType);
|
|
||||||
if (dbInfraOSPort == null) {
|
|
||||||
InfraOSPort infraOSPort = new InfraOSPort();
|
|
||||||
infraOSPort.setInfraOS(infraOS);
|
|
||||||
infraOSPort.setPort(port.getPortNumber());
|
|
||||||
infraOSPort.setPortType(portType);
|
|
||||||
infraOSPort.setProbe(probe);
|
|
||||||
infraOSPort.setMetaInfraType(typePort);
|
|
||||||
|
|
||||||
if (port.getPortType() == PortType.TLS) {
|
// }
|
||||||
infraOSPort.setTlsType(true);
|
|
||||||
}
|
|
||||||
infraOSPort.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByPort(port.getPortNumber()));
|
|
||||||
this.infraOSPortService.regist(infraOSPort);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.createService(infraHost, port, probe);
|
// }
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private InfraHost createAndReadHost(Host host, Probe probe) throws OverflowException {
|
// private void createPort(InfraHost infraHost, Host host, Probe probe) throws OverflowException {
|
||||||
|
|
||||||
InfraHost infraHost = this.infraHostService.readByIp(host.getIpv4());
|
// // if(host.getPorts() == null) {
|
||||||
if (infraHost != null) {
|
// // return;
|
||||||
|
// // }
|
||||||
|
|
||||||
if (host.isTarget() && infraHost.getTarget() == null) {
|
// String portType = "UDP";
|
||||||
Target target = new Target();
|
|
||||||
target.setDisplayName(host.getIpv4() + "-Host");
|
|
||||||
|
|
||||||
this.targetService.regist(target, probe);
|
// MetaInfraType typePort = new MetaInfraType(6);
|
||||||
infraHost.setTarget(target);
|
|
||||||
this.infraHostService.regist(infraHost);
|
|
||||||
}
|
|
||||||
|
|
||||||
return infraHost;
|
// InfraOS infraOS = infraHost.getInfraOS();
|
||||||
} else {
|
|
||||||
MetaInfraType typeMachine = new MetaInfraType(1); // 1 = Machine;
|
|
||||||
|
|
||||||
MetaInfraType typeOS = new MetaInfraType(3);// 3 = Os
|
// // for( String key: host.getPorts().keySet()) {
|
||||||
|
|
||||||
MetaInfraType typeHost = new MetaInfraType(2); // 2 = Host
|
// if (host.getPortList() == null) {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
InfraMachine infraMachine = new InfraMachine();
|
// for (Port port : host.getPortList()) {
|
||||||
infraMachine.setProbe(probe);
|
// // Port port = host.getPorts().get(key);
|
||||||
infraMachine.setMetaInfraType(typeMachine);
|
|
||||||
infraMachine.setMeta(host.getIpv4() + "-MACHINE");
|
|
||||||
this.infraMachineService.regist(infraMachine);
|
|
||||||
|
|
||||||
InfraOS infraOS = new InfraOS();
|
// if (port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP) {
|
||||||
infraOS.setInfraMachine(infraMachine);
|
// portType = "TCP";
|
||||||
infraOS.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByOS(host.getOs()));
|
// }
|
||||||
infraOS.setMetaInfraType(typeOS);
|
|
||||||
infraOS.setProbe(probe);
|
|
||||||
infraOS.setMeta(host.getIpv4() + "-OS");
|
|
||||||
this.infraOSService.regist(infraOS);
|
|
||||||
|
|
||||||
InfraHost newInfraHost = new InfraHost();
|
// InfraOSPort dbInfraOSPort = this.infraOSPortService.readByInfraOSIDAndPortAndPortType(infraOS.getId(), port.getPortNumber(),
|
||||||
newInfraHost.setIpv4(host.getIpv4());
|
// portType);
|
||||||
newInfraHost.setMac(host.getMac());
|
// if (dbInfraOSPort == null) {
|
||||||
newInfraHost.setInfraOS(infraOS);
|
// InfraOSPort infraOSPort = new InfraOSPort();
|
||||||
newInfraHost.setMetaInfraType(typeHost);
|
// infraOSPort.setInfraOS(infraOS);
|
||||||
newInfraHost.setProbe(probe);
|
// infraOSPort.setPort(port.getPortNumber());
|
||||||
|
// infraOSPort.setPortType(portType);
|
||||||
|
// infraOSPort.setProbe(probe);
|
||||||
|
// infraOSPort.setMetaInfraType(typePort);
|
||||||
|
|
||||||
if (host.isTarget()) {
|
// if (port.getPortType() == PortType.TLS) {
|
||||||
Target target = new Target();
|
// infraOSPort.setTlsType(true);
|
||||||
target.setDisplayName(host.getIpv4() + "-Host");
|
// }
|
||||||
|
// infraOSPort.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByPort(port.getPortNumber()));
|
||||||
|
// this.infraOSPortService.regist(infraOSPort);
|
||||||
|
// }
|
||||||
|
|
||||||
this.targetService.regist(target, probe);
|
// this.createService(infraHost, port, probe);
|
||||||
newInfraHost.setTarget(target);
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
this.infraHostService.regist(newInfraHost);
|
// private InfraHost createAndReadHost(Host host, Probe probe) throws OverflowException {
|
||||||
infraHost = newInfraHost;
|
|
||||||
}
|
|
||||||
|
|
||||||
return infraHost;
|
// InfraHost infraHost = this.infraHostService.readByIp(host.getIpv4());
|
||||||
}
|
// if (infraHost != null) {
|
||||||
|
|
||||||
}
|
// if (host.isTarget() && infraHost.getTarget() == null) {
|
||||||
|
// Target target = new Target();
|
||||||
|
// target.setDisplayName(host.getIpv4() + "-Host");
|
||||||
|
|
||||||
|
// this.targetService.regist(target, probe);
|
||||||
|
// infraHost.setTarget(target);
|
||||||
|
// this.infraHostService.regist(infraHost);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return infraHost;
|
||||||
|
// } else {
|
||||||
|
// MetaInfraType typeMachine = new MetaInfraType(1); // 1 = Machine;
|
||||||
|
|
||||||
|
// MetaInfraType typeOS = new MetaInfraType(3);// 3 = Os
|
||||||
|
|
||||||
|
// MetaInfraType typeHost = new MetaInfraType(2); // 2 = Host
|
||||||
|
|
||||||
|
// InfraMachine infraMachine = new InfraMachine();
|
||||||
|
// infraMachine.setProbe(probe);
|
||||||
|
// infraMachine.setMetaInfraType(typeMachine);
|
||||||
|
// infraMachine.setMeta(host.getIpv4() + "-MACHINE");
|
||||||
|
// this.infraMachineService.regist(infraMachine);
|
||||||
|
|
||||||
|
// InfraOS infraOS = new InfraOS();
|
||||||
|
// infraOS.setInfraMachine(infraMachine);
|
||||||
|
// infraOS.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByOS(host.getOs()));
|
||||||
|
// infraOS.setMetaInfraType(typeOS);
|
||||||
|
// infraOS.setProbe(probe);
|
||||||
|
// infraOS.setMeta(host.getIpv4() + "-OS");
|
||||||
|
// this.infraOSService.regist(infraOS);
|
||||||
|
|
||||||
|
// InfraHost newInfraHost = new InfraHost();
|
||||||
|
// newInfraHost.setIpv4(host.getIpv4());
|
||||||
|
// newInfraHost.setMac(host.getMac());
|
||||||
|
// newInfraHost.setInfraOS(infraOS);
|
||||||
|
// newInfraHost.setMetaInfraType(typeHost);
|
||||||
|
// newInfraHost.setProbe(probe);
|
||||||
|
|
||||||
|
// if (host.isTarget()) {
|
||||||
|
// Target target = new Target();
|
||||||
|
// target.setDisplayName(host.getIpv4() + "-Host");
|
||||||
|
|
||||||
|
// this.targetService.regist(target, probe);
|
||||||
|
// newInfraHost.setTarget(target);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// this.infraHostService.regist(newInfraHost);
|
||||||
|
// infraHost = newInfraHost;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return infraHost;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
|
@ -1,24 +1,31 @@
|
||||||
package com.loafle.overflow.central.module.target.service;
|
package com.loafle.overflow.central.module.target.service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.loafle.overflow.central.module.infra.service.CentralInfraHostService;
|
import com.loafle.overflow.central.module.infra.service.CentralInfraHostService;
|
||||||
|
import com.loafle.overflow.central.module.infra.service.CentralInfraServiceService;
|
||||||
import com.loafle.overflow.central.module.probe.service.CentralProbeService;
|
import com.loafle.overflow.central.module.probe.service.CentralProbeService;
|
||||||
import com.loafle.overflow.central.module.target.dao.TargetDAO;
|
import com.loafle.overflow.central.module.target.dao.TargetDAO;
|
||||||
import com.loafle.overflow.core.exception.OverflowException;
|
import com.loafle.overflow.core.exception.OverflowException;
|
||||||
|
import com.loafle.overflow.core.type.CryptoType;
|
||||||
import com.loafle.overflow.model.discovery.Host;
|
import com.loafle.overflow.model.discovery.Host;
|
||||||
|
import com.loafle.overflow.model.discovery.Service;
|
||||||
|
import com.loafle.overflow.model.infra.InfraHost;
|
||||||
|
import com.loafle.overflow.model.infra.InfraService;
|
||||||
|
import com.loafle.overflow.model.meta.MetaInfraType;
|
||||||
|
import com.loafle.overflow.model.meta.MetaInfraVendor;
|
||||||
import com.loafle.overflow.model.probe.Probe;
|
import com.loafle.overflow.model.probe.Probe;
|
||||||
import com.loafle.overflow.model.target.Target;
|
import com.loafle.overflow.model.target.Target;
|
||||||
import com.loafle.overflow.service.central.target.TargetService;
|
import com.loafle.overflow.service.central.target.TargetService;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by insanity on 17. 6. 28.
|
* Created by insanity on 17. 6. 28.
|
||||||
*/
|
*/
|
||||||
@Service("TargetService")
|
@org.springframework.stereotype.Service("TargetService")
|
||||||
public class CentralTargetService implements TargetService {
|
public class CentralTargetService implements TargetService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -27,6 +34,8 @@ public class CentralTargetService implements TargetService {
|
||||||
private CentralProbeService probeService;
|
private CentralProbeService probeService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private CentralInfraHostService infraHostService;
|
private CentralInfraHostService infraHostService;
|
||||||
|
@Autowired
|
||||||
|
private CentralInfraServiceService infraServiceService;
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Target regist(Target target, Probe probe) throws OverflowException {
|
public Target regist(Target target, Probe probe) throws OverflowException {
|
||||||
|
@ -73,20 +82,88 @@ public class CentralTargetService implements TargetService {
|
||||||
return this.targetDAO.save(t);
|
return this.targetDAO.save(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Target readExistHostTarget(Long probeId, String ip) throws OverflowException {
|
||||||
|
InfraHost infraHost = this.infraHostService.readByProbeIdAndIpv4(probeId, ip);
|
||||||
|
if (null == infraHost) return null;
|
||||||
|
return this.targetDAO.findByInfraId(infraHost.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Target readExistServiceTarget(Long hostId, int portNumber, String portType) throws OverflowException {
|
||||||
|
InfraService infraService = this.infraServiceService.readByInfraHostIDAndPortAndPortType(hostId, portNumber, portType);
|
||||||
|
if (null == infraService) return null;
|
||||||
|
return this.targetDAO.findByInfraId(infraService.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public List<Target> registDiscoveredTargets(Long probeId, List<Host> hosts,
|
public List<Target> registDiscoveredTargets(Long probeId, List<Host> hosts, List<Service> services)
|
||||||
List<com.loafle.overflow.model.discovery.Service> services) throws OverflowException {
|
throws OverflowException {
|
||||||
/*
|
List<Target> targets = new ArrayList<Target>();
|
||||||
* 해당 host의 mac에 해당하는 infraHost가 이미 존재하는지 검사 infraHost가 없다면 create infraHost가
|
targets.addAll(registDiscoveredHostTargets(probeId, hosts));
|
||||||
* 있다면 update infraHost.getTarget()이 있어도 무조건 새로운 target으로 연결
|
targets.addAll(this.registDiscoveredServiceTargets(probeId, services));
|
||||||
*
|
return targets;
|
||||||
*
|
|
||||||
* for(Host host : hosts) { Target target = new Target();
|
|
||||||
*
|
|
||||||
* MetaInfraType infraType = new MetaInfraType(); infraType.setId(2); InfraHost
|
|
||||||
* infraHost = new InfraHost(); infraHost.setInfraType(infraType);
|
|
||||||
* infraHost.setProbe(new Probe(probeId)); infraHost.setTarget(target); }
|
|
||||||
*/
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<Target> registDiscoveredHostTargets(Long probeId, List<Host> hosts) throws OverflowException {
|
||||||
|
List<Target> targets = new ArrayList<>();
|
||||||
|
if (null == hosts)
|
||||||
|
return targets;
|
||||||
|
for (Host host : hosts) {
|
||||||
|
InfraHost infraHost = this.registInfraHostByDiscoveredHost(host, probeId);
|
||||||
|
Target target = new Target();
|
||||||
|
target.setInfra(infraHost);
|
||||||
|
String displayName = host.getIpv6() == null ? host.getIpv6() : host.getIpv4();
|
||||||
|
target.setDisplayName(displayName);
|
||||||
|
targets.add(this.targetDAO.save(target));
|
||||||
|
}
|
||||||
|
return targets;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Target> registDiscoveredServiceTargets(Long probeId, List<Service> services) throws OverflowException {
|
||||||
|
List<Target> targets = new ArrayList<>();
|
||||||
|
if (null == services)
|
||||||
|
return targets;
|
||||||
|
for (Service service : services) {
|
||||||
|
Host host = service.getPort().getHost();
|
||||||
|
InfraHost infraHost = null;
|
||||||
|
InfraHost existInfraHost = this.infraHostService.readByProbeIdAndIpv4(probeId, host.getIpv4());
|
||||||
|
InfraService infraService = null;
|
||||||
|
if (null != existInfraHost) {
|
||||||
|
infraHost = existInfraHost;
|
||||||
|
} else {
|
||||||
|
infraHost = this.registInfraHostByDiscoveredHost(host, probeId);
|
||||||
|
infraService = this.registInfraServiceByDiscoveredService(infraHost, service, probeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
Target target = new Target();
|
||||||
|
target.setInfra(infraService);
|
||||||
|
String displayName = service.getServiceName();
|
||||||
|
target.setDisplayName(displayName);
|
||||||
|
targets.add(this.targetDAO.save(target));
|
||||||
|
}
|
||||||
|
return targets;
|
||||||
|
}
|
||||||
|
|
||||||
|
private InfraHost registInfraHostByDiscoveredHost(Host host, Long probeId) throws OverflowException {
|
||||||
|
InfraHost infraHost = new InfraHost();
|
||||||
|
infraHost.setMetaInfraType(new MetaInfraType(2));
|
||||||
|
infraHost.setProbe(new Probe(probeId));
|
||||||
|
infraHost.setIpv4(host.getIpv4());
|
||||||
|
infraHost.setIpv6(host.getIpv6());
|
||||||
|
infraHost.setMac(host.getMac());
|
||||||
|
return this.infraHostService.regist(infraHost);
|
||||||
|
}
|
||||||
|
|
||||||
|
private InfraService registInfraServiceByDiscoveredService(InfraHost infraHost, Service service, Long probeId) throws OverflowException {
|
||||||
|
InfraService infraService = new InfraService();
|
||||||
|
infraHost.setMetaInfraType(new MetaInfraType(7));
|
||||||
|
infraService.setInfraHost(infraHost);
|
||||||
|
infraService.setPort(service.getPort().getPortNumber());
|
||||||
|
infraService.setPortType(service.getPort().getPortType().toString());
|
||||||
|
infraService.setTlsType(service.getCryptoType() == CryptoType.TLS);
|
||||||
|
infraService.setMetaInfraVendor(MetaInfraVendor.CreateInfraVendorByService(service.getServiceName()));
|
||||||
|
return this.infraServiceService.regist(infraService);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user