Search in sources :

Example 1 with CollectionSpecification

use of org.opennms.netmgt.collection.core.CollectionSpecification in project opennms by OpenNMS.

the class Collectd method getSpecificationsForInterface.

/**
 * <p>getSpecificationsForInterface</p>
 *
 * @param iface a {@link org.opennms.netmgt.model.OnmsIpInterface} object.
 * @param svcName a {@link java.lang.String} object.
 * @return a {@link java.util.Collection} object.
 */
public Collection<CollectionSpecification> getSpecificationsForInterface(OnmsIpInterface iface, String svcName) {
    Collection<CollectionSpecification> matchingPkgs = new LinkedList<>();
    CollectdConfiguration collectdConfig = m_collectdConfigFactory.getCollectdConfig();
    /*
         * Compare interface/service pair against each collectd package
         * For each match, create new SnmpCollector object and
         * schedule it for collection
         */
    for (Package wpkg : collectdConfig.getPackages()) {
        /*
             * Make certain the the current service is in the package
             * and enabled!
             */
        if (!wpkg.serviceInPackageAndEnabled(svcName)) {
            LOG.debug("getSpecificationsForInterface: address/service: {}/{} not scheduled, service is not enabled or does not exist in package: {}", iface, svcName, wpkg.getName());
            continue;
        }
        // Ensure that the package is not a remote package
        if (wpkg.isRemote()) {
            LOG.debug("getSpecificationsForInterface: address/service: {}/{} not scheduled, package {} is a remote package.", iface, svcName, wpkg.getName());
            continue;
        }
        // Is the interface in the package?
        if (!m_collectdConfigFactory.interfaceInPackage(iface, wpkg)) {
            LOG.debug("getSpecificationsForInterface: address/service: {}/{} not scheduled, interface does not belong to package: {}", iface, svcName, wpkg.getName());
            continue;
        }
        LOG.debug("getSpecificationsForInterface: address/service: {}/{} scheduled, interface does belong to package: {}", iface, svcName, wpkg.getName());
        matchingPkgs.add(new CollectionSpecification(wpkg, svcName, getServiceCollector(svcName), instrumentation(), m_locationAwareCollectorClient));
    }
    return matchingPkgs;
}
Also used : CollectdConfiguration(org.opennms.netmgt.config.collectd.CollectdConfiguration) CollectionSpecification(org.opennms.netmgt.collection.core.CollectionSpecification) Package(org.opennms.netmgt.config.collectd.Package) LinkedList(java.util.LinkedList)

Example 2 with CollectionSpecification

use of org.opennms.netmgt.collection.core.CollectionSpecification in project opennms by OpenNMS.

the class Collectd method scheduleInterface.

private void scheduleInterface(OnmsIpInterface iface, String svcName, boolean existing) {
    final String ipAddress = str(iface.getIpAddress());
    if (ipAddress == null) {
        LOG.warn("Unable to schedule interface {}, could not determine IP address.", iface);
        return;
    }
    instrumentation().beginScheduleInterface(iface.getNode().getId(), ipAddress, svcName);
    try {
        Collection<CollectionSpecification> matchingSpecs = getSpecificationsForInterface(iface, svcName);
        StringBuilder sb;
        LOG.debug("scheduleInterface: found {} matching specs for interface: {}", matchingSpecs.size(), iface);
        for (CollectionSpecification spec : matchingSpecs) {
            if (existing == false) {
                /*
                 * It is possible that both a nodeGainedService and a
                 * primarySnmpInterfaceChanged event are generated for an
                 * interface during a rescan. To handle this scenario we must
                 * verify that the ipAddress/pkg pair identified by this event
                 * does not already exist in the collectable services list.
                 */
                if (alreadyScheduled(iface, spec)) {
                    LOG.debug("scheduleInterface: svc/pkgName {}/{} already in collectable service list, skipping.", iface, spec);
                    continue;
                }
            }
            try {
                /*
                 * Criteria checks have all passed. The interface/service pair
                 * can be scheduled.
                 */
                LOG.debug("scheduleInterface: now scheduling interface: {}/{}", iface, svcName);
                CollectableService cSvc = null;
                /*
                 * Create a new SnmpCollector object representing this node,
                 * interface, service and package pairing
                 */
                cSvc = new CollectableService(iface, m_ifaceDao, spec, getScheduler(), m_schedulingCompletedFlag, m_transTemplate.getTransactionManager(), m_persisterFactory, m_resourceStorageDao);
                // Add new collectable service to the collectable service list.
                m_collectableServices.add(cSvc);
                // Schedule the collectable service for immediate collection
                getScheduler().schedule(0, cSvc.getReadyRunnable());
                LOG.debug("scheduleInterface: {}/{} collection, scheduled", iface, svcName);
            } catch (CollectionInitializationException e) {
                sb = new StringBuilder();
                sb.append("scheduleInterface: Unable to schedule ");
                sb.append(iface);
                sb.append('/');
                sb.append(svcName);
                sb.append(", reason: ");
                sb.append(e.getMessage());
                // http://issues.opennms.org/browse/NMS-3324
                if (LOG.isTraceEnabled()) {
                    LOG.trace(sb.toString(), e);
                } else {
                    LOG.info(sb.toString());
                }
            } catch (Throwable t) {
                LOG.error("scheduleInterface: Uncaught exception, failed to schedule interface {}/{}.", iface, svcName, t);
            }
        }
    // end while more specifications exist
    } finally {
        instrumentation().endScheduleInterface(iface.getNode().getId(), ipAddress, svcName);
    }
}
Also used : CollectionSpecification(org.opennms.netmgt.collection.core.CollectionSpecification) CollectionInitializationException(org.opennms.netmgt.collection.api.CollectionInitializationException)

Example 3 with CollectionSpecification

use of org.opennms.netmgt.collection.core.CollectionSpecification in project opennms by OpenNMS.

the class CollectorTestUtils method createCollectionSpec.

public static CollectionSpecification createCollectionSpec(String svcName, ServiceCollector svcCollector, String collectionName) {
    Package pkg = new Package();
    Filter filter = new Filter();
    filter.setContent("IPADDR IPLIKE *.*.*.*");
    pkg.setFilter(filter);
    Service service = new Service();
    service.setName(svcName);
    Parameter collectionParm = new Parameter();
    collectionParm.setKey("collection");
    collectionParm.setValue(collectionName);
    service.addParameter(collectionParm);
    pkg.addService(service);
    CollectionSpecification spec = new CollectionSpecification(pkg, svcName, svcCollector, new DefaultCollectdInstrumentation(), createLocationAwareCollectorClient());
    return spec;
}
Also used : Filter(org.opennms.netmgt.config.collectd.Filter) CollectionSpecification(org.opennms.netmgt.collection.core.CollectionSpecification) Service(org.opennms.netmgt.config.collectd.Service) Parameter(org.opennms.netmgt.config.collectd.Parameter) Package(org.opennms.netmgt.config.collectd.Package) DefaultCollectdInstrumentation(org.opennms.netmgt.collection.core.DefaultCollectdInstrumentation)

Example 4 with CollectionSpecification

use of org.opennms.netmgt.collection.core.CollectionSpecification in project opennms by OpenNMS.

the class HttpCollectorIT method doTestNMS4886.

public final void doTestNMS4886(String svcName) throws Exception {
    HttpCollector collector = new HttpCollector();
    Map<String, String> parameters = new HashMap<String, String>();
    parameters.put("http-collection", "default");
    parameters.put("port", "10342");
    collector.initialize();
    Package pkg = new Package();
    Filter filter = new Filter();
    filter.setContent("IPADDR IPLIKE *.*.*.*");
    pkg.setFilter(filter);
    Service service = new Service();
    service.setName(svcName);
    Parameter collectionParm = new Parameter();
    collectionParm.setKey("http-collection");
    collectionParm.setValue("default");
    service.addParameter(collectionParm);
    Parameter portParm = new Parameter();
    portParm.setKey("port");
    portParm.setValue("10342");
    service.addParameter(portParm);
    pkg.addService(service);
    CollectionSpecification collectionSpecification = new CollectionSpecification(pkg, svcName, collector, new DefaultCollectdInstrumentation(), CollectorTestUtils.createLocationAwareCollectorClient());
    CollectionSet collectionSet = collectionSpecification.collect(m_collectionAgent);
    assertEquals("collection status", CollectionStatus.SUCCEEDED, collectionSet.getStatus());
    CollectorTestUtils.persistCollectionSet(m_rrdStrategy, m_resourceStorageDao, collectionSpecification, collectionSet);
}
Also used : HashMap(java.util.HashMap) Filter(org.opennms.netmgt.config.collectd.Filter) CollectionSpecification(org.opennms.netmgt.collection.core.CollectionSpecification) Service(org.opennms.netmgt.config.collectd.Service) Parameter(org.opennms.netmgt.config.collectd.Parameter) Package(org.opennms.netmgt.config.collectd.Package) DefaultCollectdInstrumentation(org.opennms.netmgt.collection.core.DefaultCollectdInstrumentation) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet)

Aggregations

CollectionSpecification (org.opennms.netmgt.collection.core.CollectionSpecification)4 Package (org.opennms.netmgt.config.collectd.Package)3 DefaultCollectdInstrumentation (org.opennms.netmgt.collection.core.DefaultCollectdInstrumentation)2 Filter (org.opennms.netmgt.config.collectd.Filter)2 Parameter (org.opennms.netmgt.config.collectd.Parameter)2 Service (org.opennms.netmgt.config.collectd.Service)2 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 CollectionInitializationException (org.opennms.netmgt.collection.api.CollectionInitializationException)1 CollectionSet (org.opennms.netmgt.collection.api.CollectionSet)1 CollectdConfiguration (org.opennms.netmgt.config.collectd.CollectdConfiguration)1