ing
This commit is contained in:
parent
6533a28d28
commit
3d3ea7b0b0
|
@ -5,7 +5,6 @@ import com.loafle.overflow.core.annotation.ProbeAPI;
|
||||||
import com.loafle.overflow.core.annotation.WebappAPI;
|
import com.loafle.overflow.core.annotation.WebappAPI;
|
||||||
import com.loafle.overflow.central.commons.utils.GenerateKey;
|
import com.loafle.overflow.central.commons.utils.GenerateKey;
|
||||||
import com.loafle.overflow.central.commons.utils.SessionMetadata;
|
import com.loafle.overflow.central.commons.utils.SessionMetadata;
|
||||||
import com.loafle.overflow.central.commons.utils.StringConvertor;
|
|
||||||
import com.loafle.overflow.central.module.noauthprobe.dao.NoAuthProbeDAO;
|
import com.loafle.overflow.central.module.noauthprobe.dao.NoAuthProbeDAO;
|
||||||
import com.loafle.overflow.core.exception.OverflowException;
|
import com.loafle.overflow.core.exception.OverflowException;
|
||||||
import com.loafle.overflow.model.apikey.ApiKey;
|
import com.loafle.overflow.model.apikey.ApiKey;
|
||||||
|
@ -20,6 +19,9 @@ import com.loafle.overflow.model.meta.MetaInfraVendor;
|
||||||
import com.loafle.overflow.model.meta.MetaNoAuthProbeStatus;
|
import com.loafle.overflow.model.meta.MetaNoAuthProbeStatus;
|
||||||
import com.loafle.overflow.model.meta.MetaProbeStatus;
|
import com.loafle.overflow.model.meta.MetaProbeStatus;
|
||||||
import com.loafle.overflow.model.noauthprobe.NoAuthProbe;
|
import com.loafle.overflow.model.noauthprobe.NoAuthProbe;
|
||||||
|
import com.loafle.overflow.model.noauthprobe.NoAuthProbeDescription;
|
||||||
|
import com.loafle.overflow.model.noauthprobe.NoAuthProbeDescriptionHost;
|
||||||
|
import com.loafle.overflow.model.noauthprobe.NoAuthProbeDescriptionNetwork;
|
||||||
import com.loafle.overflow.model.probe.Probe;
|
import com.loafle.overflow.model.probe.Probe;
|
||||||
import com.loafle.overflow.model.probe.ProbeHost;
|
import com.loafle.overflow.model.probe.ProbeHost;
|
||||||
import com.loafle.overflow.service.central.apikey.ApiKeyService;
|
import com.loafle.overflow.service.central.apikey.ApiKeyService;
|
||||||
|
@ -32,16 +34,13 @@ import com.loafle.overflow.service.central.probe.ProbeHostService;
|
||||||
import com.loafle.overflow.service.central.probe.ProbeService;
|
import com.loafle.overflow.service.central.probe.ProbeService;
|
||||||
|
|
||||||
import org.codehaus.jackson.map.ObjectMapper;
|
import org.codehaus.jackson.map.ObjectMapper;
|
||||||
import org.codehaus.jackson.type.TypeReference;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
@ -106,20 +105,17 @@ public class CentralNoAuthProbeService implements NoAuthProbeService {
|
||||||
@Transactional
|
@Transactional
|
||||||
public List<NoAuthProbe> acceptNoAuthProbe(NoAuthProbe noAuthProbe) throws OverflowException {
|
public List<NoAuthProbe> acceptNoAuthProbe(NoAuthProbe noAuthProbe) throws OverflowException {
|
||||||
|
|
||||||
HashMap<String, Object> objMap;
|
NoAuthProbeDescription noAuthProbeDescription = null;
|
||||||
try {
|
try {
|
||||||
objMap = this.objectMapper.readValue(noAuthProbe.getDescription(), new TypeReference<Map<String, Object>>(){});
|
noAuthProbeDescription = this.objectMapper.readValue(noAuthProbe.getDescription(), NoAuthProbeDescription.class);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new OverflowException("json error", e);
|
throw new OverflowException("json error", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, String> hostMap = (Map<String, String>) objMap.get("host");
|
Probe probe = this.newProbe(noAuthProbe, noAuthProbeDescription);
|
||||||
Map<String, String> netMap = (Map<String, String>) objMap.get("network");
|
|
||||||
|
|
||||||
Probe probe = this.newProbe(noAuthProbe, hostMap, netMap);
|
|
||||||
InfraMachine machine = this.newInfraMachine(noAuthProbe);
|
InfraMachine machine = this.newInfraMachine(noAuthProbe);
|
||||||
InfraOS os = this.newInfraOS(machine, hostMap);
|
InfraOS os = this.newInfraOS(machine, noAuthProbeDescription.getHost());
|
||||||
InfraHost host = this.newInfraHost(os, netMap);
|
InfraHost host = this.newInfraHost(os, noAuthProbeDescription.getNetwork());
|
||||||
this.newProbeHost(host, probe);
|
this.newProbeHost(host, probe);
|
||||||
|
|
||||||
noAuthProbe.setStatus(new MetaNoAuthProbeStatus((short) 1));
|
noAuthProbe.setStatus(new MetaNoAuthProbeStatus((short) 1));
|
||||||
|
@ -131,7 +127,7 @@ public class CentralNoAuthProbeService implements NoAuthProbeService {
|
||||||
return this.readAllByDomain(noAuthProbe.getDomain());
|
return this.readAllByDomain(noAuthProbe.getDomain());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Probe newProbe(NoAuthProbe noauthprobe, Map<String, String> hostMap, Map<String, String> netMap) throws OverflowException {
|
private Probe newProbe(NoAuthProbe noauthprobe, NoAuthProbeDescription noAuthProbeDescription) throws OverflowException {
|
||||||
|
|
||||||
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
||||||
String encryptKey = passwordEncoder.encode(UUID.randomUUID().toString());
|
String encryptKey = passwordEncoder.encode(UUID.randomUUID().toString());
|
||||||
|
@ -148,11 +144,11 @@ public class CentralNoAuthProbeService implements NoAuthProbeService {
|
||||||
probe.setTargetCount(0);
|
probe.setTargetCount(0);
|
||||||
probe.setStatus(new MetaProbeStatus((short) 1));
|
probe.setStatus(new MetaProbeStatus((short) 1));
|
||||||
|
|
||||||
String dispName = hostMap.get("name");
|
String dispName = noAuthProbeDescription.getHost().getName();
|
||||||
dispName += " probe";
|
dispName += " probe";
|
||||||
probe.setDisplayName(dispName);
|
probe.setDisplayName(dispName);
|
||||||
|
|
||||||
String addrStr = netMap.get("address");
|
String addrStr = noAuthProbeDescription.getNetwork().getAddress();
|
||||||
String[] addrArr = addrStr.split("\\|");
|
String[] addrArr = addrStr.split("\\|");
|
||||||
probe.setCidr(addrArr[0]);
|
probe.setCidr(addrArr[0]);
|
||||||
|
|
||||||
|
@ -170,28 +166,28 @@ public class CentralNoAuthProbeService implements NoAuthProbeService {
|
||||||
return this.infraMachineService.regist(infraMachine);
|
return this.infraMachineService.regist(infraMachine);
|
||||||
}
|
}
|
||||||
|
|
||||||
private InfraOS newInfraOS(InfraMachine infraMachine, Map<String, String> hostMap) throws OverflowException {
|
private InfraOS newInfraOS(InfraMachine infraMachine, NoAuthProbeDescriptionHost noAuthProbeDescriptionHost) throws OverflowException {
|
||||||
MetaInfraType infraType = new MetaInfraType();
|
MetaInfraType infraType = new MetaInfraType();
|
||||||
infraType.setId(3);
|
infraType.setId(3);
|
||||||
|
|
||||||
InfraOS infraOS = new InfraOS();
|
InfraOS infraOS = new InfraOS();
|
||||||
infraOS.setMachine(infraMachine);
|
infraOS.setMachine(infraMachine);
|
||||||
infraOS.setInfraType(infraType);
|
infraOS.setInfraType(infraType);
|
||||||
infraOS.setVendor(MetaInfraVendor.CreateInfraVendorByOS(hostMap.get("os")));
|
infraOS.setVendor(MetaInfraVendor.CreateInfraVendorByOS(noAuthProbeDescriptionHost.getOS()));
|
||||||
|
|
||||||
return this.infraOSService.regist(infraOS);
|
return this.infraOSService.regist(infraOS);
|
||||||
}
|
}
|
||||||
|
|
||||||
private InfraHost newInfraHost(InfraOS infraOS, Map<String, String> netMap) throws OverflowException {
|
private InfraHost newInfraHost(InfraOS infraOS, NoAuthProbeDescriptionNetwork noAuthProbeDescriptionNetwork) throws OverflowException {
|
||||||
MetaInfraType infraType = new MetaInfraType();
|
MetaInfraType infraType = new MetaInfraType();
|
||||||
infraType.setId(2);
|
infraType.setId(2);
|
||||||
|
|
||||||
InfraHost infraHost = new InfraHost();
|
InfraHost infraHost = new InfraHost();
|
||||||
String addrStr = netMap.get("address");
|
String addrStr = noAuthProbeDescriptionNetwork.getAddress();
|
||||||
String[] addrArr = addrStr.split("\\|");
|
String[] addrArr = addrStr.split("\\|");
|
||||||
|
|
||||||
infraHost.setIpv4(addrArr[0]);
|
infraHost.setIpv4(addrArr[0]);
|
||||||
infraHost.setMac(netMap.get("macAddress"));
|
infraHost.setMac(noAuthProbeDescriptionNetwork.getMacAddress());
|
||||||
infraHost.setOs(infraOS);
|
infraHost.setOs(infraOS);
|
||||||
infraHost.setInfraType(infraType);
|
infraHost.setInfraType(infraType);
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
datasource.url=jdbc:postgresql://192.168.1.50:5432/overflow
|
datasource.url=jdbc:postgresql://192.168.1.101:5432/overflow
|
||||||
datasource.username=overflow
|
datasource.username=overflow
|
||||||
datasource.password=qwer5795
|
datasource.password=qwer5795
|
||||||
datasource.driver-class-name=org.postgresql.Driver
|
datasource.driver-class-name=org.postgresql.Driver
|
||||||
|
|
|
@ -990,7 +990,7 @@ INSERT INTO public.infra_os_application ("name",id,os_id) VALUES (
|
||||||
INSERT INTO public.infra_os_daemon ("name",id,os_id) VALUES (
|
INSERT INTO public.infra_os_daemon ("name",id,os_id) VALUES (
|
||||||
'Apache',6,2);
|
'Apache',6,2);
|
||||||
|
|
||||||
insert into public.PROBE_INFRAHOST (HOST_ID, PROBE_ID) values (3, 1);
|
insert into public.probe_host (HOST_ID, PROBE_ID) values (3, 1);
|
||||||
|
|
||||||
|
|
||||||
INSERT INTO public.sensor (crawler_input_items,create_date,description,crawler_id,status,target_id,item_count,display_name) VALUES (
|
INSERT INTO public.sensor (crawler_input_items,create_date,description,crawler_id,status,target_id,item_count,display_name) VALUES (
|
||||||
|
@ -1237,10 +1237,10 @@ INSERT INTO public.noauth_probe (api_key,create_date,description,temp_probe_key,
|
||||||
'52abd6fd57e511e7ac52080027658d13','2017-06-26 12:43:46.877','{"host":{"name":"geek-ubuntu","os":"linux","paltform":"ubuntu","platformFamily":"debian","platformVersion":"","kernelVersion":"4.4.0-93-generic","hostID":"03000200-0400-0500-0006-000700080009"},"network":{"name":"enp3s0","address":"192.168.1.103/24|fe80::36c0:6c3e:6006:dd23/64","gateway":"192.168.1.254","macAddress":"44:8a:5b:f1:f1:f3"}}','1cf2555c57d511e79714080027658d13',1,NULL,3);
|
'52abd6fd57e511e7ac52080027658d13','2017-06-26 12:43:46.877','{"host":{"name":"geek-ubuntu","os":"linux","paltform":"ubuntu","platformFamily":"debian","platformVersion":"","kernelVersion":"4.4.0-93-generic","hostID":"03000200-0400-0500-0006-000700080009"},"network":{"name":"enp3s0","address":"192.168.1.103/24|fe80::36c0:6c3e:6006:dd23/64","gateway":"192.168.1.254","macAddress":"44:8a:5b:f1:f1:f3"}}','1cf2555c57d511e79714080027658d13',1,NULL,3);
|
||||||
|
|
||||||
INSERT INTO public.noauth_probe (api_key,create_date,description,temp_probe_key,domain_id,probe_id,status) VALUES (
|
INSERT INTO public.noauth_probe (api_key,create_date,description,temp_probe_key,domain_id,probe_id,status) VALUES (
|
||||||
'52abd6fd57e511e7ac52080027658d14','2017-08-11 12:43:46.877','{"host":{"name":"insanity-ubuntu","os":"linux","paltform":"ubuntu","platformFamily":"debian","platformVersion":"","kernelVersion":"4.4.0-93-generic","hostID":"4C4C4544-0044-4A10-8039-C7C04F595031"},"network":{"name":"enp3s0","address":"192.168.1.105/24|fe80::36c0:6c3e:6006:dd23/64","gateway":"192.168.1.254","macAddress":"44:8a:5b:f1:f1:f3"}}','1cf2555c57d511e79714080027658d14',1,NULL,3);
|
'52abd6fd57e511e7ac52080027658d13','2017-08-11 12:43:46.877','{"host":{"name":"insanity-ubuntu","os":"linux","paltform":"ubuntu","platformFamily":"debian","platformVersion":"","kernelVersion":"4.4.0-93-generic","hostID":"4C4C4544-0044-4A10-8039-C7C04F595031"},"network":{"name":"enp3s0","address":"192.168.1.105/24|fe80::36c0:6c3e:6006:dd23/64","gateway":"192.168.1.254","macAddress":"44:8a:5b:f1:f1:f3"}}','1cf2555c57d511e79714080027658d14',1,NULL,3);
|
||||||
|
|
||||||
INSERT INTO public.noauth_probe (api_key,create_date,description,temp_probe_key,domain_id,probe_id,status) VALUES (
|
INSERT INTO public.noauth_probe (api_key,create_date,description,temp_probe_key,domain_id,probe_id,status) VALUES (
|
||||||
'52abd6fd57e511e7ac52080027658d15','2017-08-11 12:43:46.877','{"host":{"name":"snoop-ubuntu","os":"linux","paltform":"ubuntu","platformFamily":"debian","platformVersion":"","kernelVersion":"4.4.0-93-generic","hostID":"DE60E4C3-347A-4D38-AEAB-1760471665EA"},"network":{"name":"enp3s0","address":"192.168.1.106/24|fe80::36c0:6c3e:6006:dd23/64","gateway":"192.168.1.254","macAddress":"44:8a:5b:f1:f1:f3"}}','1cf2555c57d511e79714080027658d15',1,NULL,3);
|
'52abd6fd57e511e7ac52080027658d13','2017-08-11 12:43:46.877','{"host":{"name":"snoop-ubuntu","os":"linux","paltform":"ubuntu","platformFamily":"debian","platformVersion":"","kernelVersion":"4.4.0-93-generic","hostID":"DE60E4C3-347A-4D38-AEAB-1760471665EA"},"network":{"name":"enp3s0","address":"192.168.1.106/24|fe80::36c0:6c3e:6006:dd23/64","gateway":"192.168.1.254","macAddress":"44:8a:5b:f1:f1:f3"}}','1cf2555c57d511e79714080027658d15',1,NULL,3);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user