From b9170daea5c5da0d76e5b93b56f51e8015f75dbc Mon Sep 17 00:00:00 2001 From: snoop Date: Fri, 8 Sep 2017 14:26:44 +0900 Subject: [PATCH] fixed int crawler id -> enum --- .../generator/service/GenerateUtil.java | 66 +++++++----------- .../generator/service/InfraHostGenerator.java | 8 +-- .../service/InfraServiceGenerator.java | 10 +-- .../service/InfraServiceMysqlGenerator.java | 67 +++++++++---------- .../module/meta/type/MetaCrawlerEnum.java | 44 ++++++++++++ 5 files changed, 109 insertions(+), 86 deletions(-) create mode 100644 src/main/java/com/loafle/overflow/module/meta/type/MetaCrawlerEnum.java diff --git a/src/main/java/com/loafle/overflow/module/generator/service/GenerateUtil.java b/src/main/java/com/loafle/overflow/module/generator/service/GenerateUtil.java index d883485..cb9ef76 100644 --- a/src/main/java/com/loafle/overflow/module/generator/service/GenerateUtil.java +++ b/src/main/java/com/loafle/overflow/module/generator/service/GenerateUtil.java @@ -8,6 +8,7 @@ import com.loafle.overflow.module.infra.model.InfraHost; import com.loafle.overflow.module.meta.model.MetaCrawler; import com.loafle.overflow.module.meta.model.MetaSensorItemKey; import com.loafle.overflow.module.meta.service.MetaSensorItemKeyService; +import com.loafle.overflow.module.meta.type.MetaCrawlerEnum; import com.loafle.overflow.module.sensor.model.Sensor; import com.loafle.overflow.module.sensor.model.SensorItem; import org.springframework.beans.factory.annotation.Autowired; @@ -51,15 +52,11 @@ public class GenerateUtil { Map auth = new HashMap<>(); - switch (metaCrawler.getId()) { - case 11: // mysql - { - auth.put("url", "jdbc:mysql://"+ StringConvertor.intToIp(infraService.getHost().getIp())+":"+String.valueOf(infraService.getPort())); - auth.put("id", "docker"); // FIXME: Auth Info - auth.put("pw", "qwer5795QWER"); // FIXME: Auth Info - } - break; - } + if(metaCrawler.getId() == MetaCrawlerEnum.MYSQL_CRAWLER.getValue()) { + auth.put("url", "jdbc:mysql://"+ StringConvertor.intToIp(infraService.getHost().getIp())+":"+String.valueOf(infraService.getPort())); + auth.put("id", "docker"); // FIXME: Auth Info + auth.put("pw", "qwer5795QWER"); // FIXME: Auth Info + } return auth; } @@ -71,22 +68,17 @@ public class GenerateUtil { String container = ""; - switch (metaCrawler.getId()) { - case 1: - break; - case 2: - case 9: - case 10: - case 11: - case 13: - case 15: - container = "java_proxy"; - break; - default: - container = "java_proxy"; - break; + if(metaCrawler.getId() == MetaCrawlerEnum.CASSANDRA_CRAWLER.getValue() + || metaCrawler.getId() == MetaCrawlerEnum.CASSANDRA_CRAWLER.getValue() + || metaCrawler.getId() == MetaCrawlerEnum.MONGODB_CRAWLER.getValue() + || metaCrawler.getId() == MetaCrawlerEnum.MSSQL_CRAWLER.getValue() + || metaCrawler.getId() == MetaCrawlerEnum.ORACLE_CRAWLER.getValue() + || metaCrawler.getId() == MetaCrawlerEnum.POSTGRESQL_CRAWLER.getValue()) { + container = "java_proxy"; + } + else { + container = "network_proxy"; } - crawler.setContainer(container); @@ -99,28 +91,22 @@ public class GenerateUtil { Connection connection = new Connection(); connection.setIp(StringConvertor.intToIp(infraHost.getIp())); + if(dbSensor.getCrawler().getId() == MetaCrawlerEnum.WMI_CRAWLER.getValue()) { + connection.setPort("135"); + connection.setPortType("tcp"); + connection.setSsl(false); - switch (dbSensor.getCrawler().getId()) { - case 23: - { - connection.setPort("135"); - connection.setPortType("tcp"); - connection.setSsl(false); + target.setConnection(connection); - target.setConnection(connection); + // FIXME: load crawler Auth Info + Map auth = new HashMap<>(); + auth.put("id", "administrator"); + auth.put("pw", "dbseogns18"); - // FIXME: load crawler Auth Info - Map auth = new HashMap<>(); - auth.put("id", "administrator"); - auth.put("pw", "dbseogns18"); + target.setAuth(auth); - target.setAuth(auth); - - } - break; } - return target; } diff --git a/src/main/java/com/loafle/overflow/module/generator/service/InfraHostGenerator.java b/src/main/java/com/loafle/overflow/module/generator/service/InfraHostGenerator.java index ba007bb..f89dd02 100644 --- a/src/main/java/com/loafle/overflow/module/generator/service/InfraHostGenerator.java +++ b/src/main/java/com/loafle/overflow/module/generator/service/InfraHostGenerator.java @@ -6,6 +6,7 @@ import com.loafle.overflow.crawler.config.Schedule; import com.loafle.overflow.module.infra.model.Infra; import com.loafle.overflow.module.infra.model.InfraHost; import com.loafle.overflow.module.meta.model.MetaSensorItemKey; +import com.loafle.overflow.module.meta.type.MetaCrawlerEnum; import com.loafle.overflow.module.sensor.model.Sensor; import com.loafle.overflow.module.sensor.model.SensorItem; import org.codehaus.jackson.map.ObjectMapper; @@ -49,11 +50,8 @@ public class InfraHostGenerator { Map keyMap = this.generateUtil.initMappingMap(dbSensor.getCrawler()); - switch (dbSensor.getCrawler().getId()) { - case 23: - this.infraHostWMIGenerator.process(sensorItems, keyMap, dbSensor, config); - default: - break; + if(dbSensor.getCrawler().getId() == MetaCrawlerEnum.WMI_CRAWLER.getValue()) { + this.infraHostWMIGenerator.process(sensorItems, keyMap, dbSensor, config); } ObjectMapper objectMapper = new ObjectMapper(); diff --git a/src/main/java/com/loafle/overflow/module/generator/service/InfraServiceGenerator.java b/src/main/java/com/loafle/overflow/module/generator/service/InfraServiceGenerator.java index 398008b..636bf53 100644 --- a/src/main/java/com/loafle/overflow/module/generator/service/InfraServiceGenerator.java +++ b/src/main/java/com/loafle/overflow/module/generator/service/InfraServiceGenerator.java @@ -7,6 +7,7 @@ import com.loafle.overflow.crawler.config.Crawler; import com.loafle.overflow.crawler.config.Schedule; import com.loafle.overflow.module.infra.model.Infra; import com.loafle.overflow.module.meta.model.MetaSensorItemKey; +import com.loafle.overflow.module.meta.type.MetaCrawlerEnum; import com.loafle.overflow.module.sensor.model.Sensor; import com.loafle.overflow.module.sensor.model.SensorItem; import org.codehaus.jackson.map.ObjectMapper; @@ -60,13 +61,8 @@ public class InfraServiceGenerator { Map keyMap = this.generateUtil.initMappingMap(dbSensor.getCrawler()); - switch (dbSensor.getCrawler().getId()) { - case 11: - this.infraServiceMysqlGenerator.process(sensorItems, keyMap, dbSensor, config); -// case 23: -// processWMI(sensorItems, keyMap, dbSensor, config); - default: - break; + if(dbSensor.getCrawler().getId() == MetaCrawlerEnum.MYSQL_CRAWLER.getValue()) { + this.infraServiceMysqlGenerator.process(sensorItems, keyMap, dbSensor, config); } ObjectMapper objectMapper = new ObjectMapper(); diff --git a/src/main/java/com/loafle/overflow/module/generator/service/InfraServiceMysqlGenerator.java b/src/main/java/com/loafle/overflow/module/generator/service/InfraServiceMysqlGenerator.java index 0e0a1e0..01c5c87 100644 --- a/src/main/java/com/loafle/overflow/module/generator/service/InfraServiceMysqlGenerator.java +++ b/src/main/java/com/loafle/overflow/module/generator/service/InfraServiceMysqlGenerator.java @@ -1,7 +1,6 @@ package com.loafle.overflow.module.generator.service; import com.loafle.overflow.crawler.config.*; -import com.loafle.overflow.module.meta.model.MetaCrawler; import com.loafle.overflow.module.meta.model.MetaSensorItemKey; import com.loafle.overflow.module.sensor.model.Sensor; import com.loafle.overflow.module.sensor.model.SensorItem; @@ -117,37 +116,37 @@ public class InfraServiceMysqlGenerator { // return objectMapper.writeValueAsString(config); } - public void setQueryAndMapping(MetaCrawler metaCrawler, List keysList, QueryInfo queryInfo, MappingInfo mappingInfo) { - - switch (metaCrawler.getId()) { - case 11: // mysql - { - String query = "show status where "; -// queryInfo.setQuery("show status where "); - - Keys keys = null; - for(int indexI = 0 ; indexI < keysList.size(); ++indexI) { - keys = keysList.get(indexI); - query += "variable_name = '"; - query += keys.getKey(); - query += "'"; - if(indexI + 1 < keysList.size()) { - query += " or "; - } - } - - queryInfo.setQuery(query); - - mappingInfo.setParseDirection("row"); - mappingInfo.setValueColumn("Value"); - - List keyColumns = new ArrayList<>(); - keyColumns.add("Variable_name"); - - mappingInfo.setKeyColumns(keyColumns); - } - break; - } - - } +// public void setQueryAndMapping(MetaCrawler metaCrawler, List keysList, QueryInfo queryInfo, MappingInfo mappingInfo) { +// +// switch (metaCrawler.getId()) { +// case 11: // mysql +// { +// String query = "show status where "; +//// queryInfo.setQuery("show status where "); +// +// Keys keys = null; +// for(int indexI = 0 ; indexI < keysList.size(); ++indexI) { +// keys = keysList.get(indexI); +// query += "variable_name = '"; +// query += keys.getKey(); +// query += "'"; +// if(indexI + 1 < keysList.size()) { +// query += " or "; +// } +// } +// +// queryInfo.setQuery(query); +// +// mappingInfo.setParseDirection("row"); +// mappingInfo.setValueColumn("Value"); +// +// List keyColumns = new ArrayList<>(); +// keyColumns.add("Variable_name"); +// +// mappingInfo.setKeyColumns(keyColumns); +// } +// break; +// } +// +// } } diff --git a/src/main/java/com/loafle/overflow/module/meta/type/MetaCrawlerEnum.java b/src/main/java/com/loafle/overflow/module/meta/type/MetaCrawlerEnum.java new file mode 100644 index 0000000..b5c83bd --- /dev/null +++ b/src/main/java/com/loafle/overflow/module/meta/type/MetaCrawlerEnum.java @@ -0,0 +1,44 @@ +package com.loafle.overflow.module.meta.type; + +/** + * Created by snoop on 17. 9. 8. + */ +public enum MetaCrawlerEnum { + + ACTIVEDIRECTORY_CRAWLER((short)1), + CASSANDRA_CRAWLER((short)2), + DHCP_CRAWLER((short)3), + DNS_CRAWLER((short)4), + FTP_CRAWLER((short)5), + HTTP_CRAWLER((short)6), + IMAP_CRAWLER((short)7), + LDAP_CRAWLER((short)8), + MONGODB_CRAWLER((short)9), + MSSQL_CRAWLER((short)10), + MYSQL_CRAWLER((short)11), + NETBIOS_CRAWLER((short)12), + ORACLE_CRAWLER((short)13), + POP_CRAWLER((short)14), + POSTGRESQL_CRAWLER((short)15), + REDIS_CRAWLER((short)16), + RMI_CRAWLER((short)17), + SMB_CRAWLER((short)18), + SMTP_CRAWLER((short)19), + SNMP_CRAWLER((short)20), + SSH_CRAWLER((short)21), + TELNET_CRAWLER((short)22), + WMI_CRAWLER((short)23), + UNKNOWN_CRAWLER((short)24); + + + private short value; + + private MetaCrawlerEnum(short value) { + this.value = value; + } + + public short getValue() { + return this.value; + } + +}