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.target.model.Target;
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
import org.codehaus.jackson.type.TypeReference;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -281,52 +282,92 @@ public class SensorService {
|
|||
}
|
||||
private void processWMI(List<SensorItem> sensorItems, Map<Integer, MetaSensorItemKey> keyMap, Sensor dbSensor, Config config) throws IOException {
|
||||
|
||||
List<Keys> keysList = new ArrayList<>();
|
||||
|
||||
Map<String, List<Keys>> metricMap = new HashMap<>();
|
||||
Map<String, List<MetaSensorItemKey>> metricMap = new HashMap<>();
|
||||
|
||||
MetaSensorItemKey itemKey = null;
|
||||
Keys keys = null;
|
||||
|
||||
for(SensorItem sItem : sensorItems) {
|
||||
|
||||
itemKey = keyMap.get(sItem.getItem().getId());
|
||||
|
||||
if(metricMap.containsKey(itemKey.getFroms()) == false) {
|
||||
metricMap.put(itemKey.getFroms(), new ArrayList<>());
|
||||
}
|
||||
keys = new Keys();
|
||||
keys.setKey(itemKey.getKey());
|
||||
keys.setMetric(itemKey.getItem().getKey());
|
||||
|
||||
metricMap.get(itemKey.getFroms()).add(keys);
|
||||
metricMap.get(itemKey.getFroms()).add(itemKey);
|
||||
}
|
||||
|
||||
List<Item> itemList = new ArrayList<>();
|
||||
Item item = null;
|
||||
QueryInfo queryInfo = null;
|
||||
MappingInfo mappingInfo = null;
|
||||
String query = null;
|
||||
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
|
||||
Map<String, Object> extendMap = new HashMap<>();
|
||||
extendMap.put("nameSpace", "root/cimv2");
|
||||
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();
|
||||
stringBuffer.setLength(0);
|
||||
|
||||
stringBuffer.append("SELECT ");
|
||||
|
||||
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()) {
|
||||
stringBuffer.append(", ");
|
||||
}
|
||||
|
||||
keys = new Keys();
|
||||
keys.setKey(tempItemKey.getKey());
|
||||
keys.setMetric(tempItemKey.getItem().getKey());
|
||||
keysList.add(keys);
|
||||
}
|
||||
|
||||
stringBuffer.append(" FROM ");
|
||||
stringBuffer.append(elems.getKey());
|
||||
|
||||
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(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.setQuery(stringBuffer.toString());
|
||||
|
@ -334,13 +375,11 @@ public class SensorService {
|
|||
|
||||
mappingInfo = new MappingInfo();
|
||||
mappingInfo.setParseDirection("col");
|
||||
List<String> arrayColumns = new ArrayList<>();
|
||||
arrayColumns.add("Caption");
|
||||
mappingInfo.setArrayColumns(arrayColumns);
|
||||
|
||||
item.setMappingInfo(mappingInfo);
|
||||
item.setQueryInfo(queryInfo);
|
||||
item.setKeys(elems.getValue());
|
||||
item.setKeys(keysList);
|
||||
|
||||
itemList.add(item);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user