diff --git a/src/main/java/com/loafle/overflow/module/sensor/service/SensorService.java b/src/main/java/com/loafle/overflow/module/sensor/service/SensorService.java index f7a236c..c6bc150 100644 --- a/src/main/java/com/loafle/overflow/module/sensor/service/SensorService.java +++ b/src/main/java/com/loafle/overflow/module/sensor/service/SensorService.java @@ -46,8 +46,6 @@ public class SensorService { @Autowired private SensorConfigGenerator sensorConfigGenerator; -// private Map> mappingMap = null; - public Sensor regist(Sensor sensor) { return this.sensorDAO.save(sensor); } @@ -112,375 +110,6 @@ public class SensorService { return this.sensorConfigGenerator.generate(sensor); -// PageParams pageParams = new PageParams(); -// pageParams.setPageNo(0); -// pageParams.setCountPerPage(Integer.MAX_VALUE); -// pageParams.setSortCol("id"); -// pageParams.setSortDirection("descending"); -// Page dbItemList = this.sensorItemService.readAllBySensor(sensor, pageParams); -// -// List sensorItems = dbItemList.getContent(); -// -// if(sensorItems.size() <= 0) { -// return ""; -// } -// Sensor dbSensor = sensorItems.get(0).getSensor(); -// -// Infra infra = this.infraService.readByTarget(dbSensor.getTarget()); -// -// // 7 = Infra OS Service -// if(infra.getInfraType().getId() == 7) { -// return this.processService(dbSensor, sensorItems, infra); -// } -// if(infra.getInfraType().getId() == 2) { -// return this.processHost(dbSensor, sensorItems, infra); -// } -// -// return null; } -// private String processHost(Sensor dbSensor, List sensorItems, Infra infra) throws IOException { -// -// InfraHost infraHost = (InfraHost)infra; -// -// Config config = new Config(); -// config.setId(String.valueOf(dbSensor.getId())); -// -// com.loafle.overflow.crawler.config.Target target = this.createTarget(infraHost, dbSensor); -// -// config.setTarget(target); -// -// // FIXME: Interval -// Schedule schedule = new Schedule(); -// schedule.setInterval("5"); -// config.setSchedule(schedule); -// -// Crawler crawler = this.getCrawler(dbSensor.getCrawler()); -// config.setCrawler(crawler); -// -// Map keyMap = this.initMappingMap(dbSensor.getCrawler()); -// -// switch (dbSensor.getCrawler().getId()) { -// case 23: -// processWMI(sensorItems, keyMap, dbSensor, config); -// default: -// break; -// } -// -// ObjectMapper objectMapper = new ObjectMapper(); -// return objectMapper.writeValueAsString(config); -// } - -// private com.loafle.overflow.crawler.config.Target createTarget(InfraHost infraHost, Sensor dbSensor) { -// -// com.loafle.overflow.crawler.config.Target target = new com.loafle.overflow.crawler.config.Target(); -// Connection connection = new Connection(); -// connection.setIp(StringConvertor.intToIp(infraHost.getIp())); -// -// -// switch (dbSensor.getCrawler().getId()) { -// case 23: -// { -// connection.setPort("135"); -// connection.setPortType("tcp"); -// connection.setSsl(false); -// -// target.setConnection(connection); -// -// // FIXME: load crawler Auth Info -// Map auth = new HashMap<>(); -// auth.put("id", "administrator"); -// auth.put("pw", "dbseogns18"); -// -// target.setAuth(auth); -// -// } -// break; -// } -// -// -// return target; -// } - -// private String processService(Sensor dbSensor, List sensorItems, Infra infra) throws IOException { -// com.loafle.overflow.module.infra.model.InfraService infraService = (com.loafle.overflow.module.infra.model.InfraService)infra; -// -// Config config = new Config(); -// config.setId(String.valueOf(dbSensor.getId())); -// -// com.loafle.overflow.crawler.config.Target target = new com.loafle.overflow.crawler.config.Target(); -// Connection connection = new Connection(); -// connection.setIp(StringConvertor.intToIp(infraService.getHost().getIp())); -// connection.setPort(String.valueOf(infraService.getPort())); -// connection.setPortType(infraService.getPortType()); -// connection.setSsl(infraService.isTlsType()); -// -// target.setConnection(connection); -// -// Map auth = this.getAuth(dbSensor.getCrawler(), infraService); -// -// target.setAuth(auth); -// -// config.setTarget(target); -// -// // FIXME: Interval -// Schedule schedule = new Schedule(); -// schedule.setInterval("5"); -// config.setSchedule(schedule); -// -// Crawler crawler = this.getCrawler(dbSensor.getCrawler()); -// config.setCrawler(crawler); -// -// Map keyMap = this.initMappingMap(dbSensor.getCrawler()); -// -// switch (dbSensor.getCrawler().getId()) { -// case 11: -// processMysql(sensorItems, keyMap, dbSensor, config); -// case 23: -// processWMI(sensorItems, keyMap, dbSensor, config); -// default: -// break; -// } -// -// ObjectMapper objectMapper = new ObjectMapper(); -// return objectMapper.writeValueAsString(config); -// } - -// private void processMysql(List sensorItems, Map KeyMap, Sensor dbSensor, Config config) throws IOException { -// Item item = new Item(); -// Keys keys = null; -// List keysList = new ArrayList<>(); -// for(SensorItem sItem : sensorItems) { -// keys = new Keys(); -// keys.setMetric(sItem.getItem().getKey()); -// keys.setKey(KeyMap.get(sItem.getItem().getId()).getKey()); -// keysList.add(keys); -// } -// item.setKeys(keysList); -// -// QueryInfo queryInfo = new QueryInfo(); -// MappingInfo mappingInfo = new MappingInfo(); -// -// this.setQueryAndMapping(dbSensor.getCrawler(), keysList, queryInfo, mappingInfo); -// -// item.setQueryInfo(queryInfo); -// item.setMappingInfo(mappingInfo); -// -// List itemList = new ArrayList<>(); -// itemList.add(item); -// -// config.setItems(itemList); -// -// -//// ObjectMapper objectMapper = new ObjectMapper(); -//// -//// return objectMapper.writeValueAsString(config); -// } -// private void processWMI(List sensorItems, Map keyMap, Sensor dbSensor, Config config) throws IOException { -// -// Map> metricMap = new HashMap<>(); -// -// MetaSensorItemKey itemKey = null; -// -// for(SensorItem sItem : sensorItems) { -// itemKey = keyMap.get(sItem.getItem().getId()); -// if(metricMap.containsKey(itemKey.getFroms()) == false) { -// metricMap.put(itemKey.getFroms(), new ArrayList<>()); -// } -// metricMap.get(itemKey.getFroms()).add(itemKey); -// } -// -// List itemList = new ArrayList<>(); -// Item item = null; -// QueryInfo queryInfo = null; -// MappingInfo mappingInfo = null; -// -// StringBuffer stringBuffer = new StringBuffer(); -// -// Map extendMap = new HashMap<>(); -// extendMap.put("nameSpace", "root/cimv2"); -// extendMap.put("wmicPath", "/home/snoop/temp/wmic"); -// -// -// List keysList = null; -// MetaSensorItemKey tempItemKey = null; -// Keys keys = null; -// for(Map.Entry> elems : metricMap.entrySet()) { -// keysList = new ArrayList<>(); -// item = new Item(); -// stringBuffer.setLength(0); -// -// stringBuffer.append("SELECT "); -// -// for(int indexI = 0; indexI < elems.getValue().size(); ++indexI) { -// -// tempItemKey = elems.getValue().get(indexI); -// stringBuffer.append(tempItemKey.getKey()); -// if(indexI + 1 < elems.getValue().size()) { -// stringBuffer.append(", "); -// } -// -// keys = new Keys(); -// keys.setKey(tempItemKey.getKey()); -// keys.setMetric(tempItemKey.getItem().getKey()); -// keysList.add(keys); -// } -// -// -// List arrayColumns = null; -// -// String json = tempItemKey.getOption(); -// if(json != null && json.length() > 0) { -// HashMap optionMap; -// optionMap = new ObjectMapper().readValue(json, new TypeReference>() {}); -// -// Object obj = null; -// obj = optionMap.get("appends"); -// if(obj != null) { -// List appendsList = (List)obj; -// for(String append : appendsList) { -// stringBuffer.append(", "); -// stringBuffer.append(append); -// } -// } -// -// stringBuffer.append(" FROM "); -// stringBuffer.append(elems.getKey()); -// -// obj = optionMap.get("where"); -// if(obj != null) { -// String where = (String)obj; -// stringBuffer.append(" WHERE "); -// stringBuffer.append(where); -// } -// -// obj = optionMap.get("arrayColumns"); -// if(obj != null) { -// arrayColumns = (List)obj; -// } -// -// } -// else { -// stringBuffer.append(" FROM "); -// stringBuffer.append(elems.getKey()); -// } -// -// queryInfo = new QueryInfo(); -// queryInfo.setQuery(stringBuffer.toString()); -// queryInfo.setExtend(extendMap); -// -// mappingInfo = new MappingInfo(); -// mappingInfo.setParseDirection("col"); -// mappingInfo.setArrayColumns(arrayColumns); -// -// item.setMappingInfo(mappingInfo); -// item.setQueryInfo(queryInfo); -// item.setKeys(keysList); -// -// itemList.add(item); -// -// } -// -// config.setItems(itemList); -// -// } - -// private 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; -// } -// -// } - -// private Map initMappingMap(MetaCrawler metaCrawler) { -// -// if(this.mappingMap == null) { -// this.mappingMap = new HashMap<>(); -// } -// -// Map resultMap = this.mappingMap.get(metaCrawler.getId()); -// -// if(resultMap != null) { -// return resultMap; -// } -// -// resultMap = this.metaSensorItemKeyService.readAllByCrawler(metaCrawler); -// this.mappingMap.put(metaCrawler.getId(), resultMap); -// -// return resultMap; -// } -// -// private Map getAuth(MetaCrawler metaCrawler, com.loafle.overflow.module.infra.model.InfraService infraService) { -// -// 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; -// } -// -// return auth; -// } -// -// private Crawler getCrawler(MetaCrawler metaCrawler) { -// -// Crawler crawler = new Crawler(); -// crawler.setName(metaCrawler.getName()); -// -// 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; -// } -// -// -// crawler.setContainer(container); -// -// return crawler; -// } - }