added infrahost - wmi
This commit is contained in:
parent
a50164bec1
commit
297e94b21f
|
@ -19,6 +19,7 @@ import com.loafle.overflow.module.sensor.model.Sensor;
|
||||||
import com.loafle.overflow.module.sensor.model.SensorItem;
|
import com.loafle.overflow.module.sensor.model.SensorItem;
|
||||||
import com.loafle.overflow.module.target.model.Target;
|
import com.loafle.overflow.module.target.model.Target;
|
||||||
import org.codehaus.jackson.map.ObjectMapper;
|
import org.codehaus.jackson.map.ObjectMapper;
|
||||||
|
import org.codehaus.jackson.type.TypeReference;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
@ -281,66 +282,104 @@ public class SensorService {
|
||||||
}
|
}
|
||||||
private void processWMI(List<SensorItem> sensorItems, Map<Integer, MetaSensorItemKey> keyMap, Sensor dbSensor, Config config) throws IOException {
|
private void processWMI(List<SensorItem> sensorItems, Map<Integer, MetaSensorItemKey> keyMap, Sensor dbSensor, Config config) throws IOException {
|
||||||
|
|
||||||
List<Keys> keysList = new ArrayList<>();
|
Map<String, List<MetaSensorItemKey>> metricMap = new HashMap<>();
|
||||||
|
|
||||||
Map<String, List<Keys>> metricMap = new HashMap<>();
|
|
||||||
|
|
||||||
MetaSensorItemKey itemKey = null;
|
MetaSensorItemKey itemKey = null;
|
||||||
Keys keys = null;
|
|
||||||
for(SensorItem sItem : sensorItems) {
|
for(SensorItem sItem : sensorItems) {
|
||||||
|
|
||||||
itemKey = keyMap.get(sItem.getItem().getId());
|
itemKey = keyMap.get(sItem.getItem().getId());
|
||||||
|
|
||||||
if(metricMap.containsKey(itemKey.getFroms()) == false) {
|
if(metricMap.containsKey(itemKey.getFroms()) == false) {
|
||||||
metricMap.put(itemKey.getFroms(), new ArrayList<>());
|
metricMap.put(itemKey.getFroms(), new ArrayList<>());
|
||||||
}
|
}
|
||||||
keys = new Keys();
|
metricMap.get(itemKey.getFroms()).add(itemKey);
|
||||||
keys.setKey(itemKey.getKey());
|
|
||||||
keys.setMetric(itemKey.getItem().getKey());
|
|
||||||
|
|
||||||
metricMap.get(itemKey.getFroms()).add(keys);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Item> itemList = new ArrayList<>();
|
List<Item> itemList = new ArrayList<>();
|
||||||
Item item = null;
|
Item item = null;
|
||||||
QueryInfo queryInfo = null;
|
QueryInfo queryInfo = null;
|
||||||
MappingInfo mappingInfo = null;
|
MappingInfo mappingInfo = null;
|
||||||
String query = null;
|
|
||||||
StringBuffer stringBuffer = new StringBuffer();
|
StringBuffer stringBuffer = new StringBuffer();
|
||||||
|
|
||||||
Map<String, Object> extendMap = new HashMap<>();
|
Map<String, Object> extendMap = new HashMap<>();
|
||||||
extendMap.put("nameSpace", "root/cimv2");
|
extendMap.put("nameSpace", "root/cimv2");
|
||||||
extendMap.put("wmicPath", "/home/snoop/temp/wmic");
|
extendMap.put("wmicPath", "/home/snoop/temp/wmic");
|
||||||
|
|
||||||
for(Map.Entry<String, List<Keys>> elems : metricMap.entrySet()) {
|
|
||||||
|
List<Keys> keysList = null;
|
||||||
|
MetaSensorItemKey tempItemKey = null;
|
||||||
|
Keys keys = null;
|
||||||
|
for(Map.Entry<String, List<MetaSensorItemKey>> elems : metricMap.entrySet()) {
|
||||||
|
keysList = new ArrayList<>();
|
||||||
item = new Item();
|
item = new Item();
|
||||||
stringBuffer.setLength(0);
|
stringBuffer.setLength(0);
|
||||||
|
|
||||||
stringBuffer.append("SELECT ");
|
stringBuffer.append("SELECT ");
|
||||||
|
|
||||||
for(int indexI = 0; indexI < elems.getValue().size(); ++indexI) {
|
for(int indexI = 0; indexI < elems.getValue().size(); ++indexI) {
|
||||||
stringBuffer.append(elems.getValue().get(indexI).getKey());
|
|
||||||
|
tempItemKey = elems.getValue().get(indexI);
|
||||||
|
stringBuffer.append(tempItemKey.getKey());
|
||||||
if(indexI + 1 < elems.getValue().size()) {
|
if(indexI + 1 < elems.getValue().size()) {
|
||||||
stringBuffer.append(", ");
|
stringBuffer.append(", ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
keys = new Keys();
|
||||||
|
keys.setKey(tempItemKey.getKey());
|
||||||
|
keys.setMetric(tempItemKey.getItem().getKey());
|
||||||
|
keysList.add(keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
List<String> arrayColumns = null;
|
||||||
|
|
||||||
|
String json = tempItemKey.getOption();
|
||||||
|
if(json != null && json.length() > 0) {
|
||||||
|
HashMap<String,Object> optionMap;
|
||||||
|
optionMap = new ObjectMapper().readValue(json, new TypeReference<HashMap<String,Object>>() {});
|
||||||
|
|
||||||
|
Object obj = null;
|
||||||
|
obj = optionMap.get("appends");
|
||||||
|
if(obj != null) {
|
||||||
|
List<String> appendsList = (List<String>)obj;
|
||||||
|
for(String append : appendsList) {
|
||||||
|
stringBuffer.append(", ");
|
||||||
|
stringBuffer.append(append);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stringBuffer.append(" FROM ");
|
stringBuffer.append(" FROM ");
|
||||||
stringBuffer.append(elems.getKey());
|
stringBuffer.append(elems.getKey());
|
||||||
|
|
||||||
|
obj = optionMap.get("where");
|
||||||
|
if(obj != null) {
|
||||||
|
String where = (String)obj;
|
||||||
|
stringBuffer.append(" WHERE ");
|
||||||
|
stringBuffer.append(where);
|
||||||
|
}
|
||||||
|
|
||||||
|
obj = optionMap.get("arrayColumns");
|
||||||
|
if(obj != null) {
|
||||||
|
arrayColumns = (List<String>)obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
stringBuffer.append(" FROM ");
|
||||||
|
stringBuffer.append(elems.getKey());
|
||||||
|
}
|
||||||
|
|
||||||
queryInfo = new QueryInfo();
|
queryInfo = new QueryInfo();
|
||||||
queryInfo.setQuery(stringBuffer.toString());
|
queryInfo.setQuery(stringBuffer.toString());
|
||||||
queryInfo.setExtend(extendMap);
|
queryInfo.setExtend(extendMap);
|
||||||
|
|
||||||
mappingInfo = new MappingInfo();
|
mappingInfo = new MappingInfo();
|
||||||
mappingInfo.setParseDirection("col");
|
mappingInfo.setParseDirection("col");
|
||||||
List<String> arrayColumns = new ArrayList<>();
|
|
||||||
arrayColumns.add("Caption");
|
|
||||||
mappingInfo.setArrayColumns(arrayColumns);
|
mappingInfo.setArrayColumns(arrayColumns);
|
||||||
|
|
||||||
item.setMappingInfo(mappingInfo);
|
item.setMappingInfo(mappingInfo);
|
||||||
item.setQueryInfo(queryInfo);
|
item.setQueryInfo(queryInfo);
|
||||||
item.setKeys(elems.getValue());
|
item.setKeys(keysList);
|
||||||
|
|
||||||
itemList.add(item);
|
itemList.add(item);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user