From 67fc64a27457f619ce9cbe3e2be276c18627b911 Mon Sep 17 00:00:00 2001 From: crusader Date: Wed, 25 Apr 2018 23:06:23 +0900 Subject: [PATCH] ing --- .../general/crawler/impl/wmi/WMICrawler.java | 79 +++++++++++++++++-- .../crawler/impl/wmi/WMICrawlerOS.java | 44 +++++------ .../resources/config/wmi/meta/meta_cpu.json | 49 ++++++++++++ .../config/wmi/meta/meta_filesystem.json | 61 ++++++++++++++ .../config/wmi/meta/meta_memory.json | 53 +++++++++++++ .../config/wmi/meta/meta_network.json | 53 +++++++++++++ src/main/resources/netty.properties | 2 - 7 files changed, 310 insertions(+), 31 deletions(-) create mode 100644 src/main/resources/config/wmi/meta/meta_cpu.json create mode 100644 src/main/resources/config/wmi/meta/meta_filesystem.json create mode 100644 src/main/resources/config/wmi/meta/meta_memory.json create mode 100644 src/main/resources/config/wmi/meta/meta_network.json delete mode 100644 src/main/resources/netty.properties diff --git a/src/main/java/com/loafle/overflow/container/general/crawler/impl/wmi/WMICrawler.java b/src/main/java/com/loafle/overflow/container/general/crawler/impl/wmi/WMICrawler.java index 51db8f1..11f2f3c 100644 --- a/src/main/java/com/loafle/overflow/container/general/crawler/impl/wmi/WMICrawler.java +++ b/src/main/java/com/loafle/overflow/container/general/crawler/impl/wmi/WMICrawler.java @@ -1,12 +1,28 @@ package com.loafle.overflow.container.general.crawler.impl.wmi; +import com.google.gson.Gson; import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.crawler.Crawler; +import com.loafle.overflow.model.sensorconfig.ResultSet; import com.loafle.overflow.model.sensorconfig.SensorConfig; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; import java.util.Map; public class WMICrawler implements Crawler { + private Gson gson; + + public WMICrawler() { + this.gson = new Gson(); + } + @Override public String name() { return "WMI"; @@ -23,11 +39,62 @@ public class WMICrawler implements Crawler { } @Override - public Map get(SensorConfig sensorConfig) throws OverflowException { - try { - return WMICrawlerOS.getInstance().process(sensorConfig); - } catch (Exception e) { - throw new OverflowException("WMICrawler", e); + public Map get(SensorConfig sensorConfig) throws OverflowException { + try { + return WMICrawlerOS.getInstance().process(sensorConfig); + } catch (Exception e) { + throw new OverflowException("WMICrawler", e); + } + } + + public Object getMeta(SensorConfig sensorConfig) throws OverflowException { + + try { + List metaConfigList = loadMetaConfig(); + + WMICrawlerOS os = WMICrawlerOS.getInstance(); + Map returnMap = new HashMap(); + ResultSet ofResultSet = null; + for (SensorConfig metaConfig : metaConfigList) { + for (int indexI = 0; indexI < metaConfig.getItems().size(); ++indexI) { + ofResultSet = os.processWMI(sensorConfig, metaConfig.getItems().get(indexI)); + if (ofResultSet != null) { + returnMap.putAll(ofResultSet.getData()); + } } - } + } + } catch (Exception e) { + throw new OverflowException("WMICrawler", e); + } + + return null; + } + + private List loadMetaConfig() throws IOException { + ClassLoader classLoader = getClass().getClassLoader(); + + URL url = classLoader.getResource("config/wmi/meta"); + if (url == null) { + return null; + } + + String path = url.getFile(); + File pathFile = new File(path); + + System.out.println(path); + String[] metaFiles = pathFile.list(); + List retList = new ArrayList<>(); + SensorConfig metaConfig = null; + for (String fi : metaFiles) { + if (fi.indexOf("meta_") > -1) { + metaConfig = new Gson().fromJson(new InputStreamReader(new FileInputStream(new File(path + "/" + fi))), SensorConfig.class); + if (metaConfig != null) { + retList.add(metaConfig); + } + } + } + + return retList; + } + } diff --git a/src/main/java/com/loafle/overflow/container/general/crawler/impl/wmi/WMICrawlerOS.java b/src/main/java/com/loafle/overflow/container/general/crawler/impl/wmi/WMICrawlerOS.java index e80598f..76f469c 100644 --- a/src/main/java/com/loafle/overflow/container/general/crawler/impl/wmi/WMICrawlerOS.java +++ b/src/main/java/com/loafle/overflow/container/general/crawler/impl/wmi/WMICrawlerOS.java @@ -9,39 +9,37 @@ import com.loafle.overflow.model.sensorconfig.SensorConfig; public abstract class WMICrawlerOS { - private static WMICrawlerOS wmiCrawlerOS = null; + private static WMICrawlerOS wmiCrawlerOS = null; - public static WMICrawlerOS getInstance() { + public static WMICrawlerOS getInstance() { - if(WMICrawlerOS.wmiCrawlerOS == null) { + if (WMICrawlerOS.wmiCrawlerOS == null) { - String os = System.getProperty("os.name").toLowerCase(); + String os = System.getProperty("os.name").toLowerCase(); - if(os.indexOf("linux") >= 0) { - WMICrawlerOS.wmiCrawlerOS = new WMICrawlerLinux(); - } else if(os.indexOf("") >= 0) { - WMICrawlerOS.wmiCrawlerOS = new WMICrawlerWindows(); - } + if (os.indexOf("linux") >= 0) { + WMICrawlerOS.wmiCrawlerOS = new WMICrawlerLinux(); + } else if (os.indexOf("") >= 0) { + WMICrawlerOS.wmiCrawlerOS = new WMICrawlerWindows(); + } - } - - return WMICrawlerOS.wmiCrawlerOS; } - public Map process(SensorConfig sensorConfig) throws Exception { - Map returnMap = new HashMap(); + return WMICrawlerOS.wmiCrawlerOS; + } - ResultSet ofResultSet = null; - for(int cIndexI = 0 ; cIndexI < sensorConfig.getItems().size() ; ++cIndexI) { + public Map process(SensorConfig sensorConfig) throws Exception { + Map returnMap = new HashMap(); - ofResultSet = processWMI(sensorConfig, sensorConfig.getItems().get(cIndexI)); - returnMap.putAll(ofResultSet.getData()); - } + ResultSet ofResultSet = null; + for (int cIndexI = 0; cIndexI < sensorConfig.getItems().size(); ++cIndexI) { - - return returnMap; + ofResultSet = processWMI(sensorConfig, sensorConfig.getItems().get(cIndexI)); + returnMap.putAll(ofResultSet.getData()); } - public abstract ResultSet processWMI(SensorConfig sensorConfig, Item item) throws Exception ; + return returnMap; + } + + public abstract ResultSet processWMI(SensorConfig sensorConfig, Item item) throws Exception; } - diff --git a/src/main/resources/config/wmi/meta/meta_cpu.json b/src/main/resources/config/wmi/meta/meta_cpu.json new file mode 100644 index 0000000..74288c6 --- /dev/null +++ b/src/main/resources/config/wmi/meta/meta_cpu.json @@ -0,0 +1,49 @@ +{ + "id": "4", + "schedule": { + "interval": "5" + }, + "items": [{ + "keys": [{ + "metric": "cpu.caption", + "key": "Caption" + }, + { + "metric": "cpu.Manufacturer", + "key": "Manufacturer" + }, + { + "metric": "cpu.MaxClockSpeed", + "key": "MaxClockSpeed" + }, + { + "metric": "cpu.CurrentClockSpeed", + "key": "CurrentClockSpeed" + }, + { + "metric": "cpu.AddressWidth", + "key": "AddressWidth" + }, + { + "metric": "cpu.DataWidth", + "key": "DataWidth" + }, + { + "metric": "cpu.Architecture", + "key": "Architecture" + }], + "queryInfo": { + "query": "SELECT Caption, Manufacturer, MaxClockSpeed, CurrentClockSpeed, AddressWidth, DataWidth, Architecture from Win32_Processor ", + "extend": { + "nameSpace": "root/cimv2", + "wmicPath": "/home/snoop/temp/wmic" + } + }, + "mappingInfo": { + "parseDirection": "col", + "arrayColumns": null, + "keyColumns": null, + "valueColumn": null + } + }] +} diff --git a/src/main/resources/config/wmi/meta/meta_filesystem.json b/src/main/resources/config/wmi/meta/meta_filesystem.json new file mode 100644 index 0000000..11dbf76 --- /dev/null +++ b/src/main/resources/config/wmi/meta/meta_filesystem.json @@ -0,0 +1,61 @@ +{ + "id": "4", + "target": { + "auth": { + "pw": "dbseogns18", + "id": "administrator" + }, + "connection": { + "ip": "192.168.1.106", + "port": "135", + "portType": "tcp", + "ssl": false + } + }, + "schedule": { + "interval": "5" + }, + "crawler": { + "name": "WMI_CRAWLER", + "container": "java_proxy" + }, + "items": [{ + "keys": [{ + "metric": "filesystem[$0].InterfaceType", + "key": "InterfaceType" + }, + { + "metric": "filesystem[$0].Status", + "key": "Status" + }, + { + "metric": "filesystem[$0].Manufacturer", + "key": "Manufacturer" + }, + { + "metric": "filesystem[$0].Model", + "key": "Model" + }, + { + "metric": "filesystem[$0].MediaType", + "key": "MediaType" + }, + { + "metric": "filesystem[$0].Size", + "key": "Size" + }], + "queryInfo": { + "query": "SELECT InterfaceType, Status, Manufacturer, Model, MediaType, Size from Win32_DiskDrive ", + "extend": { + "nameSpace": "root/cimv2", + "wmicPath": "/home/snoop/temp/wmic" + } + }, + "mappingInfo": { + "parseDirection": "col", + "arrayColumns": ["Model"], + "keyColumns": null, + "valueColumn": null + } + }] +} diff --git a/src/main/resources/config/wmi/meta/meta_memory.json b/src/main/resources/config/wmi/meta/meta_memory.json new file mode 100644 index 0000000..a3f111a --- /dev/null +++ b/src/main/resources/config/wmi/meta/meta_memory.json @@ -0,0 +1,53 @@ +{ + "id": "4", + "target": { + "auth": { + "pw": "dbseogns18", + "id": "administrator" + }, + "connection": { + "ip": "192.168.1.106", + "port": "135", + "portType": "tcp", + "ssl": false + } + }, + "schedule": { + "interval": "5" + }, + "crawler": { + "name": "WMI_CRAWLER", + "container": "java_proxy" + }, + "items": [{ + "keys": [{ + "metric": "memory.BankLabel", + "key": "BankLabel" + }, + { + "metric": "memory.Capacity", + "key": "Capacity" + }, + { + "metric": "memory.MemoryType", + "key": "MemoryType" + }, + { + "metric": "memory.DataWidth", + "key": "DataWidth" + }], + "queryInfo": { + "query": "SELECT BankLabel, Capacity, MemoryType, DataWidth from Win32_PhysicalMemory ", + "extend": { + "nameSpace": "root/cimv2", + "wmicPath": "/home/snoop/temp/wmic" + } + }, + "mappingInfo": { + "parseDirection": "col", + "arrayColumns": null, + "keyColumns": null, + "valueColumn": null + } + }] +} diff --git a/src/main/resources/config/wmi/meta/meta_network.json b/src/main/resources/config/wmi/meta/meta_network.json new file mode 100644 index 0000000..1c08a00 --- /dev/null +++ b/src/main/resources/config/wmi/meta/meta_network.json @@ -0,0 +1,53 @@ +{ + "id": "4", + "target": { + "auth": { + "pw": "dbseogns18", + "id": "administrator" + }, + "connection": { + "ip": "192.168.1.106", + "port": "135", + "portType": "tcp", + "ssl": false + } + }, + "schedule": { + "interval": "5" + }, + "crawler": { + "name": "WMI_CRAWLER", + "container": "java_proxy" + }, + "items": [{ + "keys": [{ + "metric": "network[$0].MACAddress", + "key": "MACAddress" + }, + { + "metric": "network[$0].AdapterType", + "key": "AdapterType" + }, + { + "metric": "network[$0].Manufacturer", + "key": "Manufacturer" + }, + { + "metric": "network[$0].Description", + "key": "Description" + }], + "queryInfo": { + "query": "SELECT MACAddress, AdapterType, Manufacturer, Description, NetConnectionID from Win32_NetworkAdapter WHERE PhysicalAdapter='TRUE'", + "extend": { + "nameSpace": "root/cimv2", + "wmicPath": "/home/snoop/temp/wmic" + } + }, + "mappingInfo": { + "parseDirection": "col", + "arrayColumns": ["NetConnectionID"], + "keyColumns": null, + "valueColumn": null + } + }] +} diff --git a/src/main/resources/netty.properties b/src/main/resources/netty.properties deleted file mode 100644 index d59d276..0000000 --- a/src/main/resources/netty.properties +++ /dev/null @@ -1,2 +0,0 @@ -server.netty.thread.count.boss=1 -server.netty.thread.count.worker=10 \ No newline at end of file