fixed discovery result save
This commit is contained in:
parent
0c5f529bf0
commit
a8ad0f1187
|
@ -1,6 +1,7 @@
|
|||
package com.loafle.overflow.module.discovery.model;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
@ -19,6 +20,9 @@ public class Host {
|
|||
|
||||
private Map<String, Port> ports;
|
||||
|
||||
private List<Port> portList;
|
||||
|
||||
|
||||
public Host(){}
|
||||
|
||||
public long getId() {
|
||||
|
@ -84,4 +88,12 @@ public class Host {
|
|||
public void setPorts(Map<String, Port> ports) {
|
||||
this.ports = ports;
|
||||
}
|
||||
|
||||
public List<Port> getPortList() {
|
||||
return portList;
|
||||
}
|
||||
|
||||
public void setPortList(List<Port> portList) {
|
||||
this.portList = portList;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ package com.loafle.overflow.module.discovery.model;
|
|||
import com.loafle.overflow.module.discovery.type.PortType;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
@ -26,6 +27,8 @@ public class Port {
|
|||
|
||||
private Map<String, Service> services;
|
||||
|
||||
private List<Service> serviceList;
|
||||
|
||||
public Port() {}
|
||||
|
||||
public long getId() {
|
||||
|
@ -75,4 +78,12 @@ public class Port {
|
|||
public void setServices(Map<String, Service> services) {
|
||||
this.services = services;
|
||||
}
|
||||
|
||||
public List<Service> getServiceList() {
|
||||
return serviceList;
|
||||
}
|
||||
|
||||
public void setServiceList(List<Service> serviceList) {
|
||||
this.serviceList = serviceList;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,22 +85,23 @@ public class MetaInfraVendor {
|
|||
MetaInfraVendor vendor = new MetaInfraVendor();
|
||||
|
||||
if(serviceName.equals("mysql")) {
|
||||
vendor.setId(39);
|
||||
vendor.setId(11);
|
||||
}
|
||||
else if(serviceName.equals("portgresql")) {
|
||||
vendor.setId(39);
|
||||
vendor.setId(15);
|
||||
}
|
||||
else if(serviceName.equals("wmi")) {
|
||||
vendor.setId(39);
|
||||
vendor.setId(23);
|
||||
}
|
||||
else if(serviceName.equals("snmpv2")) {
|
||||
vendor.setId(39);
|
||||
else if(serviceName.equals("snmp")) {
|
||||
vendor.setId(20);
|
||||
}
|
||||
else {
|
||||
vendor.setId(43); // unknown
|
||||
vendor.setId(24); // unknown
|
||||
}
|
||||
|
||||
|
||||
|
||||
return vendor;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,170 +59,170 @@ public class TargetDiscoveryService {
|
|||
return true;
|
||||
}
|
||||
|
||||
private void createService(InfraHost infraHost, Port port, Probe probe) {
|
||||
private void createService(InfraHost infraHost, Port port, Probe probe) {
|
||||
|
||||
if(port.getServices() == null) {
|
||||
return;
|
||||
}
|
||||
if(port.getServices() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
MetaInfraType typeService = new MetaInfraType();
|
||||
typeService.setId(7);
|
||||
MetaInfraType typeService = new MetaInfraType();
|
||||
typeService.setId(7);
|
||||
|
||||
String portType = "UDP";
|
||||
String portType = "UDP";
|
||||
|
||||
if(port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP) {
|
||||
portType = "TCP";
|
||||
}
|
||||
if(port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP) {
|
||||
portType = "TCP";
|
||||
}
|
||||
|
||||
for(String key : port.getServices().keySet()) {
|
||||
// for(String key : port.getServices().keySet()) {
|
||||
for(com.loafle.overflow.module.discovery.model.Service service : port.getServiceList()) {
|
||||
|
||||
com.loafle.overflow.module.discovery.model.Service service = port.getServices().get(key);
|
||||
// com.loafle.overflow.module.discovery.model.Service service = port.getServices().get(key);
|
||||
|
||||
InfraService dbInfraService = this.infraServiceService.readByService(infraHost.getId(), port.getPortNumber(), portType);
|
||||
InfraService dbInfraService = this.infraServiceService.readByService(infraHost.getId(), port.getPortNumber(), portType);
|
||||
|
||||
if(dbInfraService != null) {
|
||||
if(service.isTarget() && dbInfraService.getTarget() == null) {
|
||||
Target targetService = new Target();
|
||||
targetService.setDisplayName(service.getServiceName() + "-Service");
|
||||
this.targetService.regist(targetService);
|
||||
dbInfraService.setTarget(targetService);
|
||||
this.infraServiceService.regist(dbInfraService);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if(dbInfraService != null) {
|
||||
if(service.isTarget() && dbInfraService.getTarget() == null) {
|
||||
Target targetService = new Target();
|
||||
targetService.setDisplayName(service.getServiceName());
|
||||
this.targetService.regist(targetService);
|
||||
dbInfraService.setTarget(targetService);
|
||||
this.infraServiceService.regist(dbInfraService);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
InfraService infraService = new InfraService();
|
||||
infraService.setHost(infraHost);
|
||||
infraService.setPort(port.getPortNumber());
|
||||
infraService.setPortType(portType);
|
||||
infraService.setInfraType(typeService);
|
||||
infraService.setProbe(probe);
|
||||
InfraService infraService = new InfraService();
|
||||
infraService.setHost(infraHost);
|
||||
infraService.setPort(port.getPortNumber());
|
||||
infraService.setPortType(portType);
|
||||
infraService.setInfraType(typeService);
|
||||
infraService.setProbe(probe);
|
||||
|
||||
if (port.getPortType() == PortType.TLS) {
|
||||
infraService.setTlsType(true);
|
||||
}
|
||||
infraService.setVendor(MetaInfraVendor.CreateInfraVendorByService(service.getServiceName()));
|
||||
if (port.getPortType() == PortType.TLS) {
|
||||
infraService.setTlsType(true);
|
||||
}
|
||||
infraService.setVendor(MetaInfraVendor.CreateInfraVendorByService(service.getServiceName()));
|
||||
|
||||
if(service.isTarget()) {
|
||||
Target targetService = new Target();
|
||||
targetService.setDisplayName(service.getServiceName() + "-Service");
|
||||
this.targetService.regist(targetService);
|
||||
infraService.setTarget(targetService);
|
||||
}
|
||||
if(service.isTarget()) {
|
||||
Target targetService = new Target();
|
||||
targetService.setDisplayName(service.getServiceName());
|
||||
this.targetService.regist(targetService);
|
||||
infraService.setTarget(targetService);
|
||||
}
|
||||
|
||||
this.infraServiceService.regist(infraService);
|
||||
this.infraServiceService.regist(infraService);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void createPort(InfraHost infraHost, Host host, Probe probe) {
|
||||
private void createPort(InfraHost infraHost, Host host, Probe probe) {
|
||||
|
||||
if(host.getPorts() == null) {
|
||||
return;
|
||||
}
|
||||
if(host.getPorts() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String portType = "UDP";
|
||||
String portType = "UDP";
|
||||
|
||||
MetaInfraType typePort = new MetaInfraType();
|
||||
typePort.setId(6);
|
||||
MetaInfraType typePort = new MetaInfraType();
|
||||
typePort.setId(6);
|
||||
|
||||
InfraOS infraOS = infraHost.getOs();
|
||||
InfraOS infraOS = infraHost.getOs();
|
||||
|
||||
for( String key: host.getPorts().keySet()) {
|
||||
// for( String key: host.getPorts().keySet()) {
|
||||
for( Port port: host.getPortList()) {
|
||||
// Port port = host.getPorts().get(key);
|
||||
|
||||
Port port = host.getPorts().get(key);
|
||||
if(port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP) {
|
||||
portType = "TCP";
|
||||
}
|
||||
|
||||
if(port.getPortType() == PortType.TLS || port.getPortType() == PortType.TCP) {
|
||||
portType = "TCP";
|
||||
}
|
||||
InfraOSPort dbInfraOSPort = this.infraOSPortService.readByPort(infraOS.getId(), port.getPortNumber(), portType);
|
||||
if(dbInfraOSPort == null) {
|
||||
InfraOSPort infraOSPort = new InfraOSPort();
|
||||
infraOSPort.setOs(infraOS);
|
||||
infraOSPort.setPort(port.getPortNumber());
|
||||
infraOSPort.setPortType(portType);
|
||||
infraOSPort.setProbe(probe);
|
||||
infraOSPort.setInfraType(typePort);
|
||||
|
||||
InfraOSPort dbInfraOSPort = this.infraOSPortService.readByPort(infraOS.getId(), port.getPortNumber(), portType);
|
||||
if(dbInfraOSPort == null) {
|
||||
InfraOSPort infraOSPort = new InfraOSPort();
|
||||
infraOSPort.setOs(infraOS);
|
||||
infraOSPort.setPort(port.getPortNumber());
|
||||
infraOSPort.setPortType(portType);
|
||||
infraOSPort.setProbe(probe);
|
||||
infraOSPort.setInfraType(typePort);
|
||||
if (port.getPortType() == PortType.TLS) {
|
||||
infraOSPort.setTlsType(true);
|
||||
}
|
||||
infraOSPort.setVendor(MetaInfraVendor.CreateInfraVendorByPort(port.getPortNumber()));
|
||||
this.infraOSPortService.regist(infraOSPort);
|
||||
}
|
||||
|
||||
if (port.getPortType() == PortType.TLS) {
|
||||
infraOSPort.setTlsType(true);
|
||||
}
|
||||
infraOSPort.setVendor(MetaInfraVendor.CreateInfraVendorByPort(port.getPortNumber()));
|
||||
this.infraOSPortService.regist(infraOSPort);
|
||||
}
|
||||
this.createService(infraHost, port, probe);
|
||||
}
|
||||
}
|
||||
|
||||
this.createService(infraHost, port, probe);
|
||||
}
|
||||
}
|
||||
|
||||
private InfraHost createAndReadHost(Host host, Probe probe) {
|
||||
private InfraHost createAndReadHost(Host host, Probe probe) {
|
||||
|
||||
|
||||
InfraHost infraHost = this.infraHostService.readByIp(StringConvertor.ipToLong(host.getIp()));
|
||||
if(infraHost != null) {
|
||||
InfraHost infraHost = this.infraHostService.readByIp(StringConvertor.ipToLong(host.getIp()));
|
||||
if(infraHost != null) {
|
||||
|
||||
if(host.isTarget() && infraHost.getTarget() == null) {
|
||||
Target target = new Target();
|
||||
target.setDisplayName(String.valueOf(host.getIp()) + "-Host");
|
||||
if(host.isTarget() && infraHost.getTarget() == null) {
|
||||
Target target = new Target();
|
||||
target.setDisplayName(String.valueOf(host.getIp()) + "-Host");
|
||||
|
||||
this.targetService.regist(target);
|
||||
infraHost.setTarget(target);
|
||||
this.infraHostService.regist(infraHost);
|
||||
}
|
||||
this.targetService.regist(target);
|
||||
infraHost.setTarget(target);
|
||||
this.infraHostService.regist(infraHost);
|
||||
}
|
||||
|
||||
return infraHost;
|
||||
} else {
|
||||
MetaInfraType typeMachine = new MetaInfraType();
|
||||
typeMachine.setId(1); // 1 = Machine;
|
||||
return infraHost;
|
||||
} else {
|
||||
MetaInfraType typeMachine = new MetaInfraType();
|
||||
typeMachine.setId(1); // 1 = Machine;
|
||||
|
||||
MetaInfraType typeOS = new MetaInfraType();
|
||||
typeOS.setId(3); // 3 = Os
|
||||
MetaInfraType typeOS = new MetaInfraType();
|
||||
typeOS.setId(3); // 3 = Os
|
||||
|
||||
MetaInfraType typeHost = new MetaInfraType();
|
||||
typeHost.setId(2); // 2 = Host
|
||||
MetaInfraType typeHost = new MetaInfraType();
|
||||
typeHost.setId(2); // 2 = Host
|
||||
|
||||
InfraMachine infraMachine = new InfraMachine();
|
||||
infraMachine.setProbe(probe);
|
||||
infraMachine.setInfraType(typeMachine);
|
||||
infraMachine.setMeta(host.getIp()+"-MACHINE");
|
||||
this.infraMachineService.regist(infraMachine);
|
||||
InfraMachine infraMachine = new InfraMachine();
|
||||
infraMachine.setProbe(probe);
|
||||
infraMachine.setInfraType(typeMachine);
|
||||
infraMachine.setMeta(host.getIp()+"-MACHINE");
|
||||
this.infraMachineService.regist(infraMachine);
|
||||
|
||||
InfraOS infraOS = new InfraOS();
|
||||
infraOS.setMachine(infraMachine);
|
||||
infraOS.setVendor(MetaInfraVendor.CreateInfraVendorByOS(host.getOs()));
|
||||
infraOS.setInfraType(typeOS);
|
||||
infraOS.setProbe(probe);
|
||||
infraOS.setMeta(host.getIp()+"-OS");
|
||||
this.infraOSService.regist(infraOS);
|
||||
InfraOS infraOS = new InfraOS();
|
||||
infraOS.setMachine(infraMachine);
|
||||
infraOS.setVendor(MetaInfraVendor.CreateInfraVendorByOS(host.getOs()));
|
||||
infraOS.setInfraType(typeOS);
|
||||
infraOS.setProbe(probe);
|
||||
infraOS.setMeta(host.getIp()+"-OS");
|
||||
this.infraOSService.regist(infraOS);
|
||||
|
||||
InfraHost newInfraHost = new InfraHost();
|
||||
newInfraHost.setIp(StringConvertor.ipToLong(host.getIp()));
|
||||
InfraHost newInfraHost = new InfraHost();
|
||||
newInfraHost.setIp(StringConvertor.ipToLong(host.getIp()));
|
||||
// newInfraHost.setMac(StringConvertor.ipToLong(host.getMac()));
|
||||
newInfraHost.setMac(StringConvertor.macStrToLong(host.getMac()));
|
||||
newInfraHost.setOs(infraOS);
|
||||
newInfraHost.setInfraType(typeHost);
|
||||
newInfraHost.setProbe(probe);
|
||||
newInfraHost.setMac(StringConvertor.macStrToLong(host.getMac()));
|
||||
newInfraHost.setOs(infraOS);
|
||||
newInfraHost.setInfraType(typeHost);
|
||||
newInfraHost.setProbe(probe);
|
||||
|
||||
|
||||
if(host.isTarget()) {
|
||||
Target target = new Target();
|
||||
target.setDisplayName(host.getIp() + "-Host");
|
||||
if(host.isTarget()) {
|
||||
Target target = new Target();
|
||||
target.setDisplayName(host.getIp() + "-Host");
|
||||
|
||||
this.targetService.regist(target);
|
||||
newInfraHost.setTarget(target);
|
||||
}
|
||||
this.targetService.regist(target);
|
||||
newInfraHost.setTarget(target);
|
||||
}
|
||||
|
||||
this.infraHostService.regist(newInfraHost);
|
||||
infraHost = newInfraHost;
|
||||
}
|
||||
this.infraHostService.regist(newInfraHost);
|
||||
infraHost = newInfraHost;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return infraHost;
|
||||
}
|
||||
|
||||
return infraHost;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
1
src/test/resources/180403-td.json
Normal file
1
src/test/resources/180403-td.json
Normal file
|
@ -0,0 +1 @@
|
|||
[{"id":0,"ip":"192.168.1.254","mac":"64:e5:99:63:e7:80","os":null,"discoveredDate":-62135596800000,"target":false,"zone":null,"ports":{},"portList":[{"id":0,"portType":"UDP","portNumber":53,"discoveredDate":-62135596800000,"host":null,"services":{},"serviceList":[{"id":0,"cryptoType":null,"serviceName":"DNS","discoveredDate":-62135596800000,"port":null,"target":false}]}]},{"id":0,"ip":"192.168.1.99","mac":"00:25:b3:fa:ca:9b","os":null,"discoveredDate":-62135596800000,"target":false,"zone":null,"ports":{},"portList":[{"id":0,"portType":"UDP","portNumber":161,"discoveredDate":-62135596800000,"host":null,"services":{},"serviceList":[{"id":0,"cryptoType":null,"serviceName":"SNMP_V2","discoveredDate":-62135596800000,"port":null,"target":false}]},{"id":0,"portType":"TCP","portNumber":7,"discoveredDate":-62135596800000,"host":null,"services":null}]},{"id":0,"ip":"192.168.1.206","mac":"30:9c:23:15:a3:09","os":null,"discoveredDate":-62135596800000,"target":false,"zone":null,"ports":null},{"id":0,"ip":"192.168.1.50","mac":"6c:f0:49:7a:60:68","os":null,"discoveredDate":-62135596800000,"target":false,"zone":null,"ports":{},"portList":[{"id":0,"portType":"TCP","portNumber":22,"discoveredDate":-62135596800000,"host":null,"services":{},"serviceList":[{"id":0,"cryptoType":"TCP","serviceName":"SSH","discoveredDate":-62135596800000,"port":null,"target":false}]}]},{"id":0,"ip":"192.168.1.15","mac":"00:19:b9:35:8e:a6","os":null,"discoveredDate":-62135596800000,"target":false,"zone":null,"ports":{},"portList":[{"id":0,"portType":"TCP","portNumber":22,"discoveredDate":-62135596800000,"host":null,"services":null},{"id":0,"portType":"TCP","portNumber":25,"discoveredDate":-62135596800000,"host":null,"services":null}]},{"id":0,"ip":"192.168.1.100","mac":"00:17:08:8d:cf:f7","os":null,"discoveredDate":-62135596800000,"target":false,"zone":null,"ports":{},"portList":[{"id":0,"portType":"UDP","portNumber":161,"discoveredDate":-62135596800000,"host":null,"services":{},"serviceList":[{"id":0,"cryptoType":null,"serviceName":"SNMP_V2","discoveredDate":-62135596800000,"port":null,"target":false}]},{"id":0,"portType":"TCP","portNumber":23,"discoveredDate":-62135596800000,"host":null,"services":null},{"id":0,"portType":"TCP","portNumber":21,"discoveredDate":-62135596800000,"host":null,"services":null}]},{"id":0,"ip":"192.168.1.16","mac":"00:19:b9:19:7e:c7","os":null,"discoveredDate":-62135596800000,"target":false,"zone":null,"ports":{},"portList":[{"id":0,"portType":"TCP","portNumber":22,"discoveredDate":-62135596800000,"host":null,"services":null}]},{"id":0,"ip":"192.168.1.106","mac":"44:8a:5b:f1:3a:7d","os":null,"discoveredDate":-62135596800000,"target":false,"zone":null,"ports":{},"portList":[{"id":0,"portType":"UDP","portNumber":161,"discoveredDate":-62135596800000,"host":null,"services":{},"serviceList":[{"id":0,"cryptoType":null,"serviceName":"SNMP_V2","discoveredDate":-62135596800000,"port":null,"target":false}]},{"id":0,"portType":"TCP","portNumber":21,"discoveredDate":-62135596800000,"host":null,"services":null}]},{"id":0,"ip":"192.168.1.101","mac":"44:8a:5b:f1:f1:f3","os":null,"discoveredDate":-62135596800000,"target":false,"zone":null,"ports":null},{"id":0,"ip":"192.168.1.102","mac":"44:8a:5b:f1:f2:d3","os":null,"discoveredDate":-62135596800000,"target":false,"zone":null,"ports":null},{"id":0,"ip":"192.168.1.205","mac":"40:98:ad:7b:d0:43","os":null,"discoveredDate":-62135596800000,"target":false,"zone":null,"ports":null},{"id":0,"ip":"192.168.1.103","mac":"44:8a:5b:44:8c:e8","os":null,"discoveredDate":-62135596800000,"target":false,"zone":null,"ports":{},"portList":[{"id":0,"portType":"TCP","portNumber":21,"discoveredDate":-62135596800000,"host":null,"services":null}]},{"id":0,"ip":"192.168.1.10","mac":"d0:50:99:97:5d:99","os":null,"discoveredDate":-62135596800000,"target":false,"zone":null,"ports":{},"portList":[{"id":0,"portType":"TCP","portNumber":22,"discoveredDate":-62135596800000,"host":null,"services":null}]},{"id":0,"ip":"192.168.1.203","mac":"a8:e5:39:5b:c9:62","os":null,"discoveredDate":-62135596800000,"target":false,"zone":null,"ports":null}]
|
Loading…
Reference in New Issue
Block a user