/** * <p>getPackage</p> * * @param name a {@link java.lang.String} object. * @return a {@link org.opennms.netmgt.config.collectd.Package} object. */ public Package getPackage(final String name) { synchronized (m_collectdConfigMutex) { for (Package pkg : m_collectdConfig.getPackages()) { if (pkg.getName().equals(name)) { return pkg; } } return null; } }
public CollectdConfiguration getCollectdConfigurationForPackages(List<String> collectionPackageNames) { if (collectionPackageNames == null || collectionPackageNames.size() < 1) return null; final Set<String> seenCollectors = new HashSet<>(); final CollectdConfiguration newConfig = new CollectdConfiguration(); newConfig.setThreads(getThreads()); // Add all requested polling packages to the config boolean foundPackage = false; for (String packageName : collectionPackageNames) { final Package pkg = getPackage(packageName); if (pkg != null) { newConfig.addPackage(pkg); foundPackage = true; for (final Service service : pkg.getServices()) { seenCollectors.add(service.getName()); } } } // If the list of polling packages doesn't match anything, then return null if (!foundPackage) return null; for (final Collector collector : getCollectors()) { if (seenCollectors.contains(collector.getService())) { newConfig.addCollector(collector); } } return newConfig; }
private void setupCollector(String svcName, ServiceCollector svcCollector) throws CollectionInitializationException { MockServiceCollector.setDelegate(svcCollector); // Tell the config to use the MockServiceCollector for the specified service Collector collector = new Collector(); collector.setService(svcName); collector.setClassName(MockServiceCollector.class.getName()); m_collectdConfigFactory = m_easyMockUtils.createMock(CollectdConfigFactory.class); m_collectdConfig = m_easyMockUtils.createMock(CollectdConfiguration.class); expect(m_collectdConfigFactory.getCollectdConfig()).andReturn(m_collectdConfig).anyTimes(); expect(m_collectdConfig.getCollectors()).andReturn(Collections.singletonList(collector)).anyTimes(); expect(m_collectdConfig.getThreads()).andReturn(1).anyTimes(); m_collectd.setCollectdConfigFactory(m_collectdConfigFactory); } }
/** * Gets the JMX services. * * @param config the Collectd's configuration * @return the list of JMX services */ private List<String> getJmxServices(CollectdConfiguration config) { List<String> services = new ArrayList<>(); for (Collector c : config.getCollectors()) { // The following code has been made that way to avoid a dependency with opennms-services // TODO Depends on opennms-services is not that bad, considering that some customers could have different implementations. if (c.getClassName().matches(".*(JBoss|JMXSecure|Jsr160|MX4J)Collector$")) { services.add(c.getService()); } } return services; }
CollectdConfiguration config = new CollectdConfiguration(); config.addPackage(defaultPackage); config.addCollector(collector); defaultPackage.addService(service);
private void createScheduler() { Logging.withPrefix(LOG4J_CATEGORY, () -> { // Create a scheduler try { LOG.debug("init: Creating collectd scheduler"); setScheduler(new LegacyScheduler("Collectd", m_collectdConfigFactory.getCollectdConfig().getThreads())); } catch (final RuntimeException e) { LOG.error("init: Failed to create collectd scheduler", e); throw e; } }); }
/** * Returns true if collection package exists * * @param name * The package name to check * @return True if the package exists */ public boolean packageExists(String name) { synchronized (m_collectdConfigMutex) { return m_collectdConfig.getPackage(name) != null; } }
m_collectdConfiguration = m_mockUtils.createMock(CollectdConfiguration.class); EasyMock.expect(m_collectdConfigFactory.getCollectdConfig()).andReturn(m_collectdConfiguration).anyTimes(); EasyMock.expect(m_collectdConfiguration.getCollectors()).andReturn(Collections.singletonList(collector)).anyTimes(); EasyMock.expect(m_collectdConfiguration.getThreads()).andReturn(1).anyTimes();
/** * <p>visit</p> * * @param visitor a {@link org.opennms.netmgt.dao.jaxb.collector.CollectdConfigVisitor} object. */ public void visit(CollectdConfigVisitor visitor) { CollectdConfiguration collectdConfiguration = getCollectdConfiguration(); visitor.visitCollectdConfiguration(collectdConfiguration); for (Iterator<Collector> it = collectdConfiguration.getCollectors().iterator(); it.hasNext();) { Collector collector = it.next(); doVisit(collector, visitor); } visitor.completeCollectdConfiguration(collectdConfiguration); }
CollectdConfiguration config = new CollectdConfiguration(); config.addPackage(defaultPackage); config.addCollector(collector); defaultPackage.addService(service);
/** * For performance reasons, we only enable the {@link DomainResourceType} if * one or more packages use it. Here we iterator over all of defined packages, * return true if a package uses the domain types, and false otherwise. */ private boolean isDomainResourceTypeUsed() { for (Package pkg : m_collectdConfig.getCollectdConfig().getPackages()) { if ("true".equalsIgnoreCase(pkg.getStoreByIfAlias())) { return true; } } return false; } }
m_collectdConfiguration = m_mockUtils.createMock(CollectdConfiguration.class); EasyMock.expect(m_collectdConfigFactory.getCollectdConfig()).andReturn(m_collectdConfiguration).anyTimes(); EasyMock.expect(m_collectdConfiguration.getCollectors()).andReturn(Collections.singletonList(collector)).anyTimes(); EasyMock.expect(m_collectdConfiguration.getThreads()).andReturn(2).anyTimes();
private void rebuildScheduler() { for (Collector collector : m_collectdConfigFactory.getCollectdConfig().getCollectors()) { String svcName = collector.getService(); configuredCollectors.add(svcName);
/** * Gets the service object. * * @param config the Collectd's configuration * @param service the service's name * @return the service object */ private Service getServiceObject(CollectdConfiguration config, String service) { for (Package pkg : config.getPackages()) { for (Service svc : pkg.getServices()) { if (svc.getName().equals(service)) { return svc; } } } return null; }
private void instantiateCollectors() { LOG.debug("instantiateCollectors: Loading collectors"); /* * Load up an instance of each collector from the config * so that the event processor will have them for * new incoming events to create collectable service objects. */ Collection<Collector> collectors = m_collectdConfigFactory.getCollectdConfig().getCollectors(); for (Collector collector : collectors) { String svcName = collector.getService(); try { LOG.debug("instantiateCollectors: Loading collector {}, classname {}", svcName, collector.getClassName()); final ServiceCollector sc = m_serviceCollectorRegistry.getCollectorByClassName(collector.getClassName()); if (sc == null) { throw new IllegalArgumentException(String.format("No collector found with class name '%s'. Available collectors include: %s", collector.getClassName(), m_serviceCollectorRegistry.getCollectorClassNames())); } sc.initialize(); setServiceCollector(svcName, sc); } catch (Throwable t) { LOG.warn("instantiateCollectors: Failed to load collector {} for service {}", collector.getClassName(), svcName, t); } } }
/** * Returns true if collection domain exists * * @param name * The domain name to check * @return True if the domain exists */ public boolean domainExists(final String name) { synchronized (m_collectdConfigMutex) { for (Package pkg : m_collectdConfig.getPackages()) { if ((pkg.getIfAliasDomain() != null) && pkg.getIfAliasDomain().equals(name)) { return true; } } return false; } }
public Filter getFilter(final String filterName) { final List<Filter> filters = new ArrayList<>(); for (final Package p : getPackages()) { final Filter filter = p.getFilter(); if (filterName.equals(filter.getName())) { filters.add(filter); } else if (filterName.equals(p.getName())) { filter.setName(p.getName()); filters.add(filter); } } if (filters.size() > 1) { throw new IllegalArgumentException("Filter name " + filterName + " matched more than one filter in collectd-configuration.xml!"); } else if (filters.size() == 1) { return filters.get(0); } else { return null; } }
/** * Returns true if the specified interface is included by at least one * package which has the specified service and that service is enabled (set * to "on"). * * @param iface * {@link OnmsIpInterface} to lookup * @param svcName * The service name to lookup * @return true if Collectd config contains a package which includes the * specified interface and has the specified service enabled. */ public boolean isServiceCollectionEnabled(final OnmsIpInterface iface, final String svcName) { for (Package wpkg : m_collectdConfig.getPackages()) { // Does the package include the interface? if (interfaceInPackage(iface, wpkg)) { // Yes, now see if package includes // the service and service is enabled // if (wpkg.serviceInPackageAndEnabled(svcName)) { // Thats all we need to know... return true; } } } return false; }
for (Package wpkg : m_collectdConfig.getPackages()) {
for(Package wpkg : collectdConfig.getPackages()) {