use of com.vmware.vim25.mo.ManagedEntity in project opennms by OpenNMS.
the class VmwareImporter method iterateHostSystems.
/**
* Iterates through the host systems and adds them to the requisition object.
*
* @param vmwareViJavaAccess the access/connection to use
* @throws RemoteException
*/
private void iterateHostSystems(VmwareViJavaAccess vmwareViJavaAccess, int apiVersion) throws RemoteException {
ManagedEntity[] hostSystems;
// search for host systems (esx hosts)
logger.debug("Starting to iterate host systems on VMware host {} ...", request.getHostname());
hostSystems = vmwareViJavaAccess.searchManagedEntities("HostSystem");
if (hostSystems != null) {
for (ManagedEntity managedEntity : hostSystems) {
HostSystem hostSystem = (HostSystem) managedEntity;
logger.debug("Iterating host systems on VMware management server {} : {} (ID: {})", request.getHostname(), hostSystem.getName(), hostSystem.getMOR().getVal());
m_hostSystemMap.put(hostSystem.getMOR().getVal(), hostSystem.getName());
// check for correct key/value-pair
if (checkHostPowerState(hostSystem) && checkForAttribute(hostSystem)) {
logger.debug("Adding Host System '{}' (ID: {})", hostSystem.getName(), hostSystem.getMOR().getVal());
// iterate over all service console networks and add interface Ip addresses
TreeSet<String> ipAddresses = vmwareViJavaAccess.getHostSystemIpAddresses(hostSystem);
// create the new node...
RequisitionNode node = createRequisitionNode(ipAddresses, hostSystem, apiVersion, vmwareViJavaAccess);
// add cpu
try {
node.putAsset(new RequisitionAsset("cpu", hostSystem.getHardware().getCpuInfo().getNumCpuCores() + " cores"));
} catch (Exception e) {
logger.debug("Can't find CPU information for {} (ID: {})", hostSystem.getName(), hostSystem.getMOR().getVal());
}
// add memory
try {
node.putAsset(new RequisitionAsset("ram", Math.round(hostSystem.getHardware().getMemorySize() / 1000000f) + " MB"));
} catch (Exception e) {
logger.debug("Can't find Memory information for {} (ID: {})", hostSystem.getName(), hostSystem.getMOR().getVal());
}
// add vendor
/*
try {
node.putAsset(new RequisitionAsset("vendor", hostSystem.getHardware().getSystemInfo().getVendor()));
} catch (Exception e) {
logger.debug("Can't find vendor information for {}", hostSystem.getName());
}
*/
// set the location
node.setLocation(request.getLocation());
// ...and add it to the requisition
if (node != null && request.isPersistHosts()) {
m_requisition.insertNode(node);
}
}
}
}
}
use of com.vmware.vim25.mo.ManagedEntity in project opennms by OpenNMS.
the class VmwareViJavaAccess method getManagedEntityByManagedObjectId.
/**
* Returns a managed entitiy for a given managed object Id.
*
* @param managedObjectId the managed object Id
* @return the managed entity
*/
public ManagedEntity getManagedEntityByManagedObjectId(String managedObjectId) {
ManagedObjectReference managedObjectReference = new ManagedObjectReference();
managedObjectReference.setType("ManagedEntity");
managedObjectReference.setVal(managedObjectId);
ManagedEntity managedEntity = MorUtil.createExactManagedEntity(m_serviceInstance.getServerConnection(), managedObjectReference);
return managedEntity;
}
use of com.vmware.vim25.mo.ManagedEntity in project opennms by OpenNMS.
the class VmwareViJavaAccess method queryPerformanceValues.
/**
* This method queries performance values for a given managed entity.
*
* @param managedEntity the managed entity to query
* @return the perfomance values
* @throws RemoteException
*/
public VmwarePerformanceValues queryPerformanceValues(ManagedEntity managedEntity) throws RemoteException {
VmwarePerformanceValues vmwarePerformanceValues = new VmwarePerformanceValues();
int refreshRate = getPerformanceManager().queryPerfProviderSummary(managedEntity).getRefreshRate();
PerfQuerySpec perfQuerySpec = new PerfQuerySpec();
perfQuerySpec.setEntity(managedEntity.getMOR());
perfQuerySpec.setMaxSample(Integer.valueOf(1));
perfQuerySpec.setIntervalId(refreshRate);
PerfEntityMetricBase[] perfEntityMetricBases = getPerformanceManager().queryPerf(new PerfQuerySpec[] { perfQuerySpec });
if (perfEntityMetricBases != null) {
for (int i = 0; i < perfEntityMetricBases.length; i++) {
PerfMetricSeries[] perfMetricSeries = ((PerfEntityMetric) perfEntityMetricBases[i]).getValue();
for (int j = 0; perfMetricSeries != null && j < perfMetricSeries.length; j++) {
if (perfMetricSeries[j] instanceof PerfMetricIntSeries) {
long[] longs = ((PerfMetricIntSeries) perfMetricSeries[j]).getValue();
if (longs.length == 1) {
PerfCounterInfo perfCounterInfo = getPerfCounterInfoMap().get(perfMetricSeries[j].getId().getCounterId());
String instance = perfMetricSeries[j].getId().getInstance();
String name = getHumanReadableName(perfCounterInfo);
if (instance != null && !"".equals(instance)) {
vmwarePerformanceValues.addValue(name, instance, longs[0]);
} else {
vmwarePerformanceValues.addValue(name, longs[0]);
}
}
}
}
}
}
return vmwarePerformanceValues;
}
use of com.vmware.vim25.mo.ManagedEntity in project opennms by OpenNMS.
the class VmwareCimQuery method cimQuery.
private static void cimQuery(String hostname, String username, String password) {
System.out.print("Trying to connect to " + hostname + "... ");
VmwareViJavaAccess vmwareViJavaAccess = new VmwareViJavaAccess(hostname, username, password);
try {
vmwareViJavaAccess.connect();
} catch (MalformedURLException e) {
System.out.println("Exception:");
e.printStackTrace();
return;
} catch (RemoteException e) {
System.out.println("Exception:");
e.printStackTrace();
return;
}
System.out.println("Success!");
ManagedEntity[] hostSystems;
System.out.print(" Querying " + hostname + " for host systems... ");
try {
hostSystems = vmwareViJavaAccess.searchManagedEntities("HostSystem");
} catch (RemoteException remoteException) {
remoteException.printStackTrace();
vmwareViJavaAccess.disconnect();
return;
}
if (hostSystems != null) {
System.out.println(hostSystems.length + " host system(s) found!");
for (ManagedEntity managedEntity : hostSystems) {
HostSystem hostSystem = (HostSystem) managedEntity;
if (hostSystem.getSummary() != null) {
if (hostSystem.getRuntime() != null) {
String powerState = hostSystem.getRuntime().getPowerState().toString();
if (!"poweredOn".equals(powerState)) {
System.out.println(" Ignoring host system " + hostSystem.getName() + " (powerState=" + powerState + ")... ");
continue;
} else {
System.out.print(" Determining primary Ip address of host system " + hostSystem.getName() + " (powerState=" + powerState + ")... ");
}
} else {
System.out.println(" Ignoring host system " + hostSystem.getName() + " (powerState=unknown)... ");
continue;
}
} else {
System.out.println(" Ignoring host system " + hostSystem.getName() + " (powerState=unknown)... ");
continue;
}
String ipAddress;
try {
ipAddress = vmwareViJavaAccess.getPrimaryHostSystemIpAddress(hostSystem);
} catch (RemoteException remoteException) {
System.out.println("Exception:");
remoteException.printStackTrace();
continue;
}
if (ipAddress != null) {
System.out.print(ipAddress + "\n Querying host system " + hostSystem.getName() + " for numeric sensors... ");
List<CIMObject> cimObjects;
try {
cimObjects = vmwareViJavaAccess.queryCimObjects(hostSystem, "CIM_NumericSensor");
} catch (Exception e) {
System.out.println("Exception:");
e.printStackTrace();
continue;
}
if (cimObjects != null) {
// FIXME queryCimObjects returns an empty list or a filled list, but never null
System.out.println(cimObjects.size() + " sensor(s) found!");
for (CIMObject cimObject : cimObjects) {
String healthState = vmwareViJavaAccess.getPropertyOfCimObject(cimObject, "HealthState");
String cimObjectName = vmwareViJavaAccess.getPropertyOfCimObject(cimObject, "Name");
System.out.print(" " + cimObjectName);
if (healthState != null) {
System.out.println(" " + m_healthStates.get(Integer.valueOf(healthState)));
} else {
System.out.println();
}
}
} else {
System.out.println("NULL - aborting...");
continue;
}
} else {
System.out.println("NULL - aborting...");
continue;
}
}
} else {
System.out.println("NULL - aborting...");
}
System.out.println("Cleaning up...");
vmwareViJavaAccess.disconnect();
}
use of com.vmware.vim25.mo.ManagedEntity in project opennms by OpenNMS.
the class VmwareConfigBuilder method generateData.
private void generateData(String rrdRepository) throws Exception {
serviceInstance = new ServiceInstance(new URL("https://" + hostname + "/sdk"), username, password);
performanceManager = serviceInstance.getPerformanceManager();
PerfCounterInfo[] perfCounterInfos = performanceManager.getPerfCounter();
for (PerfCounterInfo perfCounterInfo : perfCounterInfos) {
perfCounterInfoMap.put(perfCounterInfo.getKey(), perfCounterInfo);
}
System.out.println("Generating configuration files for '" + serviceInstance.getAboutInfo().getFullName() + "' using rrdRepository '" + rrdRepository + "'...");
StringBuffer buffer = new StringBuffer();
buffer.append("Configuration file generated for:\n\n");
buffer.append("Full name.......: " + serviceInstance.getAboutInfo().getFullName() + "\n");
buffer.append("API type........: " + serviceInstance.getAboutInfo().getApiType() + "\n");
buffer.append("API version.....: " + serviceInstance.getAboutInfo().getApiVersion() + "\n");
buffer.append("Product name....: " + serviceInstance.getAboutInfo().getLicenseProductName() + "\n");
buffer.append("Product version.: " + serviceInstance.getAboutInfo().getLicenseProductVersion() + "\n");
buffer.append("OS type.........: " + serviceInstance.getAboutInfo().getOsType() + "\n");
versionInformation = buffer.toString();
String[] arr = serviceInstance.getAboutInfo().getApiVersion().split("\\.");
if (arr.length > 1) {
apiVersion = arr[0];
if (Integer.valueOf(apiVersion) < 4) {
apiVersion = "3";
}
}
ManagedEntity[] hostSystems, virtualMachines;
virtualMachines = new InventoryNavigator(serviceInstance.getRootFolder()).searchManagedEntities("VirtualMachine");
if (virtualMachines != null) {
if (virtualMachines.length > 0) {
for (ManagedEntity managedEntity : virtualMachines) {
if ("poweredOn".equals(((VirtualMachine) managedEntity).getRuntime().getPowerState().toString())) {
lookupMetrics("default-VirtualMachine" + apiVersion, managedEntity.getMOR().getVal());
break;
}
}
} else {
System.err.println("No virtual machines found");
}
}
hostSystems = new InventoryNavigator(serviceInstance.getRootFolder()).searchManagedEntities("HostSystem");
if (hostSystems != null) {
if (hostSystems.length > 0) {
for (ManagedEntity managedEntity : hostSystems) {
if ("poweredOn".equals(((HostSystem) managedEntity).getRuntime().getPowerState().toString())) {
lookupMetrics("default-HostSystem" + apiVersion, managedEntity.getMOR().getVal());
break;
}
}
} else {
System.err.println("No host systems found!");
}
}
saveVMwareDatacollectionConfig(rrdRepository);
saveVMwareDatacollectionInclude();
saveVMwareGraphProperties();
}
Aggregations