Search in sources :

Example 1 with VmwareServer

use of org.opennms.netmgt.config.vmware.VmwareServer in project opennms by OpenNMS.

the class VmwareCollectorComplianceTest method getRequiredBeans.

@Override
public Map<String, Object> getRequiredBeans() {
    OnmsNode node = mock(OnmsNode.class, RETURNS_DEEP_STUBS);
    NodeDao nodeDao = mock(NodeDao.class);
    when(nodeDao.get(anyInt())).thenReturn(node);
    when(node.getAssetRecord().getVmwareManagementServer()).thenReturn("mdx");
    when(node.getAssetRecord().getVmwareManagedEntityType()).thenReturn("tsx");
    when(node.getForeignId()).thenReturn("rsx");
    VmwareCollection collection = new VmwareCollection();
    VmwareDatacollectionConfigDao vmwareDatacollectionConfigDao = mock(VmwareDatacollectionConfigDao.class);
    when(vmwareDatacollectionConfigDao.getVmwareCollection(COLLECTION)).thenReturn(collection);
    when(vmwareDatacollectionConfigDao.getRrdRepository(COLLECTION)).thenReturn(new RrdRepository());
    VmwareServer vmwareServer = new VmwareServer();
    vmwareServer.setHostname(InetAddrUtils.getLocalHostAddress().getCanonicalHostName());
    Map<String, VmwareServer> serverMap = new ImmutableMap.Builder<String, VmwareServer>().put("mdx", vmwareServer).build();
    VmwareConfigDao vmwareConfigDao = mock(VmwareConfigDao.class);
    when(vmwareConfigDao.getServerMap()).thenReturn(serverMap);
    return new ImmutableMap.Builder<String, Object>().put("nodeDao", nodeDao).put("vmwareDatacollectionConfigDao", vmwareDatacollectionConfigDao).put("vmwareConfigDao", vmwareConfigDao).build();
}
Also used : NodeDao(org.opennms.netmgt.dao.api.NodeDao) VmwareConfigDao(org.opennms.netmgt.dao.VmwareConfigDao) OnmsNode(org.opennms.netmgt.model.OnmsNode) VmwareServer(org.opennms.netmgt.config.vmware.VmwareServer) VmwareCollection(org.opennms.netmgt.config.vmware.vijava.VmwareCollection) VmwareDatacollectionConfigDao(org.opennms.netmgt.dao.VmwareDatacollectionConfigDao) RrdRepository(org.opennms.netmgt.rrd.RrdRepository)

Example 2 with VmwareServer

use of org.opennms.netmgt.config.vmware.VmwareServer 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();
}
Also used : MalformedURLException(java.net.MalformedURLException) CIMObject(org.sblim.wbem.cim.CIMObject) CollectionSetBuilder(org.opennms.netmgt.collection.support.builder.CollectionSetBuilder) HostRuntimeInfo(com.vmware.vim25.HostRuntimeInfo) HashMap(java.util.HashMap) DeferredGenericTypeResource(org.opennms.netmgt.collection.support.builder.DeferredGenericTypeResource) Resource(org.opennms.netmgt.collection.support.builder.Resource) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) VmwareCimCollection(org.opennms.netmgt.config.vmware.cim.VmwareCimCollection) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) HostSystemPowerState(com.vmware.vim25.HostSystemPowerState) CollectionException(org.opennms.netmgt.collection.api.CollectionException) MalformedURLException(java.net.MalformedURLException) RemoteException(java.rmi.RemoteException) CollectionInitializationException(org.opennms.netmgt.collection.api.CollectionInitializationException) Attrib(org.opennms.netmgt.config.vmware.cim.Attrib) DeferredGenericTypeResource(org.opennms.netmgt.collection.support.builder.DeferredGenericTypeResource) VmwareServer(org.opennms.netmgt.config.vmware.VmwareServer) AttributeType(org.opennms.netmgt.collection.api.AttributeType) HostSystem(com.vmware.vim25.mo.HostSystem) List(java.util.List) VmwareCimGroup(org.opennms.netmgt.config.vmware.cim.VmwareCimGroup) RemoteException(java.rmi.RemoteException) VmwareViJavaAccess(org.opennms.protocols.vmware.VmwareViJavaAccess)

Example 3 with VmwareServer

use of org.opennms.netmgt.config.vmware.VmwareServer in project opennms by OpenNMS.

the class VmwareCollector method getRuntimeAttributes.

