use of org.opennms.protocols.vmware.VmwareViJavaAccess 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;
StringBuffer reason = new StringBuffer("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;
}
Aggregations