ing
This commit is contained in:
parent
3c4df318af
commit
67fc64a274
|
@ -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";
|
||||
|
@ -30,4 +46,55 @@ public class WMICrawler implements Crawler {
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -38,10 +38,8 @@ public abstract class WMICrawlerOS {
|
|||
returnMap.putAll(ofResultSet.getData());
|
||||
}
|
||||
|
||||
|
||||
return returnMap;
|
||||
}
|
||||
|
||||
public abstract ResultSet processWMI(SensorConfig sensorConfig, Item item) throws Exception;
|
||||
}
|
||||
|
||||
|
|
49
src/main/resources/config/wmi/meta/meta_cpu.json
Normal file
49
src/main/resources/config/wmi/meta/meta_cpu.json
Normal 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
|
||||
}
|
||||
}]
|
||||
}
|
61
src/main/resources/config/wmi/meta/meta_filesystem.json
Normal file
61
src/main/resources/config/wmi/meta/meta_filesystem.json
Normal 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
|
||||
}
|
||||
}]
|
||||
}
|
53
src/main/resources/config/wmi/meta/meta_memory.json
Normal file
53
src/main/resources/config/wmi/meta/meta_memory.json
Normal 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
|
||||
}
|
||||
}]
|
||||
}
|
53
src/main/resources/config/wmi/meta/meta_network.json
Normal file
53
src/main/resources/config/wmi/meta/meta_network.json
Normal 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
|
||||
}
|
||||
}]
|
||||
}
|
|
@ -1,2 +0,0 @@
|
|||
server.netty.thread.count.boss=1
|
||||
server.netty.thread.count.worker=10
|
Loading…
Reference in New Issue
Block a user