auth info for generate config
This commit is contained in:
snoop 2017-09-11 15:01:54 +09:00
parent 39648273b4
commit 0153c0fd1f
8 changed files with 138 additions and 57 deletions

View File

@ -1,6 +1,8 @@
package com.loafle.overflow.module.auth.dao;
import com.loafle.overflow.module.auth.model.AuthCrawler;
import com.loafle.overflow.module.meta.model.MetaCrawler;
import com.loafle.overflow.module.target.model.Target;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@ -9,4 +11,5 @@ import org.springframework.stereotype.Repository;
*/
@Repository
public interface AuthCrawlerDAO extends JpaRepository<AuthCrawler, Long> {
AuthCrawler findByCrawlerAndTarget(MetaCrawler metaCrawler, Target target);
}

View File

@ -5,6 +5,7 @@ import com.loafle.overflow.module.auth.model.AuthCrawler;
import com.loafle.overflow.module.infra.model.Infra;
import com.loafle.overflow.module.infra.service.InfraService;
import com.loafle.overflow.module.meta.model.MetaCrawler;
import com.loafle.overflow.module.target.model.Target;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -28,8 +29,14 @@ public class AuthCrawlerService {
Infra infra = this.infraService.read(infraId);
// FIXME: Check Crawler
// FIXME: Check Crawler on Probe
return false;
}
public AuthCrawler readAuth(MetaCrawler metaCrawler, Target target) {
return this.authCrawlerDAO.findByCrawlerAndTarget(metaCrawler, target);
}
}

View File