@Override
public Map<String, Object> getRuntimeAttributes(CollectionAgent agent, Map<String, Object> parameters) {
    final Map<String, Object> runtimeAttributes = new HashMap<>();
    final OnmsNode onmsNode = m_nodeDao.get(agent.getNodeId());
    if (onmsNode == null) {
        throw new IllegalArgumentException(String.format("VmwareCollector: No node found with id: %d", agent.getNodeId()));
    }
    // retrieve the assets
    final String vmwareManagementServer = onmsNode.getAssetRecord().getVmwareManagementServer();
    if (Strings.isNullOrEmpty(vmwareManagementServer)) {
        throw new IllegalArgumentException(String.format("VmwareCollector: No management server is set on node with id %d.", onmsNode.getId()));
    }
    runtimeAttributes.put(VMWARE_MGMT_SERVER_KEY, vmwareManagementServer);
    final String vmwareManagedObjectId = onmsNode.getForeignId();
    if (Strings.isNullOrEmpty(vmwareManagedObjectId)) {
        throw new IllegalArgumentException(String.format("VmwareCollector: No foreign id is set on node with id %d.", onmsNode.getId()));
    }
    runtimeAttributes.put(VMWARE_MGED_OBJECT_ID_KEY, vmwareManagedObjectId);
    // retrieve the collection
    final String collectionName = ParameterMap.getKeyedString(parameters, "collection", ParameterMap.getKeyedString(parameters, "vmware-collection", null));
    final VmwareCollection collection = m_vmwareDatacollectionConfigDao.getVmwareCollection(collectionName);
    if (collection == null) {
        throw new IllegalArgumentException(String.format("VmwareCollector: No collection found with name '%s'.", collectionName));
    }
    runtimeAttributes.put(VMWARE_COLLECTION_KEY, collection);
    // retrieve the server configuration
    final Map<String, VmwareServer> serverMap = m_vmwareConfigDao.getServerMap();
    if (serverMap == null) {
        throw new IllegalStateException(String.format("VmwareCollector: Error getting vmware-config.xml's server map."));
    }
    final VmwareServer vmwareServer = serverMap.get(vmwareManagementServer);
    if (vmwareServer == null) {
        throw new IllegalStateException(String.format("VmwareCollector: Error getting credentials for VMware management server: %s", vmwareManagementServer));
    }
    runtimeAttributes.put(VMWARE_SERVER_KEY, vmwareServer);
    return runtimeAttributes;
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) HashMap(java.util.HashMap) VmwareServer(org.opennms.netmgt.config.vmware.VmwareServer) VmwareCollection(org.opennms.netmgt.config.vmware.vijava.VmwareCollection)

Example 4 with VmwareServer

use of org.opennms.netmgt.config.vmware.VmwareServer in project opennms by OpenNMS.

the class VmwareCollector 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 VmwareCollection collection = (VmwareCollection) 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.getVmwareGroup().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();
    }
    ManagedEntity managedEntity = vmwareViJavaAccess.getManagedEntityByManagedObjectId(vmwareManagedObjectId);
    VmwarePerformanceValues vmwarePerformanceValues = null;
    try {
        vmwarePerformanceValues = vmwareViJavaAccess.queryPerformanceValues(managedEntity);
    } catch (RemoteException e) {
        logger.warn("Error retrieving performance values from VMware management server '" + vmwareManagementServer + "' for managed object '" + vmwareManagedObjectId + "'", e.getMessage());
        vmwareViJavaAccess.disconnect();
        return builder.build();
    }
    for (final VmwareGroup vmwareGroup : collection.getVmwareGroup()) {
        final NodeLevelResource nodeResource = new NodeLevelResource(agent.getNodeId());
        if ("node".equalsIgnoreCase(vmwareGroup.getResourceType())) {
            for (Attrib attrib : vmwareGroup.getAttrib()) {
                if (!vmwarePerformanceValues.hasSingleValue(attrib.getName())) {
                    // warning
                    logger.debug("Warning! No single value for '{}' defined as single instance attribute for node {}", attrib.getName(), agent.getNodeId());
                } else {
                    final Long value = vmwarePerformanceValues.getValue(attrib.getName());
                    logger.debug("Storing single instance value {}='{}' for node {}", attrib.getName(), value, agent.getNodeId());
                    final AttributeType type = attrib.getType();
                    if (type.isNumeric()) {
                        builder.withNumericAttribute(nodeResource, vmwareGroup.getName(), attrib.getAlias(), value, type);
                    } else {
                        builder.withStringAttribute(nodeResource, vmwareGroup.getName(), attrib.getAlias(), String.valueOf(value));
                    }
                }
            }
        } else {
            // multi instance value
            final Set<String> instanceSet = new TreeSet<>();
            final HashMap<String, Resource> resources = new HashMap<>();
            for (Attrib attrib : vmwareGroup.getAttrib()) {
                if (!vmwarePerformanceValues.hasInstances(attrib.getName())) {
                    // warning
                    logger.debug("Warning! No multi instance value for '{}' defined as multi instance attribute for node {}", attrib.getName(), agent.getNodeId());
                } else {
                    Set<String> newInstances = vmwarePerformanceValues.getInstances(attrib.getName());
                    for (String instance : newInstances) {
                        if (!instanceSet.contains(instance)) {
                            resources.put(instance, new DeferredGenericTypeResource(nodeResource, vmwareGroup.getResourceType(), instance));
                            instanceSet.add(instance);
                        }
                        final AttributeType type = attrib.getType();
                        final Long value = vmwarePerformanceValues.getValue(attrib.getName(), instance);
                        logger.debug("Storing multi instance value {}[{}='{}' for node {}", attrib.getName(), instance, value, agent.getNodeId());
                        if (type.isNumeric()) {
                            builder.withNumericAttribute(resources.get(instance), vmwareGroup.getName(), attrib.getAlias(), value, type);
                        } else {
                            builder.withStringAttribute(resources.get(instance), vmwareGroup.getName(), attrib.getAlias(), Long.toString(value));
                        }
                    }
                }
            }
            for (String instance : instanceSet) {
                logger.debug("Storing multi instance value {}[{}='{}' for node {}", vmwareGroup.getResourceType() + "Name", instance, instance, agent.getNodeId());
                builder.withStringAttribute(resources.get(instance), vmwareGroup.getName(), vmwareGroup.getResourceType() + "Name", instance);
            }
        }
    }
    builder.withStatus(CollectionStatus.SUCCEEDED);
    vmwareViJavaAccess.disconnect();
    return builder.build();
}
Also used : ManagedEntity(com.vmware.vim25.mo.ManagedEntity) MalformedURLException(java.net.MalformedURLException) CollectionSetBuilder(org.opennms.netmgt.collection.support.builder.CollectionSetBuilder) HashMap(java.util.HashMap) DeferredGenericTypeResource(org.opennms.netmgt.collection.support.builder.DeferredGenericTypeResource) Resource(org.opennms.netmgt.collection.support.builder.Resource) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) Attrib(org.opennms.netmgt.config.vmware.vijava.Attrib) DeferredGenericTypeResource(org.opennms.netmgt.collection.support.builder.DeferredGenericTypeResource) VmwareGroup(org.opennms.netmgt.config.vmware.vijava.VmwareGroup) VmwareServer(org.opennms.netmgt.config.vmware.VmwareServer) AttributeType(org.opennms.netmgt.collection.api.AttributeType) TreeSet(java.util.TreeSet) VmwareCollection(org.opennms.netmgt.config.vmware.vijava.VmwareCollection) VmwarePerformanceValues(org.opennms.netmgt.collectd.vmware.vijava.VmwarePerformanceValues) RemoteException(java.rmi.RemoteException) VmwareViJavaAccess(org.opennms.protocols.vmware.VmwareViJavaAccess)

