use of com.vmware.vim25.HostSystemPowerState in project opennms by OpenNMS.
the class VmwareCimCollector method collect.
/**
* This method collect the data for a given collection agent.
*
* @param agent the collection agent
* @param parameters the parameters map
* @return the generated collection set
* @throws CollectionException
*/
@Override
public CollectionSet collect(CollectionAgent agent, Map<String, Object> parameters) throws CollectionException {
final VmwareCimCollection collection = (VmwareCimCollection) parameters.get(VMWARE_COLLECTION_KEY);
final String vmwareManagementServer = (String) parameters.get(VMWARE_MGMT_SERVER_KEY);
final String vmwareManagedObjectId = (String) parameters.get(VMWARE_MGED_OBJECT_ID_KEY);
final VmwareServer vmwareServer = (VmwareServer) parameters.get(VMWARE_SERVER_KEY);
CollectionSetBuilder builder = new CollectionSetBuilder(agent);
builder.withStatus(CollectionStatus.FAILED);
VmwareViJavaAccess vmwareViJavaAccess = new VmwareViJavaAccess(vmwareServer);
int timeout = ParameterMap.getKeyedInteger(parameters, "timeout", -1);
if (timeout > 0) {
if (!vmwareViJavaAccess.setTimeout(timeout)) {
logger.warn("Error setting connection timeout for VMware management server '{}'", vmwareManagementServer);
}
}
if (collection.getVmwareCimGroup().length < 1) {
logger.info("No groups to collect. Returning empty collection set.");
builder.withStatus(CollectionStatus.SUCCEEDED);
return builder.build();
}
try {
vmwareViJavaAccess.connect();
} catch (MalformedURLException e) {
logger.warn("Error connecting VMware management server '{}': '{}' exception: {} cause: '{}'", vmwareManagementServer, e.getMessage(), e.getClass().getName(), e.getCause());
return builder.build();
} catch (RemoteException e) {
logger.warn("Error connecting VMware management server '{}': '{}' exception: {} cause: '{}'", vmwareManagementServer, e.getMessage(), e.getClass().getName(), e.getCause());
return builder.build();
}
HostSystem hostSystem = vmwareViJavaAccess.getHostSystemByManagedObjectId(vmwareManagedObjectId);
String powerState = null;
if (hostSystem == null) {
logger.debug("hostSystem=null");
} else {
HostRuntimeInfo hostRuntimeInfo = hostSystem.getRuntime();
if (hostRuntimeInfo == null) {
logger.debug("hostRuntimeInfo=null");
} else {
HostSystemPowerState hostSystemPowerState = hostRuntimeInfo.getPowerState();
if (hostSystemPowerState == null) {
logger.debug("hostSystemPowerState=null");
} else {
powerState = hostSystemPowerState.toString();
}
}
}
logger.debug("The power state for host system '{}' is '{}'", vmwareManagedObjectId, powerState);
if ("poweredOn".equals(powerState)) {
HashMap<String, List<CIMObject>> cimObjects = new HashMap<String, List<CIMObject>>();
for (final VmwareCimGroup vmwareCimGroup : collection.getVmwareCimGroup()) {
String cimClass = vmwareCimGroup.getCimClass();
if (!cimObjects.containsKey(cimClass)) {
List<CIMObject> cimList = null;
try {
cimList = vmwareViJavaAccess.queryCimObjects(hostSystem, cimClass, InetAddressUtils.str(agent.getAddress()));
} catch (Exception e) {
logger.warn("Error retrieving CIM values from host system '{}'. Error message: '{}'", vmwareManagedObjectId, e.getMessage());
return builder.build();
} finally {
vmwareViJavaAccess.disconnect();
}
cimObjects.put(cimClass, cimList);
}
final List<CIMObject> cimList = cimObjects.get(cimClass);
if (cimList == null) {
logger.warn("Error getting objects of CIM class '{}' from host system '{}'", cimClass, vmwareManagedObjectId);
continue;
}
String keyAttribute = vmwareCimGroup.getKey();
String attributeValue = vmwareCimGroup.getValue();
String instanceAttribute = vmwareCimGroup.getInstance();
for (CIMObject cimObject : cimList) {
boolean addObject = false;
if (keyAttribute != null && attributeValue != null) {
String cimObjectValue = vmwareViJavaAccess.getPropertyOfCimObject(cimObject, keyAttribute);
if (attributeValue.equals(cimObjectValue)) {
addObject = true;
} else {
addObject = false;
}
} else {
addObject = true;
}
if (addObject) {
final String instance = vmwareViJavaAccess.getPropertyOfCimObject(cimObject, instanceAttribute);
final NodeLevelResource nodeResource = new NodeLevelResource(agent.getNodeId());
final Resource resource = new DeferredGenericTypeResource(nodeResource, vmwareCimGroup.getResourceType(), instance);
for (Attrib attrib : vmwareCimGroup.getAttrib()) {
final AttributeType type = attrib.getType();
String value = vmwareViJavaAccess.getPropertyOfCimObject(cimObject, attrib.getName());
if (valueModifiers.containsKey(attrib.getName())) {
String modifiedValue = valueModifiers.get(attrib.getName()).modifyValue(attrib.getName(), value, cimObject, vmwareViJavaAccess);
logger.debug("Applying value modifier for instance value " + attrib.getName() + "[" + instance + "]='" + value + "' => '" + modifiedValue + "' for node " + agent.getNodeId());
value = modifiedValue;
}
builder.withAttribute(resource, vmwareCimGroup.getName(), attrib.getAlias(), value, type);
}
}
}
}
builder.withStatus(CollectionStatus.SUCCEEDED);
}
vmwareViJavaAccess.disconnect();
return builder.build();
}
use of com.vmware.vim25.HostSystemPowerState in project opennms by OpenNMS.
the class VmwareCimMonitor method poll.
/**
* This method queries the Vmware hypervisor for sensor data.
*
* @param svc the monitored service
* @param parameters the parameter map
* @return the poll status for this system
*/
@Override
public PollStatus poll(MonitoredService svc, Map<String, Object> parameters) {
final boolean ignoreStandBy = getKeyedBoolean(parameters, "ignoreStandBy", false);
final String vmwareManagementServer = getKeyedString(parameters, VMWARE_MANAGEMENT_SERVER_KEY, null);
final String vmwareManagedObjectId = getKeyedString(parameters, VMWARE_MANAGED_OBJECT_ID_KEY, null);
final String vmwareMangementServerUsername = getKeyedString(parameters, VMWARE_MANAGEMENT_SERVER_USERNAME_KEY, null);
final String vmwareMangementServerPassword = getKeyedString(parameters, VMWARE_MANAGEMENT_SERVER_PASSWORD_KEY, null);
TimeoutTracker tracker = new TimeoutTracker(parameters, DEFAULT_RETRY, DEFAULT_TIMEOUT);
PollStatus serviceStatus = PollStatus.unknown();
for (tracker.reset(); tracker.shouldRetry() && !serviceStatus.isAvailable(); tracker.nextAttempt()) {
final VmwareViJavaAccess vmwareViJavaAccess = new VmwareViJavaAccess(vmwareManagementServer, vmwareMangementServerUsername, vmwareMangementServerPassword);
try {
vmwareViJavaAccess.connect();
} catch (MalformedURLException e) {
logger.warn("Error connecting VMware management server '{}': '{}' exception: {} cause: '{}'", vmwareManagementServer, e.getMessage(), e.getClass().getName(), e.getCause());
return PollStatus.unavailable("Error connecting VMware management server '" + vmwareManagementServer + "'");
} catch (RemoteException e) {
logger.warn("Error connecting VMware management server '{}': '{}' exception: {} cause: '{}'", vmwareManagementServer, e.getMessage(), e.getClass().getName(), e.getCause());
return PollStatus.unavailable("Error connecting VMware management server '" + vmwareManagementServer + "'");
}
if (!vmwareViJavaAccess.setTimeout(tracker.getConnectionTimeout())) {
logger.warn("Error setting connection timeout for VMware management server '{}'", vmwareManagementServer);
}
HostSystem hostSystem = vmwareViJavaAccess.getHostSystemByManagedObjectId(vmwareManagedObjectId);
String powerState = null;
if (hostSystem == null) {
return PollStatus.unknown("hostSystem=null");
} else {
HostRuntimeInfo hostRuntimeInfo = hostSystem.getRuntime();
if (hostRuntimeInfo == null) {
return PollStatus.unknown("hostRuntimeInfo=null");
} else {
HostSystemPowerState hostSystemPowerState = hostRuntimeInfo.getPowerState();
if (hostSystemPowerState == null) {
return PollStatus.unknown("hostSystemPowerState=null");
} else {
powerState = hostSystemPowerState.toString();
}
}
}
if ("poweredOn".equals(powerState)) {
List<CIMObject> cimObjects = null;
try {
cimObjects = vmwareViJavaAccess.queryCimObjects(hostSystem, "CIM_NumericSensor", svc.getIpAddr());
} catch (Exception e) {
logger.warn("Error retrieving CIM values from host system '{}'", vmwareManagedObjectId, e.getMessage());
vmwareViJavaAccess.disconnect();
return PollStatus.unavailable("Error retrieving cim values from host system '" + vmwareManagedObjectId + "'");
}
boolean success = true;
final StringBuilder reason = new StringBuilder("VMware CIM query returned: ");
for (CIMObject cimObject : cimObjects) {
String healthState = vmwareViJavaAccess.getPropertyOfCimObject(cimObject, "HealthState");
String cimObjectName = vmwareViJavaAccess.getPropertyOfCimObject(cimObject, "Name");
if (healthState != null) {
int healthStateInt = Integer.valueOf(healthState).intValue();
if (healthStateInt != 5) {
if (!success) {
reason.append(", ");
}
success = false;
reason.append(cimObjectName + " ");
if (m_healthStates.containsKey(healthStateInt)) {
reason.append("(" + m_healthStates.get(healthStateInt) + ")");
} else {
reason.append("(" + healthStateInt + ")");
}
}
}
}
if (success) {
serviceStatus = PollStatus.available();
} else {
serviceStatus = PollStatus.unavailable(reason.toString());
}
} else {
if (ignoreStandBy && "standBy".equals(powerState)) {
serviceStatus = PollStatus.up();
} else {
serviceStatus = PollStatus.unresponsive("Host system's power state is '" + powerState + "'");
}
}
vmwareViJavaAccess.disconnect();
}
return serviceStatus;
}
use of com.vmware.vim25.HostSystemPowerState in project opennms by OpenNMS.
the class VmwareMonitor method poll.
/**
* This method queries the Vmware vCenter server for sensor data.
*
* @param svc the monitored service
* @param parameters the parameter map
* @return the poll status for this system
*/
@Override
public PollStatus poll(MonitoredService svc, Map<String, Object> parameters) {
final boolean ignoreStandBy = getKeyedBoolean(parameters, "ignoreStandBy", false);
final String vmwareManagementServer = getKeyedString(parameters, VMWARE_MANAGEMENT_SERVER_KEY, null);
final String vmwareManagedEntityType = getKeyedString(parameters, VMWARE_MANAGED_ENTITY_TYPE_KEY, null);
final String vmwareManagedObjectId = getKeyedString(parameters, VMWARE_MANAGED_OBJECT_ID_KEY, null);
final String vmwareMangementServerUsername = getKeyedString(parameters, VMWARE_MANAGEMENT_SERVER_USERNAME_KEY, null);
final String vmwareMangementServerPassword = getKeyedString(parameters, VMWARE_MANAGEMENT_SERVER_PASSWORD_KEY, null);
final TimeoutTracker tracker = new TimeoutTracker(parameters, DEFAULT_RETRY, DEFAULT_TIMEOUT);
PollStatus serviceStatus = PollStatus.unknown();
for (tracker.reset(); tracker.shouldRetry() && !serviceStatus.isAvailable(); tracker.nextAttempt()) {
final VmwareViJavaAccess vmwareViJavaAccess = new VmwareViJavaAccess(vmwareManagementServer, vmwareMangementServerUsername, vmwareMangementServerPassword);
try {
vmwareViJavaAccess.connect();
} catch (MalformedURLException e) {
logger.warn("Error connecting VMware management server '{}': '{}' exception: {} cause: '{}'", vmwareManagementServer, e.getMessage(), e.getClass().getName(), e.getCause());
return PollStatus.unavailable("Error connecting VMware management server '" + vmwareManagementServer + "'");
} catch (RemoteException e) {
logger.warn("Error connecting VMware management server '{}': '{}' exception: {} cause: '{}'", vmwareManagementServer, e.getMessage(), e.getClass().getName(), e.getCause());
return PollStatus.unavailable("Error connecting VMware management server '" + vmwareManagementServer + "'");
}
if (!vmwareViJavaAccess.setTimeout(tracker.getConnectionTimeout())) {
logger.warn("Error setting connection timeout for VMware management server '{}'", vmwareManagementServer);
}
String powerState = "unknown";
if ("HostSystem".equals(vmwareManagedEntityType)) {
HostSystem hostSystem = vmwareViJavaAccess.getHostSystemByManagedObjectId(vmwareManagedObjectId);
if (hostSystem == null) {
return PollStatus.unknown("hostSystem=null");
} else {
HostRuntimeInfo hostRuntimeInfo = hostSystem.getRuntime();
if (hostRuntimeInfo == null) {
return PollStatus.unknown("hostRuntimeInfo=null");
} else {
HostSystemPowerState hostSystemPowerState = hostRuntimeInfo.getPowerState();
if (hostSystemPowerState == null) {
return PollStatus.unknown("hostSystemPowerState=null");
} else {
powerState = hostSystemPowerState.toString();
}
}
}
} else {
if ("VirtualMachine".equals(vmwareManagedEntityType)) {
VirtualMachine virtualMachine = vmwareViJavaAccess.getVirtualMachineByManagedObjectId(vmwareManagedObjectId);
if (virtualMachine == null) {
return PollStatus.unknown("virtualMachine=null");
} else {
VirtualMachineRuntimeInfo virtualMachineRuntimeInfo = virtualMachine.getRuntime();
if (virtualMachineRuntimeInfo == null) {
return PollStatus.unknown("virtualMachineRuntimeInfo=null");
} else {
VirtualMachinePowerState virtualMachinePowerState = virtualMachineRuntimeInfo.getPowerState();
if (virtualMachinePowerState == null) {
return PollStatus.unknown("virtualMachinePowerState=null");
} else {
powerState = virtualMachinePowerState.toString();
}
}
}
} else {
logger.warn("Error getting '{}' for '{}'", vmwareManagedEntityType, vmwareManagedObjectId);
vmwareViJavaAccess.disconnect();
return serviceStatus;
}
}
if ("poweredOn".equals(powerState)) {
serviceStatus = PollStatus.available();
} else {
if (ignoreStandBy && "standBy".equals(powerState)) {
serviceStatus = PollStatus.up();
} else {
serviceStatus = PollStatus.unavailable("The system's state is '" + powerState + "'");
}
}
vmwareViJavaAccess.disconnect();
}
return serviceStatus;
}
use of com.vmware.vim25.HostSystemPowerState in project opennms by OpenNMS.
the class VmwareImporter method createRequisitionNode.
/**
* Creates a requisition node for the given managed entity and type.
*
* @param ipAddresses the set of Ip addresses
* @param managedEntity the managed entity
* @return the generated requisition node
*/
private RequisitionNode createRequisitionNode(Set<String> ipAddresses, ManagedEntity managedEntity, int apiVersion, VmwareViJavaAccess vmwareViJavaAccess) {
RequisitionNode requisitionNode = new RequisitionNode();
// Setting the node label
requisitionNode.setNodeLabel(managedEntity.getName());
// Foreign Id consisting of managed entity Id
requisitionNode.setForeignId(managedEntity.getMOR().getVal());
/*
* Original version:
*
* Foreign Id consisting of VMware management server's hostname and managed entity id
*
* requisitionNode.setForeignId(m_hostname + "/" + managedEntity.getMOR().getVal());
*/
logger.debug("Start primary interface search for managed entity '{}' (ID: {})", managedEntity.getName(), managedEntity.getMOR().getVal());
if (managedEntity instanceof VirtualMachine) {
boolean firstInterface = true;
// add all given interfaces
for (String ipAddress : ipAddresses) {
try {
if ((request.isPersistIPv4() && InetAddressUtils.isIPv4Address(ipAddress)) || (request.isPersistIPv6() && InetAddressUtils.isIPv6Address(ipAddress))) {
InetAddress inetAddress = InetAddress.getByName(ipAddress);
if (!inetAddress.isLoopbackAddress()) {
RequisitionInterface requisitionInterface = new RequisitionInterface();
requisitionInterface.setIpAddr(ipAddress);
// the first one will be primary
if (firstInterface) {
requisitionInterface.setSnmpPrimary(PrimaryType.PRIMARY);
for (String service : request.getVirtualMachineServices()) {
requisitionInterface.insertMonitoredService(new RequisitionMonitoredService(service.trim()));
}
firstInterface = false;
} else {
requisitionInterface.setSnmpPrimary(PrimaryType.SECONDARY);
}
requisitionInterface.setManaged(Boolean.TRUE);
requisitionInterface.setStatus(Integer.valueOf(1));
requisitionNode.putInterface(requisitionInterface);
}
}
} catch (UnknownHostException unknownHostException) {
logger.warn("Invalid IP address '{}'", unknownHostException.getMessage());
}
}
} else {
if (managedEntity instanceof HostSystem) {
boolean reachableInterfaceFound = false, firstInterface = true;
List<RequisitionInterface> requisitionInterfaceList = new ArrayList<>();
RequisitionInterface primaryInterfaceCandidate = null;
// add all given interfaces
for (String ipAddress : ipAddresses) {
try {
if ((request.isPersistIPv4() && InetAddressUtils.isIPv4Address(ipAddress)) || (request.isPersistIPv6() && InetAddressUtils.isIPv6Address(ipAddress))) {
InetAddress inetAddress = InetAddress.getByName(ipAddress);
if (!inetAddress.isLoopbackAddress()) {
RequisitionInterface requisitionInterface = new RequisitionInterface();
requisitionInterface.setIpAddr(ipAddress);
if (firstInterface) {
primaryInterfaceCandidate = requisitionInterface;
firstInterface = false;
}
if (!reachableInterfaceFound && reachableCimService(vmwareViJavaAccess, (HostSystem) managedEntity, ipAddress)) {
primaryInterfaceCandidate = requisitionInterface;
reachableInterfaceFound = true;
}
requisitionInterface.setManaged(Boolean.TRUE);
requisitionInterface.setStatus(Integer.valueOf(1));
requisitionInterface.setSnmpPrimary(PrimaryType.SECONDARY);
requisitionInterfaceList.add(requisitionInterface);
}
}
} catch (UnknownHostException unknownHostException) {
logger.warn("Invalid IP address '{}'", unknownHostException.getMessage());
}
}
if (primaryInterfaceCandidate != null) {
if (reachableInterfaceFound) {
logger.warn("Found reachable primary interface '{}'", primaryInterfaceCandidate.getIpAddr());
} else {
logger.warn("Only non-reachable interfaces found, using first one for primary interface '{}'", primaryInterfaceCandidate.getIpAddr());
}
primaryInterfaceCandidate.setSnmpPrimary(PrimaryType.PRIMARY);
for (String service : request.getHostSystemServices()) {
if (reachableInterfaceFound || !"VMwareCim-HostSystem".equals(service)) {
primaryInterfaceCandidate.insertMonitoredService(new RequisitionMonitoredService(service.trim()));
}
}
} else {
logger.warn("No primary interface found");
}
for (RequisitionInterface requisitionInterface : requisitionInterfaceList) {
requisitionNode.putInterface(requisitionInterface);
}
} else {
logger.error("Undefined type of managedEntity '{}'", managedEntity.getMOR().getType());
return null;
}
}
/*
* For now we use displaycategory, notifycategory and pollercategory for storing
* the vcenter Ip address, the username and the password
*/
String powerState = "unknown";
final StringBuilder vmwareTopologyInfo = new StringBuilder();
// putting parents to topology information
ManagedEntity parentEntity = managedEntity.getParent();
do {
if (vmwareTopologyInfo.length() > 0) {
vmwareTopologyInfo.append(", ");
}
try {
if (parentEntity != null && parentEntity.getMOR() != null) {
vmwareTopologyInfo.append(parentEntity.getMOR().getVal() + "/" + URLEncoder.encode(parentEntity.getName(), StandardCharsets.UTF_8.name()));
} else {
logger.warn("Can't add topologyInformation because either the parentEntity or the MOR is null for " + managedEntity.getName());
}
} catch (UnsupportedEncodingException e) {
logger.warn("Unsupported encoding '{}'", e.getMessage());
}
parentEntity = parentEntity == null ? null : parentEntity.getParent();
} while (parentEntity != null);
if (managedEntity instanceof HostSystem) {
HostSystem hostSystem = (HostSystem) managedEntity;
HostRuntimeInfo hostRuntimeInfo = hostSystem.getRuntime();
if (hostRuntimeInfo == null) {
logger.debug("hostRuntimeInfo=null");
} else {
HostSystemPowerState hostSystemPowerState = hostRuntimeInfo.getPowerState();
if (hostSystemPowerState == null) {
logger.debug("hostSystemPowerState=null");
} else {
powerState = hostSystemPowerState.toString();
}
}
try {
if (request.isTopologyDatastores()) {
for (Datastore datastore : hostSystem.getDatastores()) {
if (vmwareTopologyInfo.length() > 0) {
vmwareTopologyInfo.append(", ");
}
try {
vmwareTopologyInfo.append(datastore.getMOR().getVal() + "/" + URLEncoder.encode(datastore.getSummary().getName(), StandardCharsets.UTF_8.name()));
} catch (UnsupportedEncodingException e) {
logger.warn("Unsupported encoding '{}'", e.getMessage());
}
}
}
} catch (RemoteException e) {
logger.warn("Cannot retrieve datastores for managedEntity '{}': '{}'", managedEntity.getMOR().getVal(), e.getMessage());
}
try {
if (request.isTopologyNetworks()) {
for (Network network : hostSystem.getNetworks()) {
if (vmwareTopologyInfo.length() > 0) {
vmwareTopologyInfo.append(", ");
}
try {
if (network instanceof DistributedVirtualPortgroup ? request.isTopologyPortGroups() : true) {
vmwareTopologyInfo.append(network.getMOR().getVal() + "/" + URLEncoder.encode(network.getSummary().getName(), StandardCharsets.UTF_8.name()));
}
} catch (UnsupportedEncodingException e) {
logger.warn("Unsupported encoding '{}'", e.getMessage());
}
}
}
} catch (RemoteException e) {
logger.warn("Cannot retrieve networks for managedEntity '{}': '{}'", managedEntity.getMOR().getVal(), e.getMessage());
}
} else {
if (managedEntity instanceof VirtualMachine) {
VirtualMachine virtualMachine = (VirtualMachine) managedEntity;
VirtualMachineRuntimeInfo virtualMachineRuntimeInfo = virtualMachine.getRuntime();
if (virtualMachineRuntimeInfo == null) {
logger.debug("virtualMachineRuntimeInfo=null");
} else {
VirtualMachinePowerState virtualMachinePowerState = virtualMachineRuntimeInfo.getPowerState();
if (virtualMachinePowerState == null) {
logger.debug("virtualMachinePowerState=null");
} else {
powerState = virtualMachinePowerState.toString();
}
}
try {
if (request.isTopologyDatastores()) {
for (Datastore datastore : virtualMachine.getDatastores()) {
if (vmwareTopologyInfo.length() > 0) {
vmwareTopologyInfo.append(", ");
}
try {
vmwareTopologyInfo.append(datastore.getMOR().getVal() + "/" + URLEncoder.encode(datastore.getSummary().getName(), StandardCharsets.UTF_8.name()));
} catch (UnsupportedEncodingException e) {
logger.warn("Unsupported encoding '{}'", e.getMessage());
}
}
}
} catch (RemoteException e) {
logger.warn("Cannot retrieve datastores for managedEntity '{}': '{}'", managedEntity.getMOR().getVal(), e.getMessage());
}
try {
if (request.isTopologyNetworks()) {
for (Network network : virtualMachine.getNetworks()) {
if (vmwareTopologyInfo.length() > 0) {
vmwareTopologyInfo.append(", ");
}
try {
if (network instanceof DistributedVirtualPortgroup ? request.isTopologyPortGroups() : true) {
vmwareTopologyInfo.append(network.getMOR().getVal() + "/" + URLEncoder.encode(network.getSummary().getName(), StandardCharsets.UTF_8.name()));
}
} catch (UnsupportedEncodingException e) {
logger.warn("Unsupported encoding '{}'", e.getMessage());
}
}
}
} catch (RemoteException e) {
logger.warn("Cannot retrieve networks for managedEntity '{}': '{}'", managedEntity.getMOR().getVal(), e.getMessage());
}
if (vmwareTopologyInfo.length() > 0) {
vmwareTopologyInfo.append(", ");
}
try {
if (m_hostSystemMap.get(virtualMachine.getRuntime().getHost().getVal()) != null) {
vmwareTopologyInfo.append(virtualMachine.getRuntime().getHost().getVal() + "/" + URLEncoder.encode(m_hostSystemMap.get(virtualMachine.getRuntime().getHost().getVal()), StandardCharsets.UTF_8.name()));
} else {
logger.warn("Problem building topology information for virtual machine '{}' with power state '{}' running on host system '{}'", virtualMachine.getMOR().getVal(), powerState, virtualMachine.getRuntime().getHost().getVal());
}
} catch (UnsupportedEncodingException e) {
logger.warn("Unsupported encoding '{}'", e.getMessage());
}
} else {
logger.error("Undefined type of managedEntity '{}'", managedEntity.getMOR().getType());
return null;
}
}
RequisitionAsset requisitionAssetHostname = new RequisitionAsset("vmwareManagementServer", request.getHostname());
requisitionNode.putAsset(requisitionAssetHostname);
RequisitionAsset requisitionAssetType = new RequisitionAsset("vmwareManagedEntityType", (managedEntity instanceof HostSystem ? "HostSystem" : "VirtualMachine"));
requisitionNode.putAsset(requisitionAssetType);
RequisitionAsset requisitionAssetId = new RequisitionAsset("vmwareManagedObjectId", managedEntity.getMOR().getVal());
requisitionNode.putAsset(requisitionAssetId);
RequisitionAsset requisitionAssetTopologyInfo = new RequisitionAsset("vmwareTopologyInfo", vmwareTopologyInfo.toString());
requisitionNode.putAsset(requisitionAssetTopologyInfo);
RequisitionAsset requisitionAssetState = new RequisitionAsset("vmwareState", powerState);
requisitionNode.putAsset(requisitionAssetState);
requisitionNode.putCategory(new RequisitionCategory("VMware" + apiVersion));
return requisitionNode;
}
Aggregations