diff --git a/src/main/java/com/loafle/overflow/central/module/generator/service/InfraHostGenerator.java b/src/main/java/com/loafle/overflow/central/module/generator/service/InfraHostGenerator.java index 1f76d2a..db14e9a 100644 --- a/src/main/java/com/loafle/overflow/central/module/generator/service/InfraHostGenerator.java +++ b/src/main/java/com/loafle/overflow/central/module/generator/service/InfraHostGenerator.java @@ -85,7 +85,7 @@ public class InfraHostGenerator { Target target = new Target(); Connection connection = new Connection(); - connection.setIp(StringConvertor.intToIp(infraHost.getIp())); + connection.setIp(infraHost.getIpv4()); HashMap optionMap = this.objectMapper.readValue(authCrawler.getAuthJson(), new TypeReference>(){}); diff --git a/src/main/java/com/loafle/overflow/central/module/generator/service/InfraServiceGenerator.java b/src/main/java/com/loafle/overflow/central/module/generator/service/InfraServiceGenerator.java index 4b25ca8..5d014cc 100644 --- a/src/main/java/com/loafle/overflow/central/module/generator/service/InfraServiceGenerator.java +++ b/src/main/java/com/loafle/overflow/central/module/generator/service/InfraServiceGenerator.java @@ -90,7 +90,7 @@ public class InfraServiceGenerator { Target target = new Target(); Connection connection = new Connection(); - connection.setIp(StringConvertor.intToIp(infraService.getHost().getIp())); + connection.setIp(infraService.getHost().getIpv4()); connection.setPort(infraService.getPort()); connection.setPortType(PortType.valueOf(infraService.getPortType())); connection.setSsl(infraService.isTlsType()); @@ -102,7 +102,7 @@ public class InfraServiceGenerator { Map auth = new HashMap<>(); if(sensor.getCrawler().getId() == MetaCrawlerEnum.MYSQL_CRAWLER.getValue()) { - auth.put("url", "jdbc:mysql://"+ StringConvertor.intToIp(infraService.getHost().getIp())+":"+String.valueOf(infraService.getPort())); + auth.put("url", "jdbc:mysql://"+ infraService.getHost().getIpv4() +":" + infraService.getPort()); auth.put("id", optionMap.get("ID")); // FIXME: Auth Info auth.put("pw", optionMap.get("PassWord")); // FIXME: Auth Info } else if (sensor.getCrawler().getId() == MetaCrawlerEnum.JMX_CRAWLER.getValue()) { diff --git a/src/main/java/com/loafle/overflow/central/module/infra/dao/InfraHostDAO.java b/src/main/java/com/loafle/overflow/central/module/infra/dao/InfraHostDAO.java index 338ddb4..0a2b446 100644 --- a/src/main/java/com/loafle/overflow/central/module/infra/dao/InfraHostDAO.java +++ b/src/main/java/com/loafle/overflow/central/module/infra/dao/InfraHostDAO.java @@ -9,6 +9,6 @@ import org.springframework.stereotype.Repository; */ @Repository public interface InfraHostDAO extends JpaRepository { - InfraHost findByIp(long ip); + InfraHost findByIp(String ip); } \ No newline at end of file diff --git a/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraHostService.java b/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraHostService.java index fafaf4a..8ac3bf3 100644 --- a/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraHostService.java +++ b/src/main/java/com/loafle/overflow/central/module/infra/service/CentralInfraHostService.java @@ -24,7 +24,7 @@ public class CentralInfraHostService implements InfraHostService { return this.infraHostDAO.findOne(id); } - public InfraHost readByIp(long ip) throws OverflowException { + public InfraHost readByIp(String ip) throws OverflowException { return this.infraHostDAO.findByIp(ip); } } diff --git a/src/main/java/com/loafle/overflow/central/module/noauthprobe/service/CentralNoAuthProbeService.java b/src/main/java/com/loafle/overflow/central/module/noauthprobe/service/CentralNoAuthProbeService.java index 93522ef..1ae9c99 100644 --- a/src/main/java/com/loafle/overflow/central/module/noauthprobe/service/CentralNoAuthProbeService.java +++ b/src/main/java/com/loafle/overflow/central/module/noauthprobe/service/CentralNoAuthProbeService.java @@ -188,8 +188,8 @@ public class CentralNoAuthProbeService implements NoAuthProbeService { String addrStr = netMap.get("address"); String[] addrArr = addrStr.split("\\|"); - infraHost.setIp(StringConvertor.ipToLong(addrArr[1])); - infraHost.setMac(StringConvertor.macStrToLong(netMap.get("macAddress"))); + infraHost.setIpv4(addrArr[0]); + infraHost.setMac(netMap.get("macAddress")); infraHost.setOs(infraOS); infraHost.setInfraType(infraType); diff --git a/src/main/java/com/loafle/overflow/central/module/target/service/CentralTargetDiscoveryService.java b/src/main/java/com/loafle/overflow/central/module/target/service/CentralTargetDiscoveryService.java index d91125c..ee426fe 100644 --- a/src/main/java/com/loafle/overflow/central/module/target/service/CentralTargetDiscoveryService.java +++ b/src/main/java/com/loafle/overflow/central/module/target/service/CentralTargetDiscoveryService.java @@ -1,6 +1,5 @@ package com.loafle.overflow.central.module.target.service; -import com.loafle.overflow.central.commons.utils.StringConvertor; import com.loafle.overflow.central.module.infra.service.*; import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.core.type.PortType; @@ -37,8 +36,8 @@ public class CentralTargetDiscoveryService implements TargetDiscoveryService{ @Autowired private CentralInfraHostService infraHostService; - @Autowired - private CentralInfraService infraService; + // @Autowired + // private CentralInfraService infraService; @Autowired private CentralInfraOSPortService infraOSPortService; @@ -169,12 +168,12 @@ public class CentralTargetDiscoveryService implements TargetDiscoveryService{ private InfraHost createAndReadHost(Host host, Probe probe) throws OverflowException { - InfraHost infraHost = this.infraHostService.readByIp(StringConvertor.ipToLong(host.getIp())); + InfraHost infraHost = this.infraHostService.readByIp(host.getIpv4()); if(infraHost != null) { if(host.isTarget() && infraHost.getTarget() == null) { Target target = new Target(); - target.setDisplayName(String.valueOf(host.getIp()) + "-Host"); + target.setDisplayName(host.getIpv4() + "-Host"); this.targetService.regist(target); infraHost.setTarget(target); @@ -195,7 +194,7 @@ public class CentralTargetDiscoveryService implements TargetDiscoveryService{ InfraMachine infraMachine = new InfraMachine(); infraMachine.setProbe(probe); infraMachine.setInfraType(typeMachine); - infraMachine.setMeta(host.getIp()+"-MACHINE"); + infraMachine.setMeta(host.getIpv4()+"-MACHINE"); this.infraMachineService.regist(infraMachine); InfraOS infraOS = new InfraOS(); @@ -203,13 +202,12 @@ public class CentralTargetDiscoveryService implements TargetDiscoveryService{ infraOS.setVendor(MetaInfraVendor.CreateInfraVendorByOS(host.getOs())); infraOS.setInfraType(typeOS); infraOS.setProbe(probe); - infraOS.setMeta(host.getIp()+"-OS"); + infraOS.setMeta(host.getIpv4()+"-OS"); this.infraOSService.regist(infraOS); InfraHost newInfraHost = new InfraHost(); - newInfraHost.setIp(StringConvertor.ipToLong(host.getIp())); -// newInfraHost.setMac(StringConvertor.ipToLong(host.getMac())); - newInfraHost.setMac(StringConvertor.macStrToLong(host.getMac())); + newInfraHost.setIpv4(host.getIpv4()); + newInfraHost.setMac(host.getMac()); newInfraHost.setOs(infraOS); newInfraHost.setInfraType(typeHost); newInfraHost.setProbe(probe); @@ -217,7 +215,7 @@ public class CentralTargetDiscoveryService implements TargetDiscoveryService{ if(host.isTarget()) { Target target = new Target(); - target.setDisplayName(host.getIp() + "-Host"); + target.setDisplayName(host.getIpv4() + "-Host"); this.targetService.regist(target); newInfraHost.setTarget(target); diff --git a/src/main/resources/local/init.sql b/src/main/resources/local/init.sql index c8658fb..e75a0ca 100644 --- a/src/main/resources/local/init.sql +++ b/src/main/resources/local/init.sql @@ -972,8 +972,8 @@ INSERT INTO public.infra_machine (meta,id) VALUES ( INSERT INTO public.infra_os (meta,id,machine_id,vendor_id) VALUES ( '',2,1,24); -INSERT INTO public.infra_host (ip,mac,id,os_id) VALUES ( -3232235980,8796753988883,3,2); +INSERT INTO public.infra_host (ip_v4,ip_v6,mac,id,os_id) VALUES ( +'192.168.1.111','fe80::b83c:44a8:5d71:5bc0%3','30-9C-23-15-A3-09',3,2); -- INSERT INTO public.infra_service (port,port_type,tls_type,id,host_id,vendor_id) VALUES ( -- 80,'TCP',false,4,3,45); diff --git a/src/test/java/com/loafle/overflow/central/module/infra/service/InfraHostServiceTest.java b/src/test/java/com/loafle/overflow/central/module/infra/service/InfraHostServiceTest.java index 2ac8b23..604e34b 100644 --- a/src/test/java/com/loafle/overflow/central/module/infra/service/InfraHostServiceTest.java +++ b/src/test/java/com/loafle/overflow/central/module/infra/service/InfraHostServiceTest.java @@ -1,6 +1,5 @@ package com.loafle.overflow.central.module.infra.service; -import com.google.gson.Gson; import com.loafle.overflow.central.spring.AppConfigTest; import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.model.infra.InfraHost; @@ -16,12 +15,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - /** * Created by snoop on 17. 7. 27. */ @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {AppConfigTest.class}) +@ContextConfiguration(classes = { AppConfigTest.class }) public class InfraHostServiceTest { @Autowired @@ -36,9 +34,8 @@ public class InfraHostServiceTest { InfraHost infraHost = new InfraHost(); - infraHost.setMac(8796753988883L); - infraHost.setIp(3232235980L); - + infraHost.setMac("30-9C-23-15-A3-09"); + infraHost.setIpv4("192.168.1.1"); InfraOS infraOS = new InfraOS(); infraOS.setId(2); @@ -59,7 +56,7 @@ public class InfraHostServiceTest { InfraHost infraHost = this.infraHostService.read(1); - String json = objectMapper.writeValueAsString(infraHost); + String json = objectMapper.writeValueAsString(infraHost); System.out.println(json); @@ -69,14 +66,13 @@ public class InfraHostServiceTest { public void readByIp() { InfraHost infraHost; - try { - infraHost = this.infraHostService.readByIp(3232235980L); + try { + infraHost = this.infraHostService.readByIp("192.168.1.1"); Assert.assertNotEquals(infraHost, null); - } catch (OverflowException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - + } catch (OverflowException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } }