Search in sources :

Example 1 with VmwareCollection

use of org.opennms.netmgt.config.vmware.vijava.VmwareCollection 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 VmwareCollection

use of org.opennms.netmgt.config.vmware.vijava.VmwareCollection 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 3 with VmwareCollection

use of org.opennms.netmgt.config.vmware.vijava.VmwareCollection 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 4 with VmwareCollection

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

the class VmwareDatacollectionConfigDaoJaxb method getVmwareCollection.

/**
     * This method returns a subset of the configuration data for a given collection name.
     *
     * @param collectionName the collection's name
     * @return the collection object
     */
@Override
public VmwareCollection getVmwareCollection(String collectionName) {
    VmwareCollection[] collections = getConfig().getVmwareCollection();
    VmwareCollection collection = null;
    for (VmwareCollection coll : collections) {
        if (coll.getName().equalsIgnoreCase(collectionName)) {
            collection = coll;
            break;
        }
    }
    if (collection == null) {
        throw new IllegalArgumentException("getVmwareCollection: collection name: " + collectionName + " specified in collectd configuration not found in Vmware collection configuration.");
    }
    return collection;
}
Also used : VmwareCollection(org.opennms.netmgt.config.vmware.vijava.VmwareCollection)

Aggregations

VmwareCollection (org.opennms.netmgt.config.vmware.vijava.VmwareCollection)4 VmwareServer (org.opennms.netmgt.config.vmware.VmwareServer)3 HashMap (java.util.HashMap)2 OnmsNode (org.opennms.netmgt.model.OnmsNode)2 ManagedEntity (com.vmware.vim25.mo.ManagedEntity)1 MalformedURLException (java.net.MalformedURLException)1 RemoteException (java.rmi.RemoteException)1 TreeSet (java.util.TreeSet)1 VmwarePerformanceValues (org.opennms.netmgt.collectd.vmware.vijava.VmwarePerformanceValues)1 AttributeType (org.opennms.netmgt.collection.api.AttributeType)1 CollectionSetBuilder (org.opennms.netmgt.collection.support.builder.CollectionSetBuilder)1 DeferredGenericTypeResource (org.opennms.netmgt.collection.support.builder.DeferredGenericTypeResource)1 NodeLevelResource (org.opennms.netmgt.collection.support.builder.NodeLevelResource)1 Resource (org.opennms.netmgt.collection.support.builder.Resource)1 Attrib (org.opennms.netmgt.config.vmware.vijava.Attrib)1 VmwareGroup (org.opennms.netmgt.config.vmware.vijava.VmwareGroup)1 VmwareConfigDao (org.opennms.netmgt.dao.VmwareConfigDao)1 VmwareDatacollectionConfigDao (org.opennms.netmgt.dao.VmwareDatacollectionConfigDao)1 NodeDao (org.opennms.netmgt.dao.api.NodeDao)1 RrdRepository (org.opennms.netmgt.rrd.RrdRepository)1