Example 5 with VmwareServer

use of org.opennms.netmgt.config.vmware.VmwareServer in project opennms by OpenNMS.

the class VmwareRequisitionProvider method getRequest.

@Override
public VmwareImportRequest getRequest(Map<String, String> parameters) {
    // Generate a request using the parameter map
    final VmwareImportRequest request = new VmwareImportRequest(parameters);
    if (StringUtils.isBlank(request.getUsername()) || StringUtils.isBlank(request.getPassword())) {
        // No credentials were specified in the parameter map, attempt to look these up
        final Map<String, VmwareServer> serverMap = vmwareConfigDao.getServerMap();
        final VmwareServer vmwareServer = serverMap.get(request.getHostname());
        if (vmwareServer != null) {
            // We found a corresponding entry - copy the credentials to the request
            request.setUsername(vmwareServer.getUsername());
            request.setPassword(vmwareServer.getPassword());
        }
    }
    // Lookup the existing requisition, and store it in the request
    final Requisition existingRequisition = getExistingRequisition(request.getForeignSource());
    request.setExistingRequisition(existingRequisition);
    return request;
}
Also used : VmwareServer(org.opennms.netmgt.config.vmware.VmwareServer) Requisition(org.opennms.netmgt.provision.persist.requisition.Requisition)

Aggregations

VmwareServer (org.opennms.netmgt.config.vmware.VmwareServer)9 OnmsNode (org.opennms.netmgt.model.OnmsNode)5 HashMap (java.util.HashMap)4 VmwareCimCollection (org.opennms.netmgt.config.vmware.cim.VmwareCimCollection)3 VmwareCollection (org.opennms.netmgt.config.vmware.vijava.VmwareCollection)3 VmwareConfigDao (org.opennms.netmgt.dao.VmwareConfigDao)3 NodeDao (org.opennms.netmgt.dao.api.NodeDao)3 MalformedURLException (java.net.MalformedURLException)2 RemoteException (java.rmi.RemoteException)2 List (java.util.List)2 AttributeType (org.opennms.netmgt.collection.api.AttributeType)2 CollectionSetBuilder (org.opennms.netmgt.collection.support.builder.CollectionSetBuilder)2 DeferredGenericTypeResource (org.opennms.netmgt.collection.support.builder.DeferredGenericTypeResource)2 NodeLevelResource (org.opennms.netmgt.collection.support.builder.NodeLevelResource)2 Resource (org.opennms.netmgt.collection.support.builder.Resource)2 RrdRepository (org.opennms.netmgt.rrd.RrdRepository)2 VmwareViJavaAccess (org.opennms.protocols.vmware.VmwareViJavaAccess)2 CIMObject (org.sblim.wbem.cim.CIMObject)2 HostRuntimeInfo (com.vmware.vim25.HostRuntimeInfo)1 HostSystemPowerState (com.vmware.vim25.HostSystemPowerState)1