This commit is contained in:
crusader 2018-04-25 23:06:23 +09:00
parent 3c4df318af
commit 67fc64a274
7 changed files with 310 additions and 31 deletions

View File

@ -1,12 +1,28 @@
package com.loafle.overflow.container.general.crawler.impl.wmi; 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.core.exception.OverflowException;
import com.loafle.overflow.crawler.Crawler; import com.loafle.overflow.crawler.Crawler;
import com.loafle.overflow.model.sensorconfig.ResultSet;
import com.loafle.overflow.model.sensorconfig.SensorConfig; 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; import java.util.Map;
public class WMICrawler implements Crawler { public class WMICrawler implements Crawler {
private Gson gson;
public WMICrawler() {
this.gson = new Gson();
}
@Override @Override
public String name() { public String name() {
return "WMI"; return "WMI";
@ -23,11 +39,62 @@ public class WMICrawler implements Crawler {
} }
@Override @Override
public Map<String, String> get(SensorConfig sensorConfig) throws OverflowException { public Map<String, String> get(SensorConfig sensorConfig) throws OverflowException {
try { try {
return WMICrawlerOS.getInstance().process(sensorConfig); return WMICrawlerOS.getInstance().process(sensorConfig);
} catch (Exception e) { } catch (Exception e) {
throw new OverflowException("WMICrawler", e); throw new OverflowException("WMICrawler", e);
}
}
public Object getMeta(SensorConfig sensorConfig) throws OverflowException {
try {
List<SensorConfig> metaConfigList = loadMetaConfig();
WMICrawlerOS os = WMICrawlerOS.getInstance();
Map<String, String> returnMap = new HashMap<String, String>();
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<SensorConfig> 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<SensorConfig> 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;
}
} }

View File

@ -9,39 +9,37 @@ import com.loafle.overflow.model.sensorconfig.SensorConfig;
public abstract class WMICrawlerOS { 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) { if (os.indexOf("linux") >= 0) {
WMICrawlerOS.wmiCrawlerOS = new WMICrawlerLinux(); WMICrawlerOS.wmiCrawlerOS = new WMICrawlerLinux();
} else if(os.indexOf("") >= 0) { } else if (os.indexOf("") >= 0) {
WMICrawlerOS.wmiCrawlerOS = new WMICrawlerWindows(); WMICrawlerOS.wmiCrawlerOS = new WMICrawlerWindows();
} }
}
return WMICrawlerOS.wmiCrawlerOS;
} }
public Map<String, String> process(SensorConfig sensorConfig) throws Exception { return WMICrawlerOS.wmiCrawlerOS;
Map<String, String> returnMap = new HashMap<String, String>(); }
ResultSet ofResultSet = null; public Map<String, String> process(SensorConfig sensorConfig) throws Exception {
for(int cIndexI = 0 ; cIndexI < sensorConfig.getItems().size() ; ++cIndexI) { Map<String, String> returnMap = new HashMap<String, String>();
ofResultSet = processWMI(sensorConfig, sensorConfig.getItems().get(cIndexI)); ResultSet ofResultSet = null;
returnMap.putAll(ofResultSet.getData()); for (int cIndexI = 0; cIndexI < sensorConfig.getItems().size(); ++cIndexI) {
}
ofResultSet = processWMI(sensorConfig, sensorConfig.getItems().get(cIndexI));
return returnMap; 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;
} }

View File

@ -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
}
}]
}

View File

@ -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
}
}]
}

View File

@ -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
}
}]
}

View File

@ -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
}
}]
}

View File

@ -1,2 +0,0 @@
server.netty.thread.count.boss=1
server.netty.thread.count.worker=10