ing
This commit is contained in:
parent
0eda0683de
commit
2b4aeea3e6
6
pom.xml
6
pom.xml
|
@ -179,12 +179,6 @@
|
|||
<version>1.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.loafle.overflow</groupId>
|
||||
<artifactId>crawler</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.loafle.overflow</groupId>
|
||||
<artifactId>commons-java</artifactId>
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package com.loafle.overflow.central.module.generator.service;
|
||||
|
||||
import com.loafle.overflow.core.exception.OverflowException;
|
||||
import com.loafle.overflow.crawler.config.Crawler;
|
||||
import com.loafle.overflow.crawler.config.Keys;
|
||||
import com.loafle.overflow.model.meta.MetaCrawler;
|
||||
import com.loafle.overflow.model.meta.MetaSensorItemKey;
|
||||
import com.loafle.overflow.model.meta.type.MetaCrawlerEnum;
|
||||
import com.loafle.overflow.model.sensor.SensorItem;
|
||||
import com.loafle.overflow.model.sensorconfig.Crawler;
|
||||
import com.loafle.overflow.model.sensorconfig.Keys;
|
||||
import com.loafle.overflow.service.central.meta.MetaSensorItemKeyService;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
|
@ -2,10 +2,7 @@ package com.loafle.overflow.central.module.generator.service;
|
|||
|
||||
import com.loafle.overflow.central.commons.utils.StringConvertor;
|
||||
import com.loafle.overflow.core.exception.OverflowException;
|
||||
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.core.type.PortType;
|
||||
import com.loafle.overflow.model.auth.AuthCrawler;
|
||||
import com.loafle.overflow.model.infra.Infra;
|
||||
import com.loafle.overflow.model.infra.InfraHost;
|
||||
|
@ -13,6 +10,11 @@ import com.loafle.overflow.model.meta.MetaSensorItemKey;
|
|||
import com.loafle.overflow.model.meta.type.MetaCrawlerEnum;
|
||||
import com.loafle.overflow.model.sensor.Sensor;
|
||||
import com.loafle.overflow.model.sensor.SensorItem;
|
||||
import com.loafle.overflow.model.sensorconfig.Connection;
|
||||
import com.loafle.overflow.model.sensorconfig.Crawler;
|
||||
import com.loafle.overflow.model.sensorconfig.Schedule;
|
||||
import com.loafle.overflow.model.sensorconfig.SensorConfig;
|
||||
import com.loafle.overflow.model.sensorconfig.Target;
|
||||
import com.loafle.overflow.service.central.auth.AuthCrawlerService;
|
||||
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
|
@ -43,36 +45,36 @@ public class InfraHostGenerator {
|
|||
|
||||
InfraHost infraHost = (InfraHost) infra;
|
||||
|
||||
Config config = new Config();
|
||||
config.setId(String.valueOf(dbSensor.getId()));
|
||||
SensorConfig sensorConfig = new SensorConfig();
|
||||
sensorConfig.setConfigID(String.valueOf(dbSensor.getId()));
|
||||
|
||||
com.loafle.overflow.crawler.config.Target target = this.createTarget(infraHost, dbSensor);
|
||||
Target target = this.createTarget(infraHost, dbSensor);
|
||||
|
||||
if (target == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
config.setTarget(target);
|
||||
sensorConfig.setTarget(target);
|
||||
|
||||
// FIXME: Interval
|
||||
Schedule schedule = new Schedule();
|
||||
schedule.setInterval("5");
|
||||
config.setSchedule(schedule);
|
||||
sensorConfig.setSchedule(schedule);
|
||||
|
||||
Crawler crawler = this.generateUtil.getCrawler(dbSensor.getCrawler());
|
||||
config.setCrawler(crawler);
|
||||
sensorConfig.setCrawler(crawler);
|
||||
|
||||
Map<Integer, MetaSensorItemKey> keyMap = this.generateUtil.initMappingMap(dbSensor.getCrawler());
|
||||
|
||||
if (dbSensor.getCrawler().getId() == MetaCrawlerEnum.WMI_CRAWLER.getValue()) {
|
||||
this.infraHostWMIGenerator.process(sensorItems, keyMap, dbSensor, config);
|
||||
this.infraHostWMIGenerator.process(sensorItems, keyMap, dbSensor, sensorConfig);
|
||||
}
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
return objectMapper.writeValueAsString(config);
|
||||
return objectMapper.writeValueAsString(sensorConfig);
|
||||
}
|
||||
|
||||
private com.loafle.overflow.crawler.config.Target createTarget(InfraHost infraHost, Sensor dbSensor)
|
||||
private Target createTarget(InfraHost infraHost, Sensor dbSensor)
|
||||
throws Exception {
|
||||
|
||||
AuthCrawler authCrawler = this.authCrawlerService.readAuth(dbSensor.getCrawler(), dbSensor.getTarget());
|
||||
|
@ -81,7 +83,7 @@ public class InfraHostGenerator {
|
|||
return null;
|
||||
}
|
||||
|
||||
com.loafle.overflow.crawler.config.Target target = new com.loafle.overflow.crawler.config.Target();
|
||||
Target target = new Target();
|
||||
Connection connection = new Connection();
|
||||
connection.setIp(StringConvertor.intToIp(infraHost.getIp()));
|
||||
|
||||
|
@ -91,8 +93,8 @@ public class InfraHostGenerator {
|
|||
});
|
||||
|
||||
if (dbSensor.getCrawler().getId() == MetaCrawlerEnum.WMI_CRAWLER.getValue()) {
|
||||
connection.setPort("135");
|
||||
connection.setPortType("tcp");
|
||||
connection.setPort(135);
|
||||
connection.setPortType(PortType.TCP);
|
||||
connection.setSsl(false);
|
||||
|
||||
target.setConnection(connection);
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
package com.loafle.overflow.central.module.generator.service;
|
||||
|
||||
import com.loafle.overflow.crawler.config.*;
|
||||
import com.loafle.overflow.model.meta.MetaSensorItemKey;
|
||||
import com.loafle.overflow.model.sensor.Sensor;
|
||||
import com.loafle.overflow.model.sensor.SensorItem;
|
||||
import com.loafle.overflow.model.sensorconfig.Item;
|
||||
import com.loafle.overflow.model.sensorconfig.Keys;
|
||||
import com.loafle.overflow.model.sensorconfig.MappingInfo;
|
||||
import com.loafle.overflow.model.sensorconfig.QueryInfo;
|
||||
import com.loafle.overflow.model.sensorconfig.SensorConfig;
|
||||
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
import org.codehaus.jackson.type.TypeReference;
|
||||
|
@ -25,7 +29,8 @@ public class InfraHostWMIGenerator {
|
|||
@Autowired
|
||||
private GenerateUtil generateUtil;
|
||||
|
||||
public void process(List<SensorItem> sensorItems, Map<Integer, MetaSensorItemKey> keyMap, Sensor dbSensor, Config config) throws Exception {
|
||||
public void process(List<SensorItem> sensorItems, Map<Integer, MetaSensorItemKey> keyMap, Sensor dbSensor,
|
||||
SensorConfig sensorConfig) throws Exception {
|
||||
|
||||
Map<String, List<MetaSensorItemKey>> metricMap = null;
|
||||
metricMap = this.generateUtil.sortItems(sensorItems, keyMap);
|
||||
|
@ -51,7 +56,6 @@ public class InfraHostWMIGenerator {
|
|||
extendMap.put("nameSpace", "root/cimv2");
|
||||
extendMap.put("wmicPath", "/home/snoop/temp/wmic");
|
||||
|
||||
|
||||
List<Keys> keysList = null;
|
||||
MetaSensorItemKey tempItemKey = null;
|
||||
Keys keys = null;
|
||||
|
@ -76,13 +80,13 @@ public class InfraHostWMIGenerator {
|
|||
keysList.add(this.generateUtil.createKeys(tempItemKey));
|
||||
}
|
||||
|
||||
|
||||
List<String> arrayColumns = null;
|
||||
|
||||
String json = tempItemKey.getOption();
|
||||
if (json != null && json.length() > 0) {
|
||||
HashMap<String, Object> optionMap;
|
||||
optionMap = new ObjectMapper().readValue(json, new TypeReference<HashMap<String,Object>>() {});
|
||||
optionMap = new ObjectMapper().readValue(json, new TypeReference<HashMap<String, Object>>() {
|
||||
});
|
||||
|
||||
Object obj = null;
|
||||
obj = optionMap.get("appends");
|
||||
|
@ -109,8 +113,7 @@ public class InfraHostWMIGenerator {
|
|||
arrayColumns = (List<String>) obj;
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
stringBuffer.append(" FROM ");
|
||||
stringBuffer.append(elems.getKey());
|
||||
}
|
||||
|
@ -131,7 +134,7 @@ public class InfraHostWMIGenerator {
|
|||
|
||||
}
|
||||
|
||||
config.setItems(itemList);
|
||||
sensorConfig.setItems(itemList);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.loafle.overflow.central.module.generator.service;
|
||||
|
||||
import com.loafle.overflow.central.commons.utils.StringConvertor;
|
||||
import com.loafle.overflow.crawler.config.*;
|
||||
import com.loafle.overflow.core.type.PortType;
|
||||
import com.loafle.overflow.model.auth.AuthCrawler;
|
||||
import com.loafle.overflow.model.infra.Infra;
|
||||
import com.loafle.overflow.model.infra.InfraService;
|
||||
|
@ -9,6 +9,11 @@ import com.loafle.overflow.model.meta.MetaSensorItemKey;
|
|||
import com.loafle.overflow.model.meta.type.MetaCrawlerEnum;
|
||||
import com.loafle.overflow.model.sensor.Sensor;
|
||||
import com.loafle.overflow.model.sensor.SensorItem;
|
||||
import com.loafle.overflow.model.sensorconfig.Connection;
|
||||
import com.loafle.overflow.model.sensorconfig.Crawler;
|
||||
import com.loafle.overflow.model.sensorconfig.Schedule;
|
||||
import com.loafle.overflow.model.sensorconfig.SensorConfig;
|
||||
import com.loafle.overflow.model.sensorconfig.Target;
|
||||
import com.loafle.overflow.service.central.auth.AuthCrawlerService;
|
||||
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
|
@ -42,8 +47,8 @@ public class InfraServiceGenerator {
|
|||
public String process(Sensor dbSensor, List<SensorItem> sensorItems, Infra infra) throws Exception {
|
||||
com.loafle.overflow.model.infra.InfraService infraService = (com.loafle.overflow.model.infra.InfraService)infra;
|
||||
|
||||
Config config = new Config();
|
||||
config.setId(String.valueOf(dbSensor.getId()));
|
||||
SensorConfig sensorConfig = new SensorConfig();
|
||||
sensorConfig.setConfigID(String.valueOf(dbSensor.getId()));
|
||||
|
||||
Target target = this.createTarget(infraService, dbSensor);
|
||||
|
||||
|
@ -52,26 +57,26 @@ public class InfraServiceGenerator {
|
|||
}
|
||||
|
||||
|
||||
config.setTarget(target);
|
||||
sensorConfig.setTarget(target);
|
||||
|
||||
// FIXME: Interval
|
||||
Schedule schedule = new Schedule();
|
||||
schedule.setInterval("5");
|
||||
config.setSchedule(schedule);
|
||||
sensorConfig.setSchedule(schedule);
|
||||
|
||||
Crawler crawler = this.generateUtil.getCrawler(dbSensor.getCrawler());
|
||||
config.setCrawler(crawler);
|
||||
sensorConfig.setCrawler(crawler);
|
||||
|
||||
Map<Integer, MetaSensorItemKey> keyMap = this.generateUtil.initMappingMap(dbSensor.getCrawler());
|
||||
|
||||
if(dbSensor.getCrawler().getId() == MetaCrawlerEnum.MYSQL_CRAWLER.getValue()) {
|
||||
this.infraServiceMysqlGenerator.process(sensorItems, keyMap, dbSensor, config);
|
||||
this.infraServiceMysqlGenerator.process(sensorItems, keyMap, dbSensor, sensorConfig);
|
||||
} else if (dbSensor.getCrawler().getId() == MetaCrawlerEnum.JMX_CRAWLER.getValue()) {
|
||||
this.infraServiceJMXGenerator.process(sensorItems, keyMap, dbSensor, config);
|
||||
this.infraServiceJMXGenerator.process(sensorItems, keyMap, dbSensor, sensorConfig);
|
||||
}
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
return objectMapper.writeValueAsString(config);
|
||||
return objectMapper.writeValueAsString(sensorConfig);
|
||||
}
|
||||
|
||||
private Target createTarget(InfraService infraService, Sensor sensor) throws Exception {
|
||||
|
@ -82,11 +87,11 @@ public class InfraServiceGenerator {
|
|||
return null;
|
||||
}
|
||||
|
||||
Target target = new com.loafle.overflow.crawler.config.Target();
|
||||
Target target = new Target();
|
||||
Connection connection = new Connection();
|
||||
connection.setIp(StringConvertor.intToIp(infraService.getHost().getIp()));
|
||||
connection.setPort(String.valueOf(infraService.getPort()));
|
||||
connection.setPortType(infraService.getPortType());
|
||||
connection.setPort(infraService.getPort());
|
||||
connection.setPortType(PortType.valueOf(infraService.getPortType()));
|
||||
connection.setSsl(infraService.isTlsType());
|
||||
|
||||
target.setConnection(connection);
|
||||
|
@ -103,7 +108,7 @@ public class InfraServiceGenerator {
|
|||
} else if (sensor.getCrawler().getId() == MetaCrawlerEnum.JMX_CRAWLER.getValue()) {
|
||||
auth.put("id", optionMap.get("ID")); // FIXME: Auth Info
|
||||
auth.put("pw", optionMap.get("PassWord")); // FIXME: Auth Info
|
||||
connection.setPort("9840");
|
||||
connection.setPort(9840);
|
||||
}
|
||||
|
||||
target.setAuth(auth);
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
package com.loafle.overflow.central.module.generator.service;
|
||||
|
||||
import com.loafle.overflow.crawler.config.*;
|
||||
import com.loafle.overflow.model.meta.MetaSensorItemKey;
|
||||
import com.loafle.overflow.model.sensor.Sensor;
|
||||
import com.loafle.overflow.model.sensor.SensorItem;
|
||||
import com.loafle.overflow.model.sensorconfig.Item;
|
||||
import com.loafle.overflow.model.sensorconfig.Keys;
|
||||
import com.loafle.overflow.model.sensorconfig.MappingInfo;
|
||||
import com.loafle.overflow.model.sensorconfig.QueryInfo;
|
||||
import com.loafle.overflow.model.sensorconfig.SensorConfig;
|
||||
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
import org.codehaus.jackson.type.TypeReference;
|
||||
|
@ -24,7 +28,8 @@ public class InfraServiceJMXGenerator {
|
|||
@Autowired
|
||||
private GenerateUtil generateUtil;
|
||||
|
||||
public void process(List<SensorItem> sensorItems, Map<Integer, MetaSensorItemKey> keyMap, Sensor dbSensor, Config config) throws Exception {
|
||||
public void process(List<SensorItem> sensorItems, Map<Integer, MetaSensorItemKey> keyMap, Sensor dbSensor,
|
||||
SensorConfig sensorConfig) throws Exception {
|
||||
Map<String, List<MetaSensorItemKey>> metricMap = null;
|
||||
metricMap = this.generateUtil.sortItems(sensorItems, keyMap);
|
||||
|
||||
|
@ -66,7 +71,8 @@ public class InfraServiceJMXGenerator {
|
|||
|
||||
if (json != null && json.length() > 0) {
|
||||
HashMap<String, Object> optionMap;
|
||||
optionMap = new ObjectMapper().readValue(json, new TypeReference<HashMap<String,Object>>() {});
|
||||
optionMap = new ObjectMapper().readValue(json, new TypeReference<HashMap<String, Object>>() {
|
||||
});
|
||||
|
||||
Object obj = null;
|
||||
obj = optionMap.get("aliases");
|
||||
|
@ -94,8 +100,7 @@ public class InfraServiceJMXGenerator {
|
|||
item.setKeys(keysList);
|
||||
itemList.add(item);
|
||||
}
|
||||
config.setItems(itemList);
|
||||
sensorConfig.setItems(itemList);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
package com.loafle.overflow.central.module.generator.service;
|
||||
|
||||
import com.loafle.overflow.core.exception.OverflowException;
|
||||
import com.loafle.overflow.crawler.config.*;
|
||||
import com.loafle.overflow.model.meta.MetaSensorItemKey;
|
||||
import com.loafle.overflow.model.sensor.Sensor;
|
||||
import com.loafle.overflow.model.sensor.SensorItem;
|
||||
import com.loafle.overflow.model.sensorconfig.Item;
|
||||
import com.loafle.overflow.model.sensorconfig.Keys;
|
||||
import com.loafle.overflow.model.sensorconfig.MappingInfo;
|
||||
import com.loafle.overflow.model.sensorconfig.QueryInfo;
|
||||
import com.loafle.overflow.model.sensorconfig.SensorConfig;
|
||||
|
||||
import org.codehaus.jackson.JsonParseException;
|
||||
import org.codehaus.jackson.map.JsonMappingException;
|
||||
|
@ -28,8 +32,8 @@ public class InfraServiceMysqlGenerator {
|
|||
@Autowired
|
||||
private GenerateUtil generateUtil;
|
||||
|
||||
public void process(List<SensorItem> sensorItems, Map<Integer, MetaSensorItemKey> keyMap, Sensor dbSensor, Config config) throws Exception {
|
||||
|
||||
public void process(List<SensorItem> sensorItems, Map<Integer, MetaSensorItemKey> keyMap, Sensor dbSensor,
|
||||
SensorConfig sensorConfig) throws Exception {
|
||||
|
||||
// List<Keys> keysList = new ArrayList<>();
|
||||
// for(SensorItem sItem : sensorItems) {
|
||||
|
@ -74,15 +78,14 @@ public class InfraServiceMysqlGenerator {
|
|||
keysList.add(this.generateUtil.createKeys(tempItemKey));
|
||||
}
|
||||
|
||||
|
||||
|
||||
List<String> keyColumns = null;
|
||||
String valueColumn = null;
|
||||
|
||||
String json = tempItemKey.getOption();
|
||||
if (json != null && json.length() > 0) {
|
||||
HashMap<String, Object> optionMap;
|
||||
optionMap = new ObjectMapper().readValue(json, new TypeReference<HashMap<String,Object>>() {});
|
||||
optionMap = new ObjectMapper().readValue(json, new TypeReference<HashMap<String, Object>>() {
|
||||
});
|
||||
|
||||
Object obj = null;
|
||||
obj = optionMap.get("valueColumn");
|
||||
|
@ -112,8 +115,7 @@ public class InfraServiceMysqlGenerator {
|
|||
|
||||
}
|
||||
|
||||
config.setItems(itemList);
|
||||
|
||||
sensorConfig.setItems(itemList);
|
||||
|
||||
// ObjectMapper objectMapper = new ObjectMapper();
|
||||
//
|
||||
|
|
Loading…
Reference in New Issue
Block a user