From 0cbf635c90ae9ccbfb3d2dbbd8da9e23b0235110 Mon Sep 17 00:00:00 2001 From: snoop Date: Wed, 6 Sep 2017 19:31:38 +0900 Subject: [PATCH] fixed bug for default column - deviceID !!! --- .../overflow/crawler/wmi/WMICrawlerLinux.java | 11 +- .../crawler/wmi/WMICrawlerWindows.java | 2 +- .../overflow/crawler/wmi/WMICrawlerTest.java | 8 +- src/test/resources/config/test.json | 130 ++++++++++++++++++ 4 files changed, 145 insertions(+), 6 deletions(-) create mode 100644 src/test/resources/config/test.json diff --git a/src/main/java/com/loafle/overflow/crawler/wmi/WMICrawlerLinux.java b/src/main/java/com/loafle/overflow/crawler/wmi/WMICrawlerLinux.java index 2342057..80366b8 100644 --- a/src/main/java/com/loafle/overflow/crawler/wmi/WMICrawlerLinux.java +++ b/src/main/java/com/loafle/overflow/crawler/wmi/WMICrawlerLinux.java @@ -115,8 +115,17 @@ public class WMICrawlerLinux extends WMICrawlerOS { tempMap.put(columns.get(indexJ), datas[indexJ]); } + int tempSize = tempMap.size(); + int metaSize = metaMap.size(); + int resultSize = tempSize - metaSize; + + int currentIdx = 0; for (Map.Entry info : metaMap.entrySet()) { - row.set(info.getValue().intValue(), tempMap.get(info.getKey())); + currentIdx = info.getValue().intValue(); + if(currentIdx >= metaSize) { + currentIdx -= resultSize; + } + row.set(currentIdx, tempMap.get(info.getKey())); } diff --git a/src/main/java/com/loafle/overflow/crawler/wmi/WMICrawlerWindows.java b/src/main/java/com/loafle/overflow/crawler/wmi/WMICrawlerWindows.java index 123c758..72a6075 100644 --- a/src/main/java/com/loafle/overflow/crawler/wmi/WMICrawlerWindows.java +++ b/src/main/java/com/loafle/overflow/crawler/wmi/WMICrawlerWindows.java @@ -6,7 +6,7 @@ import com.jacob.com.EnumVariant; import com.jacob.com.Variant; import com.loafle.overflow.crawler.config.Config; import com.loafle.overflow.crawler.config.Item; -import com.loafle.overflow.crawler.config.Query; +//import com.loafle.overflow.crawler.config.Query; import com.loafle.overflow.crawler.result.OFResultSet; import com.loafle.overflow.crawler.result.OFResultSetCol; diff --git a/src/test/java/com/loafle/overflow/crawler/wmi/WMICrawlerTest.java b/src/test/java/com/loafle/overflow/crawler/wmi/WMICrawlerTest.java index 7e50dc2..255fd1a 100644 --- a/src/test/java/com/loafle/overflow/crawler/wmi/WMICrawlerTest.java +++ b/src/test/java/com/loafle/overflow/crawler/wmi/WMICrawlerTest.java @@ -32,13 +32,13 @@ public class WMICrawlerTest { } - @Ignore +// @Ignore @Test public void testLinuxExe() throws Exception { String command = "/home/snoop/temp/wmic"; - ProcessBuilder builder = new ProcessBuilder(command, "-U","administrator%!@#$qwer1234", "//192.168.1.1", "select * from Win32_OperatingSystem", "--namespace=root/cimv2", "--delimiter=||"); + ProcessBuilder builder = new ProcessBuilder(command, "-U","administrator%dbseogns18", "//192.168.1.106", "SELECT Caption FROM Win32_LogicalDisk", "--namespace=root/cimv2", "--delimiter=||"); Process process = builder.start(); byte[] msg = new byte[1024]; @@ -117,13 +117,13 @@ public class WMICrawlerTest { System.out.println(c); } - @Ignore +// @Ignore @Test public void testWMIJson() throws Exception { ObjectMapper mapper = new ObjectMapper(); ClassLoader classLoader = getClass().getClassLoader(); - String p = classLoader.getResource("config/example.json").getFile(); + String p = classLoader.getResource("config/test.json").getFile(); Config c = mapper.readValue(new File(p),Config.class); // Map map = new HashMap<>(); diff --git a/src/test/resources/config/test.json b/src/test/resources/config/test.json new file mode 100644 index 0000000..6740e59 --- /dev/null +++ b/src/test/resources/config/test.json @@ -0,0 +1,130 @@ +{ + "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": "cpu.usage.total.privilege", + "key": "PercentPrivilegedTime" + }, + { + "metric": "cpu.usage.total.user", + "key": "PercentUserTime" + }, + { + "metric": "cpu.usage.total.processor", + "key": "PercentProcessorTime" + }, + { + "metric": "cpu.usage.total.idle", + "key": "PercentIdleTime" + }], + "queryInfo": { + "query": "SELECT PercentPrivilegedTime, PercentUserTime, PercentProcessorTime, PercentIdleTime FROM Win32_PerfFormattedData_PerfOS_Processor WHERE Name='_Total'", + "extend": { + "nameSpace": "root/cimv2", + "wmicPath": "/home/snoop/temp/wmic" + } + }, + "mappingInfo": { + "parseDirection": "col", + "arrayColumns": null, + "keyColumns": null, + "valueColumn": null + } + }, + { + "keys": [{ + "metric": "disk.usage.free[$0]", + "key": "FreeSpace" + }, + { + "metric": "disk.usage.total[$0]", + "key": "Size" + }], + "queryInfo": { + "query": "SELECT FreeSpace, Size, Caption FROM Win32_LogicalDisk", + "extend": { + "nameSpace": "root/cimv2", + "wmicPath": "/home/snoop/temp/wmic" + } + }, + "mappingInfo": { + "parseDirection": "col", + "arrayColumns": ["Caption"], + "keyColumns": null, + "valueColumn": null + } + }, + { + "keys": [{ + "metric": "mem.usage.free.paging", + "key": "FreeSpaceInPagingFiles" + }], + "queryInfo": { + "query": "SELECT FreeSpaceInPagingFiles FROM Win32_OperatingSystem ", + "extend": { + "nameSpace": "root/cimv2", + "wmicPath": "/home/snoop/temp/wmic" + } + }, + "mappingInfo": { + "parseDirection": "col", + "arrayColumns": null, + "keyColumns": null, + "valueColumn": null + } + }, + { + "keys": [{ + "metric": "mem.usage.free.physical", + "key": "FreePhysicalMemory" + }, + { + "metric": "mem.usage.free.virtual", + "key": "FreeVirtualMemory" + }, + { + "metric": "mem.usage.total.paging", + "key": "SizeStoredInPagingFiles" + }, + { + "metric": "mem.usage.total.physical", + "key": "TotalVisibleMemorySize" + }, + { + "metric": "mem.usage.total.virtual", + "key": "TotalVirtualMemorySize" + }], + "queryInfo": { + "query": "SELECT FreePhysicalMemory, FreeVirtualMemory, SizeStoredInPagingFiles, TotalVisibleMemorySize, TotalVirtualMemorySize FROM Win32_OperatingSystem", + "extend": { + "nameSpace": "root/cimv2", + "wmicPath": "/home/snoop/temp/wmic" + } + }, + "mappingInfo": { + "parseDirection": "col", + "arrayColumns": null, + "keyColumns": null, + "valueColumn": null + } + }] +} \ No newline at end of file