@ -1,15 +1,11 @@
package com.loafle.overflow.module.generator.service;
import com.loafle.overflow.commons.utils.StringConvertor;
import com.loafle.overflow.crawler.config.Connection;
import com.loafle.overflow.crawler.config.Crawler;
import com.loafle.overflow.crawler.config.Keys;
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;
import org.springframework.stereotype.Service;
@ -28,6 +24,8 @@ public class GenerateUtil {
@Autowired
private MetaSensorItemKeyService metaSensorItemKeyService;
private Map<Short, Map<Integer, MetaSensorItemKey>> mappingMap = null;
public Map<Integer, MetaSensorItemKey> initMappingMap(MetaCrawler metaCrawler) {
@ -48,18 +46,7 @@ public class GenerateUtil {
return resultMap;
}
public Map<String, Object> getAuth(MetaCrawler metaCrawler, com.loafle.overflow.module.infra.model.InfraService infraService) {
Map<String, Object> auth = new HashMap<>();
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;
}
public Crawler getCrawler(MetaCrawler metaCrawler) {
@ -85,30 +72,7 @@ public class GenerateUtil {
return crawler;
}
public 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()));
if(dbSensor.getCrawler().getId() == MetaCrawlerEnum.WMI_CRAWLER.getValue()) {
connection.setPort("135");
connection.setPortType("tcp");
connection.setSsl(false);
target.setConnection(connection);
// FIXME: load crawler Auth Info
Map<String, Object> auth = new HashMap<>();
auth.put("id", "administrator");
auth.put("pw", "dbseogns18");
target.setAuth(auth);
}
return target;
}
public Map<String, List<MetaSensorItemKey>> sortItems(List<SensorItem> sensorItems, Map<Integer, MetaSensorItemKey> keyMap) {

View File

@ -1,8 +1,12 @@
package com.loafle.overflow.module.generator.service;
import com.loafle.overflow.commons.utils.StringConvertor;
import com.loafle.overflow.crawler.config.Config;
import com.loafle.overflow.crawler.config.Connection;
import com.loafle.overflow.crawler.config.Crawler;
import com.loafle.overflow.crawler.config.Schedule;
import com.loafle.overflow.module.auth.model.AuthCrawler;
import com.loafle.overflow.module.auth.service.AuthCrawlerService;
import com.loafle.overflow.module.infra.model.Infra;
import com.loafle.overflow.module.infra.model.InfraHost;
import com.loafle.overflow.module.meta.model.MetaSensorItemKey;
@ -10,10 +14,12 @@ 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;
import org.codehaus.jackson.type.TypeReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -29,6 +35,9 @@ public class InfraHostGenerator {
@Autowired
private InfraHostWMIGenerator infraHostWMIGenerator;
@Autowired
private AuthCrawlerService authCrawlerService;
public String process(Sensor dbSensor, List<SensorItem> sensorItems, Infra infra) throws IOException {
InfraHost infraHost = (InfraHost)infra;
@ -36,7 +45,11 @@ public class InfraHostGenerator {
Config config = new Config();
config.setId(String.valueOf(dbSensor.getId()));
com.loafle.overflow.crawler.config.Target target = this.generateUtil.createTarget(infraHost, dbSensor);
com.loafle.overflow.crawler.config.Target target = this.createTarget(infraHost, dbSensor);
if(target == null) {
return null;
}
config.setTarget(target);
@ -57,4 +70,37 @@ public class InfraHostGenerator {
ObjectMapper objectMapper = new ObjectMapper();
return objectMapper.writeValueAsString(config);
}
private com.loafle.overflow.crawler.config.Target createTarget(InfraHost infraHost, Sensor dbSensor) throws IOException {
AuthCrawler authCrawler = this.authCrawlerService.readAuth(dbSensor.getCrawler(), dbSensor.getTarget());
if(authCrawler == null) {
return null;
}
com.loafle.overflow.crawler.config.Target target = new com.loafle.overflow.crawler.config.Target();
Connection connection = new Connection();
connection.setIp(StringConvertor.intToIp(infraHost.getIp()));
HashMap<String,String> optionMap;
optionMap = new ObjectMapper().readValue(authCrawler.getAuthJson(), new TypeReference<HashMap<String,String>>() {});
if(dbSensor.getCrawler().getId() == MetaCrawlerEnum.WMI_CRAWLER.getValue()) {
connection.setPort("135");
connection.setPortType("tcp");
connection.setSsl(false);
target.setConnection(connection);
Map<String, Object> auth = new HashMap<>();
auth.put("id", optionMap.get("ID"));
auth.put("pw", optionMap.get("PassWord"));
target.setAuth(auth);
}
return target;
}
}

View File

@ -1,20 +1,23 @@
package com.loafle.overflow.module.generator.service;
import com.loafle.overflow.commons.utils.StringConvertor;
import com.loafle.overflow.crawler.config.Config;
import com.loafle.overflow.crawler.config.Connection;
import com.loafle.overflow.crawler.config.Crawler;
import com.loafle.overflow.crawler.config.Schedule;
import com.loafle.overflow.crawler.config.*;
import com.loafle.overflow.module.auth.model.AuthCrawler;
import com.loafle.overflow.module.auth.service.AuthCrawlerService;
import com.loafle.overflow.module.infra.model.Infra;
import com.loafle.overflow.module.infra.model.InfraService;
import com.loafle.overflow.module.meta.model.MetaCrawler;
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;
import org.codehaus.jackson.type.TypeReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -30,24 +33,21 @@ public class InfraServiceGenerator {
@Autowired
private InfraServiceMysqlGenerator infraServiceMysqlGenerator;
@Autowired
private AuthCrawlerService authCrawlerService;
public String process(Sensor dbSensor, List<SensorItem> 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 target = this.createTarget(infraService, dbSensor);
target.setConnection(connection);
if(target == null) {
return null;
}
Map<String, Object> auth = this.generateUtil.getAuth(dbSensor.getCrawler(), infraService);
target.setAuth(auth);
config.setTarget(target);
@ -68,4 +68,49 @@ public class InfraServiceGenerator {
ObjectMapper objectMapper = new ObjectMapper();
return objectMapper.writeValueAsString(config);
}
private Target createTarget(InfraService infraService, Sensor sensor) throws IOException {
AuthCrawler authCrawler = this.authCrawlerService.readAuth(sensor.getCrawler(), sensor.getTarget());
if(authCrawler == null) {
return null;
}
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);
HashMap<String,String> optionMap;
optionMap = new ObjectMapper().readValue(authCrawler.getAuthJson(), new TypeReference<HashMap<String,String>>() {});
Map<String, Object> 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("id", optionMap.get("ID")); // FIXME: Auth Info
auth.put("pw", optionMap.get("PassWord")); // FIXME: Auth Info
}
target.setAuth(auth);
return target;
}
private Map<String, Object> getAuth(MetaCrawler metaCrawler, com.loafle.overflow.module.infra.model.InfraService infraService) {
Map<String, Object> auth = new HashMap<>();
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;
}
}

View File

@ -1465,6 +1465,6 @@ INSERT INTO public.notification (id,confirm_date,create_date,message,title,membe
INSERT INTO public.auth_crawler (auth_json,create_date,crawler_id,target_id) VALUES (
'{"Community":"public"}','2017-09-08 18:31:05.126',20,5);
INSERT INTO public.auth_crawler (auth_json,create_date,crawler_id,target_id) VALUES (
'{"ID":"administrator","PassWord":"dbseogns18"}','2017-09-08 18:31:18.581',23,5);
'{"ID":"administrator","PassWord":"dbseogns18"}','2017-09-08 18:31:18.581',23,3);
INSERT INTO public.auth_crawler (auth_json,create_date,crawler_id,target_id) VALUES (
'{"DB Name":"test","ID":"docker","PassWord":"qwer5795QWER"}','2017-09-08 18:31:37.206',11,5);
'{"DB Name":"test","ID":"docker","PassWord":"qwer5795QWER"}','2017-09-08 18:31:37.206',11,4);

View File

@ -46,4 +46,20 @@ public class AuthCrawlerServiceTest {
}
@Test
public void findAuth() {
MetaCrawler metaCrawler = new MetaCrawler();
metaCrawler.setId((short)23);
Target target = new Target();
target.setId(5);
AuthCrawler authCrawler = this.authCrawlerService.readAuth(metaCrawler, target);
Assert.assertNotEquals(authCrawler, null);
}
}

View File

@ -65,7 +65,7 @@ public class SensorServiceTest {
public void generateSensorConfig() throws IOException {
Sensor sensor = new Sensor();
sensor.setId(4);
sensor.setId(3);
String result = this.sensorService.generateSensorConfig(sensor);
System.out.println(result);