diff --git a/pom.xml b/pom.xml index 741359d..4f4c4b4 100644 --- a/pom.xml +++ b/pom.xml @@ -37,7 +37,6 @@ ${spring-data-commons-core.version} - org.hibernate diff --git a/src/main/java/com/loafle/overflow/module/discovery/model/DiscoverHost.java b/src/main/java/com/loafle/overflow/module/discovery/model/DiscoverHost.java index b7edc32..8e3713e 100644 --- a/src/main/java/com/loafle/overflow/module/discovery/model/DiscoverHost.java +++ b/src/main/java/com/loafle/overflow/module/discovery/model/DiscoverHost.java @@ -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; } diff --git a/src/main/java/com/loafle/overflow/module/discovery/model/DiscoverPort.java b/src/main/java/com/loafle/overflow/module/discovery/model/DiscoverPort.java index a7776d3..536487c 100644 --- a/src/main/java/com/loafle/overflow/module/discovery/model/DiscoverPort.java +++ b/src/main/java/com/loafle/overflow/module/discovery/model/DiscoverPort.java @@ -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; } \ No newline at end of file diff --git a/src/main/java/com/loafle/overflow/module/discovery/model/DiscoverService.java b/src/main/java/com/loafle/overflow/module/discovery/model/DiscoverService.java index 28565a7..3f78e85 100644 --- a/src/main/java/com/loafle/overflow/module/discovery/model/DiscoverService.java +++ b/src/main/java/com/loafle/overflow/module/discovery/model/DiscoverService.java @@ -4,5 +4,5 @@ package com.loafle.overflow.module.discovery.model; * DiscoveryService */ public class DiscoverService { - public String[] includeServices; + private String[] includeServices; } \ No newline at end of file diff --git a/src/main/java/com/loafle/overflow/module/discovery/model/DiscoverZone.java b/src/main/java/com/loafle/overflow/module/discovery/model/DiscoverZone.java index f3b47f0..e370fcd 100644 --- a/src/main/java/com/loafle/overflow/module/discovery/model/DiscoverZone.java +++ b/src/main/java/com/loafle/overflow/module/discovery/model/DiscoverZone.java @@ -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; } \ No newline at end of file diff --git a/src/main/java/com/loafle/overflow/module/discovery/model/Host.java b/src/main/java/com/loafle/overflow/module/discovery/model/Host.java index cee1290..f58152b 100644 --- a/src/main/java/com/loafle/overflow/module/discovery/model/Host.java +++ b/src/main/java/com/loafle/overflow/module/discovery/model/Host.java @@ -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; } diff --git a/src/main/java/com/loafle/overflow/module/discovery/model/Port.java b/src/main/java/com/loafle/overflow/module/discovery/model/Port.java index db714f8..3ee3e9b 100644 --- a/src/main/java/com/loafle/overflow/module/discovery/model/Port.java +++ b/src/main/java/com/loafle/overflow/module/discovery/model/Port.java @@ -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; } diff --git a/src/main/java/com/loafle/overflow/module/discovery/model/Service.java b/src/main/java/com/loafle/overflow/module/discovery/model/Service.java index 6bb87ae..46bb3cc 100644 --- a/src/main/java/com/loafle/overflow/module/discovery/model/Service.java +++ b/src/main/java/com/loafle/overflow/module/discovery/model/Service.java @@ -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; } diff --git a/src/main/java/com/loafle/overflow/module/discovery/model/Zone.java b/src/main/java/com/loafle/overflow/module/discovery/model/Zone.java index 9448b62..7aa0666 100644 --- a/src/main/java/com/loafle/overflow/module/discovery/model/Zone.java +++ b/src/main/java/com/loafle/overflow/module/discovery/model/Zone.java @@ -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; } \ No newline at end of file diff --git a/src/main/java/com/loafle/overflow/module/sensorconfig/model/Connection.java b/src/main/java/com/loafle/overflow/module/sensorconfig/model/Connection.java new file mode 100644 index 0000000..ccc8ecd --- /dev/null +++ b/src/main/java/com/loafle/overflow/module/sensorconfig/model/Connection.java @@ -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; +} \ No newline at end of file diff --git a/src/main/java/com/loafle/overflow/module/sensorconfig/model/Crawler.java b/src/main/java/com/loafle/overflow/module/sensorconfig/model/Crawler.java new file mode 100644 index 0000000..6dfabe4 --- /dev/null +++ b/src/main/java/com/loafle/overflow/module/sensorconfig/model/Crawler.java @@ -0,0 +1,9 @@ +package com.loafle.overflow.module.sensorconfig.model; + +/** + * Crawler + */ +public class Crawler { + private String name; + private String container; +} diff --git a/src/main/java/com/loafle/overflow/module/sensorconfig/model/Item.java b/src/main/java/com/loafle/overflow/module/sensorconfig/model/Item.java new file mode 100644 index 0000000..99669c2 --- /dev/null +++ b/src/main/java/com/loafle/overflow/module/sensorconfig/model/Item.java @@ -0,0 +1,9 @@ +package com.loafle.overflow.module.sensorconfig.model; + +/** + * Item + */ +public class Item { + + +} \ No newline at end of file diff --git a/src/main/java/com/loafle/overflow/module/sensorconfig/model/Keys.java b/src/main/java/com/loafle/overflow/module/sensorconfig/model/Keys.java new file mode 100644 index 0000000..38a9164 --- /dev/null +++ b/src/main/java/com/loafle/overflow/module/sensorconfig/model/Keys.java @@ -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 keysToMap(Keys[] keys) { + Map map = new HashMap<>(); + for (Keys k : keys) { + map.put(k.key, k.metric); + } + return map; + } +} \ No newline at end of file diff --git a/src/main/java/com/loafle/overflow/module/sensorconfig/model/MappingInfo.java b/src/main/java/com/loafle/overflow/module/sensorconfig/model/MappingInfo.java new file mode 100644 index 0000000..78908c3 --- /dev/null +++ b/src/main/java/com/loafle/overflow/module/sensorconfig/model/MappingInfo.java @@ -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; +} \ No newline at end of file diff --git a/src/main/java/com/loafle/overflow/module/sensorconfig/model/QueryInfo.java b/src/main/java/com/loafle/overflow/module/sensorconfig/model/QueryInfo.java new file mode 100644 index 0000000..89691eb --- /dev/null +++ b/src/main/java/com/loafle/overflow/module/sensorconfig/model/QueryInfo.java @@ -0,0 +1,11 @@ +package com.loafle.overflow.module.sensorconfig.model; + +import java.util.Map; + +/** + * QueryInfo + */ +public class QueryInfo { + private String query; + private Map extend; +} \ No newline at end of file diff --git a/src/main/java/com/loafle/overflow/module/sensorconfig/model/ResultSet.java b/src/main/java/com/loafle/overflow/module/sensorconfig/model/ResultSet.java new file mode 100644 index 0000000..0913ac0 --- /dev/null +++ b/src/main/java/com/loafle/overflow/module/sensorconfig/model/ResultSet.java @@ -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> rows; + private Map 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 row) { + rows.add(row); + } + + public List> getRows() { + return rows; + } + + public void setRows(List> rows) { + this.rows = rows; + } + + public Map getMeta() { + return meta; + } + + public void setMeta(Map meta) { + this.meta = meta; + } + + public Item getItem() { + return item; + } + + public void setItem(Item item) { + this.item = item; + } + + public Map getData() { + return parse(); + } + + // abstracts + public abstract void setMeta(); + + public abstract Map parse(); + +} \ No newline at end of file diff --git a/src/main/java/com/loafle/overflow/module/sensorconfig/model/ResultSetCol.java b/src/main/java/com/loafle/overflow/module/sensorconfig/model/ResultSetCol.java new file mode 100644 index 0000000..bace6ad --- /dev/null +++ b/src/main/java/com/loafle/overflow/module/sensorconfig/model/ResultSetCol.java @@ -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 meta = this.item.getKeys(); + List 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 parse() { + + List metrics = this.item.getKeys(); + List arrayColumns = this.item.getMappingInfo().getArrayColumns(); + + Map resultMap = new HashMap<>(); + + List row = null; + + String metric = null; + List 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 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; + } +} diff --git a/src/main/java/com/loafle/overflow/module/sensorconfig/model/ResultSetRow.java b/src/main/java/com/loafle/overflow/module/sensorconfig/model/ResultSetRow.java new file mode 100644 index 0000000..92ee92b --- /dev/null +++ b/src/main/java/com/loafle/overflow/module/sensorconfig/model/ResultSetRow.java @@ -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 meta = new ArrayList<>(); + + List arrayColumns = (List) this.item.getMappingInfo().getArrayColumns(); + List keyColumns = (List) 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 parse() { + + Map returnMap = new HashMap<>(); + + String valueColumn = (String) this.item.getMappingInfo().getValueColumn(); + + for (List 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 data) { + + List metrics = this.item.getKeys(); + + List arrayColumns = (List) this.item.getMappingInfo().getArrayColumns(); + List keyColumns = (List) this.item.getMappingInfo().getKeyColumns(); + List 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; + } + +} diff --git a/src/main/java/com/loafle/overflow/module/sensorconfig/model/Schedule.java b/src/main/java/com/loafle/overflow/module/sensorconfig/model/Schedule.java new file mode 100644 index 0000000..bde872a --- /dev/null +++ b/src/main/java/com/loafle/overflow/module/sensorconfig/model/Schedule.java @@ -0,0 +1,8 @@ +package com.loafle.overflow.module.sensorconfig.model; + +/** + * Schedule + */ +public class Schedule { + private String interval; +} \ No newline at end of file diff --git a/src/main/java/com/loafle/overflow/module/sensorconfig/model/SensorConfig.java b/src/main/java/com/loafle/overflow/module/sensorconfig/model/SensorConfig.java new file mode 100644 index 0000000..ec7a478 --- /dev/null +++ b/src/main/java/com/loafle/overflow/module/sensorconfig/model/SensorConfig.java @@ -0,0 +1,9 @@ +package com.loafle.overflow.module.sensorconfig.model; + +/** + * SensorConfig + */ +public class SensorConfig { + + +} \ No newline at end of file diff --git a/src/main/java/com/loafle/overflow/module/sensorconfig/model/Target.java b/src/main/java/com/loafle/overflow/module/sensorconfig/model/Target.java new file mode 100644 index 0000000..1859012 --- /dev/null +++ b/src/main/java/com/loafle/overflow/module/sensorconfig/model/Target.java @@ -0,0 +1,11 @@ +package com.loafle.overflow.module.sensorconfig.model; + +import java.util.Map; + +/** + * Target + */ +public class Target { + private Map auth; + private Connection connection; +} \ No newline at end of file