This commit is contained in:
crusader 2018-04-23 17:28:02 +09:00
parent d7158caecb
commit 1544cd91c1
21 changed files with 417 additions and 37 deletions

View File

@ -37,7 +37,6 @@
<version>${spring-data-commons-core.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-entitymanager -->
<dependency>
<groupId>org.hibernate</groupId>

View File

@ -4,10 +4,10 @@ package com.loafle.overflow.module.discovery.model;
* DiscoveryHost
*/
public class DiscoverHost {
public String firstScanRange;
public String lastScanRange;
public String[] excludeHosts;
public String[] includeHosts;
private String firstScanRange;
private String lastScanRange;
private String[] excludeHosts;
private String[] includeHosts;
public DiscoverPort discoverPort;
private DiscoverPort discoverPort;
}

View File

@ -4,12 +4,12 @@ package com.loafle.overflow.module.discovery.model;
* DiscoveryPort
*/
public class DiscoverPort {
public int firstScanRange;
public int lastScanRange;
public int[] excludePorts;
private int firstScanRange;
private int lastScanRange;
private int[] excludePorts;
public boolean includeTCP;
public boolean includeUDP;
private boolean includeTCP;
private boolean includeUDP;
public DiscoverService discoverService;
private DiscoverService discoverService;
}

View File

@ -4,5 +4,5 @@ package com.loafle.overflow.module.discovery.model;
* DiscoveryService
*/
public class DiscoverService {
public String[] includeServices;
private String[] includeServices;
}

View File

@ -4,6 +4,6 @@ package com.loafle.overflow.module.discovery.model;
* DiscoveryZone
*/
public class DiscoverZone {
public String[] excludePatterns;
public DiscoverHost discoverHost;
private String[] excludePatterns;
private DiscoverHost discoverHost;
}

View File

@ -8,13 +8,13 @@ import java.util.Date;
*/
public class Host {
public long id;
public String ip;
public String mac;
public String os;
private long id;
private String ip;
private String mac;
private String os;
public Date discoveredDate;
private Date discoveredDate;
public Zone zone;
private Zone zone;
}

View File

@ -9,11 +9,11 @@ import java.util.Date;
*/
public class Port {
public long id;
public PortType portType;
public int portNumber;
private long id;
private PortType portType;
private int portNumber;
public Date discoveredDate;
private Date discoveredDate;
public Host host;
private Host host;
}

View File

@ -10,11 +10,11 @@ import com.loafle.overflow.module.core.type.CryptoType;
*/
public class Service {
public long id;
public CryptoType cryptoType;
public String serviceName;
private long id;
private CryptoType cryptoType;
private String serviceName;
public Date discoveredDate;
private Date discoveredDate;
public Port port;
private Port port;
}

View File

@ -6,11 +6,11 @@ import java.util.Date;
* Created by snoop on 17. 10. 31.
*/
public class Zone {
public long id;
public String network;
public String ip;
public String iface;
public String mac;
private long id;
private String network;
private String ip;
private String iface;
private String mac;
public Date discoveredDate;
private Date discoveredDate;
}

View File

@ -0,0 +1,13 @@
package com.loafle.overflow.module.sensorconfig.model;
import com.loafle.overflow.module.core.type.PortType;
/**
* Connection
*/
public class Connection {
private String ip;
private int port;
private PortType portType;
private boolean ssl;
}

View File

@ -0,0 +1,9 @@
package com.loafle.overflow.module.sensorconfig.model;
/**
* Crawler
*/
public class Crawler {
private String name;
private String container;
}

View File

@ -0,0 +1,9 @@
package com.loafle.overflow.module.sensorconfig.model;
/**
* Item
*/
public class Item {
}

View File

@ -0,0 +1,20 @@
package com.loafle.overflow.module.sensorconfig.model;
import java.util.HashMap;
import java.util.Map;
/**
* Keys
*/
public class Keys {
private String metric;
private String key;
public static Map<String, String> keysToMap(Keys[] keys) {
Map<String, String> map = new HashMap<>();
for (Keys k : keys) {
map.put(k.key, k.metric);
}
return map;
}
}

View File

@ -0,0 +1,11 @@
package com.loafle.overflow.module.sensorconfig.model;
/**
* MappingInfo
*/
public class MappingInfo {
private String parseDirection;
private String[] arrayColumns;
private String[] keyColumns;
private String valueColumn;
}

View File

@ -0,0 +1,11 @@
package com.loafle.overflow.module.sensorconfig.model;
import java.util.Map;
/**
* QueryInfo
*/
public class QueryInfo {
private String query;
private Map<String, Object> extend;
}

View File

@ -0,0 +1,71 @@
package com.loafle.overflow.module.sensorconfig.model;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* ResultSet
*/
public abstract class ResultSet {
private Item item;
private List<List<String>> rows;
private Map<String, Integer> meta;
// methods
public static ResultSet newInstance(Item item) {
if (item.getMappingInfo() == null) {
item.setMappingInfo(new MappingInfo());
}
String type = (String) item.getMappingInfo().getParseDirection();
if (type != null && type.equals("row")) {
return new ResultSetRow(item);
} else {
return new ResultSetCol(item);
}
}
public ResultSet(Item item) {
this.item = item;
this.rows = new ArrayList<>();
this.setMeta();
}
public void addRow(List<String> row) {
rows.add(row);
}
public List<List<String>> getRows() {
return rows;
}
public void setRows(List<List<String>> rows) {
this.rows = rows;
}
public Map<String, Integer> getMeta() {
return meta;
}
public void setMeta(Map<String, Integer> meta) {
this.meta = meta;
}
public Item getItem() {
return item;
}
public void setItem(Item item) {
this.item = item;
}
public Map<String, String> getData() {
return parse();
}
// abstracts
public abstract void setMeta();
public abstract Map<String, String> parse();
}

View File

@ -0,0 +1,102 @@
package com.loafle.overflow.module.sensorconfig.model;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* ResultSetCol
*/
public class ResultSetCol extends ResultSet {
public ResultSetCol(Item item) {
super(item);
}
public void setMeta() {
List<Keys> meta = this.item.getKeys();
List<String> arrayColumns = this.item.getMappingInfo().getArrayColumns();
if (this.meta == null) {
this.meta = new HashMap<>();
}
for (int indexI = 0; indexI < meta.size(); ++indexI) {
this.meta.put(meta.get(indexI).getKey(), indexI);
}
if (arrayColumns != null) {
for (int indexI = 0; indexI < arrayColumns.size(); ++indexI) {
if (this.meta.containsKey(arrayColumns.get(indexI))) {
continue;
}
this.meta.put(arrayColumns.get(indexI), indexI + meta.size());
}
}
}
public Map<String, String> parse() {
List<Keys> metrics = this.item.getKeys();
List<String> arrayColumns = this.item.getMappingInfo().getArrayColumns();
Map<String, String> resultMap = new HashMap<>();
List<String> row = null;
String metric = null;
List<String> arrayValue = new ArrayList<>();
int columnIdx = 0;
for (int indexI = 0; indexI < this.rows.size(); ++indexI) {
row = this.rows.get(indexI);
for (int indexJ = 0; indexJ < row.size(); ++indexJ) {
arrayValue.clear();
if (arrayColumns != null) {
for (int indexL = 0; indexL < arrayColumns.size(); ++indexL) {
columnIdx = this.meta.get(arrayColumns.get(indexL));
arrayValue.add(row.get(columnIdx));
}
}
for (int indexK = 0; indexK < metrics.size(); ++indexK) {
metric = metrics.get(indexK).getMetric();
metric = convertMetric(metric, arrayValue);
resultMap.put(metric, row.get(indexK));
}
}
}
return resultMap;
}
private String convertMetric(String metric, List<String> arrayValue) {
if (arrayValue == null || arrayValue.size() <= 0) {
return metric;
}
String convertChar = "$";
String convertStr = null;
for (int indexI = 0; indexI < arrayValue.size(); ++indexI) {
convertStr = convertChar + String.valueOf(indexI);
metric = metric.replace(convertStr, arrayValue.get(indexI));
}
return metric;
}
}

View File

@ -0,0 +1,107 @@
package com.loafle.overflow.module.sensorconfig.model;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* ResultSetRow
*/
public class ResultSetRow extends ResultSet {
public ResultSetRow(Item item) {
super(item);
}
public void setMeta() {
List<String> meta = new ArrayList<>();
List<String> arrayColumns = (List<String>) this.item.getMappingInfo().getArrayColumns();
List<String> keyColumns = (List<String>) this.item.getMappingInfo().getKeyColumns();
String valueColumn = (String) this.item.getMappingInfo().getValueColumn();
if (arrayColumns != null) {
for (String c : arrayColumns) {
meta.add(c);
}
}
if (keyColumns != null) {
for (String c : keyColumns) {
meta.add(c);
}
}
if (valueColumn != null && !valueColumn.equals(""))
meta.add(valueColumn);
if (this.meta == null) {
this.meta = new HashMap<>();
}
for (int indexI = 0; indexI < meta.size(); ++indexI) {
this.meta.put(meta.get(indexI), indexI);
}
}
public Map<String, String> parse() {
Map<String, String> returnMap = new HashMap<>();
String valueColumn = (String) this.item.getMappingInfo().getValueColumn();
for (List<String> row : this.rows) {
String key = makeKey(row);
if (key == null)
continue;
returnMap.put(key, row.get(this.meta.get(valueColumn)));
}
return returnMap;
}
private String makeKey(List<String> data) {
List<Keys> metrics = this.item.getKeys();
List<String> arrayColumns = (List<String>) this.item.getMappingInfo().getArrayColumns();
List<String> keyColumns = (List<String>) this.item.getMappingInfo().getKeyColumns();
List<Keys> keys = this.item.getKeys();
boolean find = false;
int findIndex = -1;
for (String keyColumn : keyColumns) {
String row = data.get(this.meta.get(keyColumn));
for (int i = 0; i < keys.size(); ++i) {
if (row.equals(keys.get(i).getKey())) {
findIndex = i;
find = true;
break;
}
}
if (find == true) {
break;
}
}
if (findIndex < 0) {
return null;
}
String metric = metrics.get(findIndex).getMetric();
if (arrayColumns != null) {
for (int i = 0; i < arrayColumns.size(); ++i) {
// replace
String k = "$" + i;
int dataIndex = this.meta.get(arrayColumns.get(i));
String replaceString = data.get(dataIndex);
metric = metric.replace(k, "'" + replaceString + "'");
}
}
return metric;
}
}

View File

@ -0,0 +1,8 @@
package com.loafle.overflow.module.sensorconfig.model;
/**
* Schedule
*/
public class Schedule {
private String interval;
}

View File

@ -0,0 +1,9 @@
package com.loafle.overflow.module.sensorconfig.model;
/**
* SensorConfig
*/
public class SensorConfig {
}

View File

@ -0,0 +1,11 @@
package com.loafle.overflow.module.sensorconfig.model;
import java.util.Map;
/**
* Target
*/
public class Target {
private Map<String, String> auth;
private Connection connection;
}